Skip to content

BUG: DataFrame.asof() : Timezone Awareness / Naivety comparison TypeError #22198

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

Merged
merged 6 commits into from
Aug 6, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.23.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,4 @@ Bug Fixes

- Tab completion on :class:`Index` in IPython no longer outputs deprecation warnings (:issue:`21125`)
- Bug preventing pandas being used on Windows without C++ redistributable installed (:issue:`21106`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we undo this diff here?

Copy link
Contributor Author

@msmarchena msmarchena Aug 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every thing looks OK in my local and in github. I don't know how this happen.

Copy link
Member

@gfyoung gfyoung Aug 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to. Just run (relative to your pandas code directory):

git checkout origin/master doc/source/whatsnew/v0.23.1.txt

Commit this change and push it.

Copy link
Contributor Author

@msmarchena msmarchena Aug 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to delete the wrong commits

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have deleted the commit and done a new one. I don't understand I didn't touch that line and it's there again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have done your suggestion. I hope it is OK

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not passing the Travis CI test. Any idea?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI looks good to me 🙂

- Bug in :func:`Dataframe.asof` that raised a ``TypeError`` when attempting to compare tz-naive and tz-aware timestamps (:issue:`21194`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this entry to v0.24.0.txt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have moved the entry to v0.24.0.txt, section "Timezones". I hope it is OK.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good choice!

2 changes: 1 addition & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2463,7 +2463,7 @@ def asof_locs(self, where, mask):
result = np.arange(len(self))[mask].take(locs)

first = mask.argmax()
result[(locs == 0) & (where < self.values[first])] = -1
result[(locs == 0) & (where.values < self.values[first])] = -1

return result

Expand Down
19 changes: 19 additions & 0 deletions pandas/tests/frame/test_asof.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# coding=utf-8

import numpy as np
import pytest
from pandas import (DataFrame, date_range, Timestamp, Series,
to_datetime)

Expand Down Expand Up @@ -106,3 +107,21 @@ def test_all_nans(self):
result = DataFrame(np.nan, index=[1, 2], columns=['A', 'B']).asof(3)
expected = Series(np.nan, index=['A', 'B'], name=3)
tm.assert_series_equal(result, expected)

# Testing awareness of DataFrame index considering different
# UTC and timezone
@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'),
Series(1.0, name=Timestamp('2018-01-01 22:33:20.682+01:00'))),
]
)
def test_time_zone_aware_index(self, stamp, expected):
# GH21194
df = DataFrame(data=[1, 2],
index=[Timestamp('2018-01-01 21:00:05.001+00:00'),
Timestamp('2018-01-01 22:35:10.550+00:00')])
result = df.asof(stamp)
tm.assert_series_equal(result, expected)