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

DataFrameSchema is not hashable #1893

Open
2 of 3 tasks
sparkiegeek opened this issue Jan 7, 2025 · 0 comments
Open
2 of 3 tasks

DataFrameSchema is not hashable #1893

sparkiegeek opened this issue Jan 7, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@sparkiegeek
Copy link

Describe the bug

DataFrameSchema is not hashable, and therefore cannot be used by e.g. functools.cache

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of pandera.
  • (optional) I have confirmed this bug exists on the main branch of pandera.

Code Sample, a copy-pastable example

import pandera as pa

schema = pa.DataFrameSchema({
    "column1": pa.Column(int)
})
hash(schema)

Expected behavior

Given that DataFrameSchema have good __str__ and __repr__s I'd have thought it would be straightforward to make them hashable, and therefore usable as dictionary keys and in turn cache'able.

As a local hack, I added the following monkey-patch

DataFrameSchema.__hash__ = lambda self: hash(repr(self))

which doesn't seem too terrible?

Desktop (please complete the following information):

  • OS: WSL Ubuntu 24.04 LTS on Windows 11
  • Browser: N/A
  • Version: 0.22.1

Screenshots

N/A

Additional context

N/A

@sparkiegeek sparkiegeek added the bug Something isn't working label Jan 7, 2025
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

No branches or pull requests

1 participant