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

pandas AttributeError : 'Series' object has no attribute 'iteritems' when using accepted.tolerance() on a MultiIndexed Series #63

Open
colinmatthieu opened this issue Oct 10, 2024 · 0 comments

Comments

@colinmatthieu
Copy link

colinmatthieu commented Oct 10, 2024

The following example code using pandas 2.2.2 throws an AttributeError :

import pandas as pd
from datatest import validate, accepted

a = pd.DataFrame([['A', 1, 1], ['B', 2, 2]], columns=['c1', 'c2', 'c3']).set_index(['c1', 'c2'])

with accepted.tolerance(1):
    validate(a['c3'], 0)

The following error is raised :

File "[...]\venv\Lib\site-packages\datatest\acceptances.py", line 191, in __exit__
    raise exc_value
  File "<input>", line 2, in <module>
  File "[...]\venv\Lib\site-packages\datatest\validation.py", line 285, in __call__
    result = requirement_object(data)  # <- Apply requirement.
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "[...]\venv\Lib\site-packages\datatest\requirements.py", line 203, in __call__
    result = self.check_data(data)
             ^^^^^^^^^^^^^^^^^^^^^
  File "[...]venv\Lib\site-packages\datatest\requirements.py", line 267, in check_data
    data = normalize(data, lazy_evaluation=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[...]\venv\Lib\site-packages\datatest\_normalize.py", line 159, in normalize
    obj = _normalize_lazy(obj)
          ^^^^^^^^^^^^^^^^^^^^
  File "[...]\venv\Lib\site-packages\datatest\_normalize.py", line 93, in _normalize_lazy
    return IterItems(obj.iteritems())  # <- EXIT!
                     ^^^^^^^^^^^^^
  File "[...]\venv\Lib\site-packages\pandas\core\generic.py", line 6299, in __getattr__
    return object.__getattribute__(self, name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Series' object has no attribute 'iteritems'

According to pandas docs, Series.iteritems is deprecated since pandas 2.0, and obj.items should now be used.

It is worth noting that changing obj.iteritems() to obj.items() in line 93 of _normalize.py removes this error and gives the expected result :

datatest.ValidationError: does not satisfy `0` (1 difference): {
    ('B', 2): Deviation(+2, 0),
}
```
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

No branches or pull requests

1 participant