Skip to content

BUG: Retain timezone dtype with cut and qcut #19890

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 3 commits into from
Mar 9, 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
Prev Previous commit
Remove .values from params bins
  • Loading branch information
mroeschke committed Mar 9, 2018
commit 23f01845f992a9b0494c64ac1753d5980dc9af20
2 changes: 1 addition & 1 deletion pandas/core/reshape/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def _convert_bin_to_numeric_type(bins, dtype):
bins = to_timedelta(bins).view(np.int64)
else:
raise ValueError("bins must be of timedelta64 dtype")
elif is_datetime64_dtype(dtype):
elif is_datetime64_dtype(dtype) or is_datetime64tz_dtype(dtype):
if bins_dtype in ['datetime', 'datetime64']:
bins = to_datetime(bins).view(np.int64)
else:
Expand Down
9 changes: 4 additions & 5 deletions pandas/tests/reshape/test_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,14 +514,13 @@ def test_datetime_cut(self):
tm.assert_series_equal(Series(result), expected)

@pytest.mark.parametrize('bins', [
3, [Timestamp('2013-01-01 04:57:07.200000').value,
Timestamp('2013-01-01 21:00:00').value,
Timestamp('2013-01-02 13:00:00').value,
Timestamp('2013-01-03 05:00:00').value]])
3, [Timestamp('2013-01-01 04:57:07.200000'),
Timestamp('2013-01-01 21:00:00'),
Timestamp('2013-01-02 13:00:00'),
Timestamp('2013-01-03 05:00:00')]])
Copy link
Member

Choose a reason for hiding this comment

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

@mroeschke trying to address #47772 im getting a failure in this test bc i think the bins here need to be tzaware for this to make sense. without them being tzaware i think this should raise. but if i pass tz="US/Eastern" to the Timestamp constructor then i just get a regular failure. pls advise

Copy link
Member

Choose a reason for hiding this comment

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

Looks like if i do Timestamp(..., tz="UTC").tz_convert("US/Eastern") in the bins the the rest of the test passes. is that what you would expect?

Copy link
Member Author

Choose a reason for hiding this comment

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

I would have expected just passing tz="US/Eastern" into Timestamp to also pass this test and not needing to localize to UTC first. Is the failure with all box types?

Copy link
Member

Choose a reason for hiding this comment

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

Is the failure with all box types?

Yes

@pytest.mark.parametrize('box', [list, np.array, Index, Series])
def test_datetimetz_cut(self, bins, box):
# GH 19872
# TODO: Remove .value from parameters once #19891 is addressed
tz = 'US/Eastern'
s = Series(date_range('20130101', periods=3, tz=tz))
if not isinstance(bins, int):
Expand Down