Erratic behavior using query() and timedelta
See original GitHub issueCode Sample, a copy-pastable example if possible
import pandas as pd
d = pd.DataFrame([pd.Timedelta(5,'D')], columns=['dt'])
d.query('dt =="5 days"', engine='numexpr')
# works:
# dt
# 0 5 days
d.query('dt =="4 days"', engine='numexpr')
# works:
#Empty DataFrame
#Columns: [dt]
#Index: []
d.query('dt <"5 days"', engine='numexpr')
# Does not work
# ValueError: unknown type timedelta64[ns]
Problem description
Using query on timedelta values has erratic behavior, and was working before. I can’t see how suddenly, less than, and greater than operations using query
do not work, but == does.
Expected Output
import pandas as pd
d = pd.DataFrame([pd.Timedelta(5,'D')], columns=['dt'])
d.query('dt <"5 days"')
#EXPECTED:
# dt
# 0 5 days`
INSTALLED VERSIONS
commit: None python: 3.7.0.final.0 python-bits: 64 OS: Darwin OS-release: 17.7.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8
pandas: 0.23.4 pytest: None pip: 18.1 setuptools: 39.2.0 Cython: 0.28.3 numpy: 1.14.5 scipy: 1.1.0 pyarrow: None xarray: None IPython: 6.4.0 sphinx: None patsy: 0.5.0 dateutil: 2.7.3 pytz: 2018.5 blosc: None bottleneck: 1.2.1 tables: None numexpr: 2.6.8 feather: None matplotlib: 2.2.2 openpyxl: 2.5.9 xlrd: 1.1.0 xlwt: None xlsxwriter: 1.1.2 lxml: 4.2.5 bs4: None html5lib: 1.0.1 sqlalchemy: None pymysql: None psycopg2: 2.7.5 (dt dec pq3 ext lo64) jinja2: 2.10 s3fs: None fastparquet: None pandas_gbq: None pandas_datareader: 0.7.0
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top GitHub Comments
So I’m able to reproduce, but you need to have
numexpr
installed. Just not sure whichpandas
version you had installed though…@jsevo : To work around this, pass in
engine='python'
.I went back a couple of year’s worth of releases, but I can’t seem to find a combo of
pandas
andnumexpr
that gets the example to work…very strange…@jsevo : if you’re able to retrieve your old environment information, that would be great!