Skip to content

Conversation

LirongMa
Copy link
Contributor

@LirongMa LirongMa commented Oct 3, 2025

Changes for #55152

@LirongMa LirongMa changed the title [Issue 55152]: Add allow_slice to is_hashable function CLN: Add allow_slice to is_hashable function Oct 3, 2025
@LirongMa LirongMa marked this pull request as ready for review October 5, 2025 20:27
@jbrockmendel
Copy link
Member

Are there non-test places where this is needed?

@LirongMa
Copy link
Contributor Author

LirongMa commented Oct 8, 2025

Are there non-test places where this is needed?

not so far. Because in your PR(#53743 (comment)) you added the checks along with the call to is_hashable(). I added this 'allow_slice' argument based on Richard's suggestion (#55152 (comment))

Let me make some changes to some of the callers and set 'allow_slice' to be False.

@LirongMa LirongMa requested a review from rhshadrach as a code owner October 13, 2025 01:35
)

try:
self._book = Workbook(self._handles.handle, **engine_kwargs) # type: ignore[arg-type]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mypy failed on this comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbrockmendel I made changes based on your feedback. Please review.

If `allow_slice` is False, objects that are slices or tuples containing slices
will always return False, even if hash(obj) would succeed.
If `allow_slice` is True or None, slices and tuples containing slices are treated as
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is None needed?

Copy link
Contributor Author

@LirongMa LirongMa Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None is a default value. So for exsiting callers, I don't need to set allow_slice. Unless you want me to change all the callers of is_hahsable and set the allow_slice to be True (if they don't have extra checks for slice). Please let me know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just set the default to True.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, set the default to be True now.

# Reconsider this decision once this numpy bug is fixed:
# https://github.com/numpy/numpy/issues/5562

def _contains_slice(x: object) -> bool:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is only called once? why does it need to be a function?

Copy link
Contributor Author

@LirongMa LirongMa Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's to make this line more clean:
if allow_slice is False and _contains_slice(obj):

Otherwise, I have to do:

if allow_slice is False:
    if isinstance(x, tuple) and any(isinstance(v, slice) for v in x):
         return False
    elif isinstance(x, slice):
         return False

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think its cleaner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed _contains_slice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLN: Add is_hashable_non_slice

2 participants