-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
TST: query with timezone aware index & column #34021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ac8b828
e7dfe1e
61efc12
50b02c5
e6cf243
d7aaf2d
b7817a0
e4eb829
7fcd7a8
986cadd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -695,6 +695,21 @@ def test_inf(self): | |
result = df.query(q, engine=self.engine, parser=self.parser) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
def test_check_tz_aware_index_query(self, tz_aware_fixture): | ||
# https://github.com/pandas-dev/pandas/issues/29463 | ||
tz = tz_aware_fixture | ||
df_index = pd.date_range( | ||
start="2019-01-01", freq="1d", periods=10, tz=tz, name="time" | ||
) | ||
expected = pd.DataFrame(index=df_index) | ||
df = pd.DataFrame(index=df_index) | ||
result = df.query('"2018-01-03 00:00:00+00" < time') | ||
tm.assert_frame_equal(result, expected) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you also test the working case here, e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jreback Done. Please review. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vipinkjonwal thanks for your updates Like this, what's the difference between I think Jeff meant result = df.reset_index().query('"2018-01-03 00:00:00+00" < time')
expected = pd.DataFrame(df_index)
tm.assert_frame_equal(result, expected) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MarcoGorelli , I thought this was already working when the related issue was raised , I've updated the test with suggested changes. |
||
expected = pd.DataFrame(df_index) | ||
result = df.reset_index().query('"2018-01-03 00:00:00+00" < time') | ||
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
@td.skip_if_no_ne | ||
class TestDataFrameQueryNumExprPython(TestDataFrameQueryNumExprPandas): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like this,
time
is always greater than2018-01-03 00:00:00+00
- I think @mroeschke was suggesting to use, say,2019-01-04
inexpected
,2019-01-01
indf
, and then2019-01-03
inquery
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MarcoGorelli Thank you for the comment / appreciation.
If we use 2019-01-03 in query it results in earlier problem , because the shape of "expected" and "df" remains the same also their tz is changing , but in query the tz remains constant and when we query it to diff timezone their shape becomes inconsistent as the query tz is always constant. (So it always result in +1 or -1 records and hence fails.)
Hence I think he suggested to use 2018-01-03 , as it will always result in consistent shape while checking tz-aware for all time zones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry I'd misunderstood, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, it seems that your index for both
df
andexpected
are identical - if so, can you make a variable to share them?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done ! Thanks.