Description
Code Sample, a copy-pastable example if possible
import pandas as pd
import numpy as np
dd = pd.DataFrame(np.arange(10))
dd['x2'] = dd[0] * dd[0]
dd['q'] = pd.qcut(dd['x2'], 5)
dd.set_index('q', inplace=True)
dd.dropna()
Problem description
The call to dropna raised the following exception:
TypeError: Cannot cast array data from dtype('float64') to dtype('<U32') according to the rule 'safe'
This seems to happen only with a categorical index for which the intervals are not all of the same length.
There was no issue in version 0.23.4 and the issue is not fixed in the master
Expected Output
No exception should be raised.
Output of pd.show_versions()
INSTALLED VERSIONS
commit: 25ff472
python: 3.7.2.final.0
python-bits: 64
OS: Linux
OS-release: 4.19.15-300.fc29.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_CA.UTF-8
LOCALE: en_CA.UTF-8
pandas: 0.25.0.dev0+44.g25ff47292
pytest: None
pip: 19.0.1
setuptools: 40.6.3
Cython: 0.29.4
numpy: 1.16.1
scipy: 1.2.0
pyarrow: None
xarray: None
IPython: 7.2.0
sphinx: None
patsy: 0.5.1
dateutil: 2.7.5
pytz: 2018.9
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 3.0.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml.etree: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None
Activity
rs2 commentedon Feb 2, 2019
Referencing #24048 that changed the
.dropna()
callstack between0.23.4
and0.24.0
.rs2 commentedon Feb 2, 2019
This is caused by https://github.com/pandas-dev/pandas/pull/24048/files#diff-1e79abbbdd150d4771b91ea60a4e1cc7R4592
rs2 commentedon Feb 2, 2019
CC @jreback @makbigc
pandas-dev#25087: Fix .dropna() functionality for categorical indices
pandas-dev#25087: Favor .loc instead of _take
samuelsinayoko commentedon Feb 2, 2019
Have got a PR out for this #25090.
Have added 3 tests and made them pass, but the changes to the interval range get_indexer is lacking. Would welcome some directions about that as I'm not too familiar with get_indexer.
19 remaining items