qcut raising ValueError if NaT present · Issue #19768 · pandas-dev/pandas (original) (raw)
Code Sample, a copy-pastable example if possible
from io import StringIO import pandas as pd
csv = 'Index,Date\n1,2013-01-01 23:00:00\n2,\n3,2013-01-01 23:00:01' df = pd.read_csv(StringIO(csv), index_col=0, parse_dates=[1]) pd.qcut(df["Date"], 2)
Problem description
qcut
raises a ValueError
:
Traceback (most recent call last):
File "mve.py", line 26, in <module>
pd.qcut(df["Date"], 2)
File "/tmp/test/env/lib/python3.5/site-packages/pandas/core/reshape/tile.py", line 208, in qcut
dtype=dtype, duplicates=duplicates)
File "/tmp/test/env/lib/python3.5/site-packages/pandas/core/reshape/tile.py", line 251, in _bins_to_cuts
dtype=dtype)
File "/tmp/test/env/lib/python3.5/site-packages/pandas/core/reshape/tile.py", line 344, in _format_labels
labels = IntervalIndex.from_breaks(breaks, closed=closed)
File "/tmp/test/env/lib/python3.5/site-packages/pandas/core/indexes/interval.py", line 370, in from_breaks
name=name, copy=copy)
File "/tmp/test/env/lib/python3.5/site-packages/pandas/core/indexes/interval.py", line 411, in from_arrays
copy=copy, verify_integrity=True)
File "/tmp/test/env/lib/python3.5/site-packages/pandas/core/indexes/interval.py", line 225, in _simple_new
result._validate()
File "/tmp/test/env/lib/python3.5/site-packages/pandas/core/indexes/interval.py", line 265, in _validate
raise ValueError('missing values must be missing in the same '
ValueError: missing values must be missing in the same location both left and right sides
Expected Output
qcut
returning something like
Index
1 (2013-01-01 22:59:59.999999999, 2013-01-01 23:00:01.0
2 NaT
3 (2013-01-01 22:59:59.999999999, 2013-01-01 23:00:01.0
Output of pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Linux
OS-release: 4.13.0-32-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: de_DE.UTF-8
LOCALE: de_DE.UTF-8
pandas: 0.22.0
pytest: None
pip: 9.0.1
setuptools: 38.5.1
Cython: None
numpy: 1.14.0
scipy: None
pyarrow: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2018.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None