|
4 | 4 | import numpy as np
|
5 | 5 | from pandas.compat import zip
|
6 | 6 |
|
7 |
| -from pandas import (Series, isna, to_datetime, DatetimeIndex, |
| 7 | +from pandas import (DataFrame, Series, isna, to_datetime, DatetimeIndex, |
8 | 8 | Timestamp, Interval, IntervalIndex, Categorical,
|
9 | 9 | cut, qcut, date_range, NaT, TimedeltaIndex)
|
10 | 10 | from pandas.tseries.offsets import Nano, Day
|
@@ -104,6 +104,12 @@ def test_cut_corner(self):
|
104 | 104 |
|
105 | 105 | pytest.raises(ValueError, cut, [1, 2, 3], 0.5)
|
106 | 106 |
|
| 107 | + @pytest.mark.parametrize('arg', [2, np.eye(2), DataFrame(np.eye(2))]) |
| 108 | + @pytest.mark.parametrize('cut_func', [cut, qcut]) |
| 109 | + def test_cut_not_1d_arg(self, arg, cut_func): |
| 110 | + with pytest.raises(ValueError): |
| 111 | + cut_func(arg, 2) |
| 112 | + |
107 | 113 | def test_cut_out_of_range_more(self):
|
108 | 114 | # #1511
|
109 | 115 | s = Series([0, -1, 0, 1, -3], name='x')
|
@@ -488,6 +494,34 @@ def test_datetime_cut(self):
|
488 | 494 | result, bins = cut(data, 3, retbins=True)
|
489 | 495 | tm.assert_series_equal(Series(result), expected)
|
490 | 496 |
|
| 497 | + def test_datetimetz_cut(self): |
| 498 | + # GH 19872 |
| 499 | + tz = 'US/Eastern' |
| 500 | + s = Series(date_range('20130101', periods=3, tz=tz)) |
| 501 | + result = cut(s, 3) |
| 502 | + expected = ( |
| 503 | + Series(IntervalIndex([ |
| 504 | + Interval(Timestamp('2012-12-31 23:57:07.200000', tz=tz), |
| 505 | + Timestamp('2013-01-01 16:00:00', tz=tz)), |
| 506 | + Interval(Timestamp('2013-01-01 16:00:00', tz=tz), |
| 507 | + Timestamp('2013-01-02 08:00:00', tz=tz)), |
| 508 | + Interval(Timestamp('2013-01-02 08:00:00', tz=tz), |
| 509 | + Timestamp('2013-01-03 00:00:00', tz=tz))])) |
| 510 | + .astype(CDT(ordered=True))) |
| 511 | + tm.assert_series_equal(result, expected) |
| 512 | + |
| 513 | + result = qcut(s, 3) |
| 514 | + expected = ( |
| 515 | + Series(IntervalIndex([ |
| 516 | + Interval(Timestamp('2012-12-31 23:59:59.999999999', tz=tz), |
| 517 | + Timestamp('2013-01-01 16:00:00', tz=tz)), |
| 518 | + Interval(Timestamp('2013-01-01 16:00:00', tz=tz), |
| 519 | + Timestamp('2013-01-02 08:00:00', tz=tz)), |
| 520 | + Interval(Timestamp('2013-01-02 08:00:00', tz=tz), |
| 521 | + Timestamp('2013-01-03 00:00:00', tz=tz))])) |
| 522 | + .astype(CDT(ordered=True))) |
| 523 | + tm.assert_series_equal(result, expected) |
| 524 | + |
491 | 525 | def test_datetime_bin(self):
|
492 | 526 | data = [np.datetime64('2012-12-13'), np.datetime64('2012-12-15')]
|
493 | 527 | bin_data = ['2012-12-12', '2012-12-14', '2012-12-16']
|
|
0 commit comments