Closed
Description
I'm trying to get the left edge from a Series of Intervals. Unexpectedly, the result is a Series of dtype category. I'm also getting a FutureWarning.
>>> import pandas as pd
>>> s = pd.Series(pd.cut([1, 2, 3], 2))
>>> s
0 (0.998, 2.0]
1 (0.998, 2.0]
2 (2.0, 3.0]
dtype: category
Categories (2, interval[float64]): [(0.998, 2.0] < (2.0, 3.0]]
>>> s.apply(lambda x: x.left)
C:\Users\My.Name\.virtualenvs\MyRepo-nagZr6A2\lib\site-packages\pandas\io\formats\format.py:1403: FutureWarning: Index.ravel returning ndarray is deprecated; in a future version this wi
ll return a view on self.
for val, m in zip(values.ravel(), mask.ravel())
0 0.998
1 0.998
2 2.000
dtype: category
Categories (2, float64): [0.998 < 2.000]
Interestingly, the individual cells have objects with the correct dtype:
>>> result = s.apply(lambda x: x.left)
>>> type(result[0])
<class 'numpy.float64'>
However, operations you would expect from a Series of floats to work do not work:
>>> result + 1
[...]
TypeError: unsupported operand type(s) for +: 'Categorical' and 'int'
pd.show_versions()
INSTALLED VERSIONS------------------
commit : 9d598a5
python : 3.8.7.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : AMD64 Family 23 Model 96 Stepping 1, AuthenticAMD
byteorder : little
LC_ALL : None
LANG : None
LOCALE : de_DE.cp1252
pandas : 1.2.1
numpy : 1.20.0
pytz : 2021.1
dateutil : 2.8.1
pip : 20.3.3
setuptools : 51.1.2
Cython : None
pytest : 6.2.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.20.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : 3.0.6
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.6.0
sqlalchemy : 1.3.23
tables : None
tabulate : 0.8.7
xarray : None
xlrd : None
xlwt : None
numba : None