mggg / VoteKit

A Swiss Army Knife for computational social choice research
https://votekit.readthedocs.io/en/latest/
MIT License
10 stars 12 forks source link

Pandas import error on cvr_loaders #70

Open gabeschoenbach opened 1 year ago

gabeschoenbach commented 1 year ago

After running poetry as instructed in the README I tried running the following code:

from votekit.cvr_loaders import rank_column_csv

and I get the following error:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[1], line 1
----> 1 from votekit.cvr_loaders import rank_column_csv

File ~/Desktop/mggg/summer23/VoteKit/src/votekit/cvr_loaders.py:8
      5 from .profile import PreferenceProfile
      6 from .ballot import Ballot
----> 8 from pandas.errors import EmptyDataError, DataError
      9 from fractions import Fraction
     12 def rank_column_csv(
     13     fpath: str,
     14     *,
   (...)
     17     id_col: Optional[int] = None,
     18 ) -> PreferenceProfile:

ImportError: cannot import name 'DataError' from 'pandas.errors' (/Users/gabe/.pyenv/versions/3.9.6/lib/python3.9/site-packages/pandas-1.4.0rc0-py3.9-macosx-10.15-x86_64.egg/pandas/errors/__init__.py)
gabeschoenbach commented 1 year ago

Once Jack mentioned that my pandas version (1.4) was likely the issue, Emarie suggested fully deactivating my conda environment (i.e. running conda deactivate twice) to go from conda environment X to (base) to nothing, and then running conda activate X to get into my environment X, which has pandas version 1.5.3 installed. After being in environment X, I ran poetry run jupyter lab to get to a Python environment and now this all works!

jamesturk commented 1 year ago

Just saw this after the other environment comments. Make sure you deactivate conda entirely and then poetry install before using poetry (or any other python package manager).

conda doesn't play nice with the rest of the Python ecosystem, so standard tools like pip-tools, poetry, pdm envs all work nicely together, but conda frequently does it's own completely different thing. Typically only one version of an env. can be active at a time, but this issue (and likely all the other environment issues you're having) likely stem from conda overriding locally installed versions like this.

gabeschoenbach commented 1 year ago

Ah that makes a lot of sense about conda, thanks James! I'll do that going forward and hopefully much will be fixed.