Skip to content
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

Regression: S3 UPaths are no longer hashable #183

Closed
johnnyg opened this issue Feb 14, 2024 · 2 comments · Fixed by #188
Closed

Regression: S3 UPaths are no longer hashable #183

johnnyg opened this issue Feb 14, 2024 · 2 comments · Fixed by #188
Labels
bug 🐛 Something isn't working
Milestone

Comments

@johnnyg
Copy link

johnnyg commented Feb 14, 2024

Python v3.11

version 0.1.4 of upath:

>> hash(UPath("s3://bucket/file"))
9171179727552408191

version 0.2.0 of upath:

>> hash(UPath("s3://bucket/file"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/mamba/envs/dev/lib/python3.11/site-packages/upath/core.py", line 574, in __hash__
    return hash((self.path, self.storage_options, self.protocol))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unhashable type: 'mappingproxy'
@ap-- ap-- added the bug 🐛 Something isn't working label Feb 14, 2024
@ap--
Copy link
Collaborator

ap-- commented Feb 14, 2024

Hey @johnnyg

Thank you for reporting! That's definitely a bug. I'll try to get a out a fixed version on the weekend.

Could you describe your use case for hashable UPath instances?
Are you using them as keys in a mapping to associate other data to the instance?

Note:

In v0.1.4 __hash__ was using pathlib's implementation, which means it just relied on .parts (or ._cparts). So while UPath instances are hashable in v0.1.x, it might not be the hash you want.

>>> import upath  # universal_pathlib==0.1.4
>>> hash(upath.UPath("s3://bucket/file.txt"))
-4817263177334106539
>>> hash(upath.UPath("memory:///file.txt"))
-4817263177334106539

Cheers,
Andreas

@johnnyg
Copy link
Author

johnnyg commented Feb 14, 2024

Hi @ap--

Thanks for your response!

Yeah the current use case is using it in a dict so we can associate it with other data but also using @cache on a function which has a UPath as a parameter.

Good to know about the current hash implementation; in the mapping scenario this won't be a problem as the paths will always have the same protocol but this could be an issue when they're used in the memoization as that function will get a mix of protocols that may have the same path.

@ap-- ap-- added this to the v0.2.1 milestone Feb 15, 2024
@ap-- ap-- closed this as completed in #188 Feb 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants