question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Erratic behavior using query() and timedelta

See original GitHub issue

Code 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:open
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
gfyoungcommented, Nov 1, 2018

So I’m able to reproduce, but you need to have numexpr installed. Just not sure which pandas version you had installed though…

@jsevo : To work around this, pass in engine='python'.

0reactions
gfyoungcommented, Nov 1, 2018

I went back a couple of year’s worth of releases, but I can’t seem to find a combo of pandas and numexpr that gets the example to work…very strange…

@jsevo : if you’re able to retrieve your old environment information, that would be great!

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Example code]-Is this intended behavior or a bug in datetime ...
[Example code]-Is this intended behavior or a bug in datetime timedelta? ... You need to call normalize() using the timezone object again when...
Read more >
(Django - Python) Problems with timedelta saving form
1 Answer 1 ... You have defined auto_now_add=True on your endDate field, which renders field uneditable and set as now(). From documentation:.
Read more >
postgresql - Getting time delta between two related rows
I have a table with a lot of entries in pairs, related to one another by a field name , each entry has...
Read more >
16 Dates and times | Python for Data Science
To get the current date or date-time you can use date.today() or datetime.now() ... return out # data table flights_dt = (flights. query('(dep_time.notna()) ......
Read more >
Dealing with DateTime Features in Python and Pandas
DateTime and Timedelta objects in Pandas. The to_datetime() method converts the date and time in string format to a DateTime object: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found