-
- Notifications
You must be signed in to change notification settings - Fork 19.4k
BUG: DataFrame.asof() : Timezone Awareness / Naivety comparison TypeError (incorrect) #21284
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
Conversation
| Hello @msmarchena! Thanks for updating the PR.
Comment last updated on August 03, 2018 at 14:02 Hours UTC |
doc/source/whatsnew/v0.23.1.txt Outdated
| Bug Fixes | ||
| ~~~~~~~~~ | ||
| | ||
| - Bug in :func:`Dataframe.asof` that reaised ``TypeError`` when attempting to compare tz-naive and tz-aware timestamps (:issue:`21194`) |
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.
"reaised" --> "raised a"
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
Codecov Report
@@ Coverage Diff @@ ## master #21284 +/- ## ======================================= Coverage 91.85% 91.85% ======================================= Files 153 153 Lines 49546 49546 ======================================= Hits 45509 45509 Misses 4037 4037
Continue to review full report at Codecov.
|
pandas/tests/frame/test_asof.py Outdated
| # Testing if DataFrame index preserve timezone (UTC) | ||
| df = DataFrame(data=[1, 2], index=[timestamp1, timestamp2]) | ||
| result = df.asof(timestamp_internal) | ||
| expected = Series(2.0, index=RangeIndex(start=0, stop=1, step=1), |
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.
RangeIndex isn't explicitly needed to construct the Series I think. It's created by default.
pandas/tests/frame/test_asof.py Outdated
| expected = Series(np.nan, index=['A', 'B'], name=3) | ||
| tm.assert_series_equal(result, expected) | ||
| | ||
| def test_time_zone_aware_index(self): |
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.
If possible, could you use pytest.mark.parameterize to combine these two tests? The structure of these tests seem very similar. Looks like you might be able to param over timestamp_internal
doc/source/whatsnew/v0.23.1.txt Outdated
| Bug Fixes | ||
| ~~~~~~~~~ | ||
| | ||
| - Bug in :func:`Dataframe.asof` that raised a ``TypeError`` when attempting to compare tz-naive and tz-aware timestamps (:issue:`21194`) |
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.
move under the Conversion section
pandas/tests/frame/test_asof.py Outdated
| # Testing awareness of DataFrame index considering different | ||
| # UTC and different timezone | ||
| @pytest.mark.parametrize("stamp,expected", | ||
| [(Timestamp('2018-01-01 23:22:43.325+00:00'), |
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.
this will have some linting errors
you can format this a bit better by doing
@pytest.mark.parameterize( "stamp, expected", [ (......), (......)]) pandas/tests/frame/test_asof.py Outdated
| @pytest.mark.parametrize("stamp,expected", | ||
| [(Timestamp('2018-01-01 23:22:43.325+00:00'), | ||
| Series(2.0,name=Timestamp('2018-01-01 23:22:43.325+00:00'))), | ||
| (Timestamp('2018-01-01 22:33:20.682+01:00'), |
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.
can you add a NaT in here as well (so another case)
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.
I don't understand what do you mean. Where exactly I should add a NaT?
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.
equiv of the naive case, but with a non-naive Timestamp (we may already have this test, if so, just add on to it)
In [2]: df = DataFrame(data=[1, 2], ...: index=[pd.Timestamp('2018-01-01 21:00:05.001'), ...: pd.Timestamp('2018-01-01 22:35:10.550')]) ...: In [3]: df Out[3]: 0 2018-01-01 21:00:05.001 1 2018-01-01 22:35:10.550 2 In [4]: df.asof('2018-01-01 22:35:10.550') Out[4]: 0 2.0 Name: 2018-01-01 22:35:10.550000, dtype: float64 In [5]: df.asof(pd.NaT) Out[5]: 0 1.0 Name: NaT, dtype: float64 In [7]: df.asof('2018-01-01') Out[7]: 0 NaN Name: 2018-01-01 00:00:00, dtype: float64 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.
thanks for the clarification. I will check it out.
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.
with the fix where.values in asof_loc I have for the NaT case the following:
df Out[18]: 0 2018-01-01 21:00:05.001 1 2018-01-01 22:35:10.550 2 result=df.asof(pd.NaT) /Users/.../pandas/core/indexes/base.py:2382: FutureWarning: In the future, 'NAT < x' and 'x < NAT' will always be False. result[(locs == 0) & (where.values < self.values[first])] = -1 result Out[20]: 0 NaN Name: NaT, dtype: float64 Is 1 really the desired value in this situation?
pandas/tests/frame/test_asof.py Outdated
| @pytest.mark.parametrize("stamp,expected", | ||
| [(Timestamp('2018-01-01 23:22:43.325+00:00'), | ||
| Series(2.0,name=Timestamp('2018-01-01 23:22:43.325+00:00'))), | ||
| (Timestamp('2018-01-01 22:33:20.682+01:00'), |
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.
equiv of the naive case, but with a non-naive Timestamp (we may already have this test, if so, just add on to it)
In [2]: df = DataFrame(data=[1, 2], ...: index=[pd.Timestamp('2018-01-01 21:00:05.001'), ...: pd.Timestamp('2018-01-01 22:35:10.550')]) ...: In [3]: df Out[3]: 0 2018-01-01 21:00:05.001 1 2018-01-01 22:35:10.550 2 In [4]: df.asof('2018-01-01 22:35:10.550') Out[4]: 0 2.0 Name: 2018-01-01 22:35:10.550000, dtype: float64 In [5]: df.asof(pd.NaT) Out[5]: 0 1.0 Name: NaT, dtype: float64 In [7]: df.asof('2018-01-01') Out[7]: 0 NaN Name: 2018-01-01 00:00:00, dtype: float64 | can you rebase and update |
| can u rebase |
- modified whatsnew.v0.23.1.txt