Skip to content

IntervalIndex.map raises "TypeError: Unexpected keyword arguments {'closed'}" in pandas 1.0.0rc0 #31202

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

Closed
vadella opened this issue Jan 22, 2020 · 1 comment · Fixed by #31232
Assignees
Labels
Interval Interval data type Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@vadella
Copy link

vadella commented Jan 22, 2020

Code Sample, a copy-pastable example if possible

pd.interval_range(1,3,2).map(str)
TypeError                                 Traceback (most recent call last)
<ipython-input-4-91424d1c664f> in <module>
----> 1 pd.interval_range(1,3,2).map(str)

C:\Miniconda3\envs\pandas_new\lib\site-packages\pandas\core\indexes\base.py in map(self, mapper, na_action)
   4546             attributes["dtype"] = self.dtype
   4547 
-> 4548         return Index(new_values, **attributes)
   4549 
   4550     def isin(self, values, level=None):

C:\Miniconda3\envs\pandas_new\lib\site-packages\pandas\core\indexes\base.py in __new__(cls, data, dtype, copy, name, tupleize_cols, **kwargs)
    389                 if new_dtype is not None:
    390                     return cls(
--> 391                         new_data, dtype=new_dtype, copy=False, name=name, **kwargs
    392                     )
    393 

C:\Miniconda3\envs\pandas_new\lib\site-packages\pandas\core\indexes\base.py in __new__(cls, data, dtype, copy, name, tupleize_cols, **kwargs)
    393 
    394             if kwargs:
--> 395                 raise TypeError(f"Unexpected keyword arguments {repr(set(kwargs))}")
    396             if subarr.ndim > 1:
    397                 # GH#13601, GH#20285, GH#27125

TypeError: Unexpected keyword arguments {'closed'}

Problem description

When using map on an IntervalIndex raises a TypeError since testing on pandas 1.0.0rc0. In 0.25.1 it worked as expected.

As a workaround pd.interval_range(1,3,2).astype(object).map(str) works, but the casting to object should not be necessary.

Expected Output

Index(['(1, 2]', '(2, 3]'], dtype='object')

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.7.6.final.0
python-bits : 64
OS : Windows
OS-release : 8.1
machine : AMD64
processor : Intel64 Family 6 Model 78 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None

pandas : 1.0.0rc0
numpy : 1.17.5
pytz : 2019.3
dateutil : 2.8.1
pip : 19.3.1
setuptools : 45.1.0.post20200119
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10.3
IPython : 7.11.1
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.1.1
numexpr : None
odfpy : None
openpyxl : 3.0.2
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : None
numba : None

@jschendel
Copy link
Member

Thanks, I can confirm that this is failing on master and that it works on 0.25.3.

Looks like moving the map definition in DatetimeIndexOpsMixin down to ExtensionIndex so it's shared with IntervalIndex fixes this. Will open a PR later tonight.

@jschendel jschendel self-assigned this Jan 22, 2020
@TomAugspurger TomAugspurger added this to the 1.0.0 milestone Jan 22, 2020
@TomAugspurger TomAugspurger added the Regression Functionality that used to work in a prior pandas version label Jan 22, 2020
@jschendel jschendel added the Interval Interval data type label Jan 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Interval Interval data type Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants