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

model comparison fails on latest versions due to pandas indexing (at -> loc) #2130

Closed
falkmielke opened this issue Oct 6, 2022 · 1 comment

Comments

@falkmielke
Copy link

falkmielke commented Oct 6, 2022

model comparison fails on my system when running the standard comparison example provided here:
https://arviz-devs.github.io/arviz/api/generated/arviz.compare.html

import arviz as az
data1 = az.load_arviz_data("non_centered_eight")
data2 = az.load_arviz_data("centered_eight")
compare_dict = {"non centered": data1, "centered": data2}
comparison = az.compare(compare_dict)

print (comparison)

(trace below)

Python 3.10.7
arviz.__version__ = 0.12.1
pandas.__version__ = 1.5.0

This can be mended by replacing
pandas.DataFrame.at[val] = (...) call in
stats.stats.py::compare(...) L306
with the more appropriate pandas.DataFrame.loc[val, :] = (...).

more appropriate because according to the pandas documentation, at is used to "Access a single value for a row/column label pair.". The code in compare() obviously accesses multiple values.

Full error trace:

Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/pandas/core/indexes/base.py", line 3800, in get_loc
    return self._engine.get_loc(casted_key)
  File "pandas/_libs/index.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/index.pyx", line 144, in pandas._libs.index.IndexEngine.get_loc
TypeError: 'slice(None, None, None)' is an invalid key

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 6, in <module>
    comparison = az.compare(compare_dict)
  File "/usr/lib/python3.10/site-packages/arviz/stats/stats.py", line 306, in compare
    df_comp.at[val] = (
  File "/usr/lib/python3.10/site-packages/pandas/core/indexing.py", line 2438, in __setitem__
    return super().__setitem__(key, value)
  File "/usr/lib/python3.10/site-packages/pandas/core/indexing.py", line 2393, in __setitem__
    self.obj._set_value(*key, value=value, takeable=self._takeable)
  File "/usr/lib/python3.10/site-packages/pandas/core/frame.py", line 4208, in _set_value
    icol = self.columns.get_loc(col)
  File "/usr/lib/python3.10/site-packages/pandas/core/indexes/base.py", line 3807, in get_loc
    self._check_indexing_error(key)
  File "/usr/lib/python3.10/site-packages/pandas/core/indexes/base.py", line 5963, in _check_indexing_error
    raise InvalidIndexError(key)
pandas.errors.InvalidIndexError: slice(None, None, None)

Hope this helps! Thanks,
Falk

@ahartikainen
Copy link
Contributor

Thanks for the report.

Issue was fixed in #2104

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

2 participants