mdeff / fma

FMA: A Dataset For Music Analysis
https://arxiv.org/abs/1612.01840
MIT License
2.25k stars 442 forks source link

ValueError: Got an unexpected argument: categories #34

Closed drscotthawley closed 4 years ago

drscotthawley commented 5 years ago

Hi, I've referred to the Usage section in the README as well as #9 and #10. I've checked out rc1 because it's appropriate for the version of fma_metadata.zip and fma_small.zip that I checked out, and also I've set my environment variables.

Nevertheless, running the line

    tracks = utils.load('tracks.csv')

in either the usage.ipynb file or my own very simple Python script will produce a ValueError about categories:

Traceback (most recent call last):
  File "proc_fma.py", line 3, in <module>
    tracks = utils.load('fma_metadata/tracks.csv')
  File "/media/datadrive/datasets/fma/utils.py", line 213, in load
    'category', categories=SUBSETS, ordered=True)
  File "/home/shawley/anaconda3/envs/panotti/lib/python3.6/site-packages/pandas/core/generic.py", line 5883, in astype
    dtype=dtype, copy=copy, errors=errors, **kwargs
  File "/home/shawley/anaconda3/envs/panotti/lib/python3.6/site-packages/pandas/core/internals/managers.py", line 581, in astype
    return self.apply("astype", dtype=dtype, **kwargs)
  File "/home/shawley/anaconda3/envs/panotti/lib/python3.6/site-packages/pandas/core/internals/managers.py", line 438, in apply
    applied = getattr(b, f)(**kwargs)
  File "/home/shawley/anaconda3/envs/panotti/lib/python3.6/site-packages/pandas/core/internals/blocks.py", line 557, in astype
    return self._astype(dtype, copy=copy, errors=errors, values=values, **kwargs)
  File "/home/shawley/anaconda3/envs/panotti/lib/python3.6/site-packages/pandas/core/internals/blocks.py", line 598, in _astype
    "Got an unexpected argument: {}".format(deprecated_arg)
ValueError: Got an unexpected argument: categories

I haven't seen this error reported in any of the other issues. Can anyone help, e.g. @mdeff ? Thanks!

drscotthawley commented 5 years ago

Fixed... Apparently there's been a change in Pandas, at least for version 0.25.0 (the requirements.txt file for fma doesn't specify a version for pandas).

So the fix is to modify utils.py so that it includes

from pandas.api.types import CategoricalDtype

and the offending line about categories that used to read as

                'category', categories=SUBSETS, ordered=True)

now reads as

                CategoricalDtype(categories=SUBSETS, ordered=True))

. :-)

andimarafioti commented 4 years ago

This error also appears in the creation notebook

mdeff commented 4 years ago

Thanks for reporting! This behavior was indeed removed in pandas 0.25:

Removed the previously deprecated ordered and categories keyword arguments in astype (GH17742)

I used pandas==0.21.0 when developing this code. I will add package versions to the requirements.txt.

717101 commented 4 years ago

Hi, I tried to use the new code but the error persist in the next line. Thanks for your work.


TypeError                                 Traceback (most recent call last)
<ipython-input-31-4224f39de5bf> in <module>()
      1 AUDIO_DIR = os.environ.get('fma_small')
----> 2 tracks = utils.load('fma_metadata/tracks.csv')

/content/utils.py in load(filepath)
    212             tracks[column] = tracks[column].astype('category')
    213 
--> 214         return tracks
    215 
    216 

TypeError: astype() got an unexpected keyword argument 'categories'
andimarafioti commented 4 years ago

What does:

import pandas
print(pandas.__version__)

prints?

717101 commented 4 years ago

Thanks, I didn't realized that my pandas version was downgraded.

mdeff commented 4 years ago

I tried to use the new code but the error persist in the next line.

The line number of the error (--> 214 return tracks) seems to indicate you're not using the latest version. The latest has a try-catch block for this case:

212        try:
213            tracks['set', 'subset'] = tracks['set', 'subset'].astype(
214                    'category', categories=SUBSETS, ordered=True)
215        except ValueError:
216            # the categories and ordered arguments were removed in pandas 0.25
217            tracks['set', 'subset'] = tracks['set', 'subset'].astype(
218                     pd.CategoricalDtype(categories=SUBSETS, ordered=True))

So both old (pandas<0.25) and new (pandas>=0.25) pandas should work.

Could you try a fresh git clone?

albert239825 commented 3 years ago

Hello, I know I'm a little late, but I would like to add that I am still getting the error despite the try-catch block.

Edit: I fixed it by removing the except ValueError: and just changing it to except:

mdeff commented 3 years ago

Thanks for reporting @albert239825. Which exception did you get? If TypeError, could you try #47? Which version of pandas (import pandas; print(pandas.__version__)) are you using?

albert239825 commented 3 years ago

@mdeff I didn't get a type error. My pandas version is 1.2.2 and the error I get is "astype() got an unexpected keyword argument 'categories'". Edit: Also, I undid a commit with the fix and now it's broken again... Edit: Nevermind, changing except ValueError: to except: fixed the issue as before

mdeff commented 3 years ago

the error I get is "astype() got an unexpected keyword argument 'categories'"

And that's a TypeError. 😉

20210318_232852

Hence I'll merge #47.

albert239825 commented 3 years ago

@mdeff Thanks! So sorry for my lack of knowledge.

mdeff commented 3 years ago

No problem. 😉 Thank you for following-up on the issue.