Skip to content

TYPES: add types in core.util.hashing #28916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

jbrockmendel
Copy link
Member

Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

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

@jbrockmendel generally lgtm.

@@ -26,13 +26,17 @@
_default_hash_key = "0123456789123456"


def _combine_hash_arrays(arrays, num_items: int):
def _combine_hash_arrays(arrays, num_items: int) -> np.uint64:
Copy link
Member

Choose a reason for hiding this comment

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

for now, I think we are going to type using python int. xref #28843 (comment)

originally, I assumed that since a numpy int is not an instance of python int, that it needed to be treated differently. But since mypy is a static type checker and has no knowledge of the actual value then a python int should be compatible with a numpy int for type checking purposes.

Also, without numpy stubs np.uint64 will be resolving to Any. so this is not adding any value as far as type checking is concerned, but granted does add value from a documentation perspective.

@WillAyd

@@ -58,7 +62,7 @@ def hash_pandas_object(
obj,
index: bool = True,
encoding: str = "utf8",
hash_key=None,
hash_key: str = _default_hash_key,
Copy link
Member

Choose a reason for hiding this comment

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

can you remove L91 and L92?

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch, thanks

@simonjayhawkins simonjayhawkins added the Typing type annotations, mypy/pyright type checking label Oct 11, 2019
@jbrockmendel
Copy link
Member Author

@simonjayhawkins changing np.uint64 to int caused mypy to complain. any other suggestions?

@WillAyd
Copy link
Member

WillAyd commented Oct 11, 2019

Shouldn't the return type of _combine_hash_arrays be an ndarray? The annotation says int but mypy is complaining because on line 210 we are trying to index what _combine_hash_arrays returns

@jbrockmendel
Copy link
Member Author

Shouldn't the return type of _combine_hash_arrays be an ndarray

I think you're right, yes. Will update. I look forward to the day when annotations support cython-like ndarray[uint64, ndim=1] or something.

@jbrockmendel
Copy link
Member Author

Closing for now to clear the queue, will troubleshoot locally.

@jbrockmendel jbrockmendel deleted the cln6 branch November 21, 2019 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants