|
26 | 26 | from pandas.core.common import PerformanceWarning, UnsortedIndexError
|
27 | 27 |
|
28 | 28 | import pandas.util.testing as tm
|
29 |
| -from pandas import date_range |
| 29 | +from pandas import (date_range, to_timedelta) |
30 | 30 |
|
31 | 31 |
|
32 | 32 | _verbose = False
|
@@ -100,7 +100,7 @@ class TestIndexing(tm.TestCase):
|
100 | 100 | _multiprocess_can_split_ = True
|
101 | 101 |
|
102 | 102 | _objs = set(['series', 'frame', 'panel'])
|
103 |
| - _typs = set(['ints', 'labels', 'mixed', 'ts', 'floats', 'empty', 'ts_rev']) |
| 103 | + _typs = set(['ints', 'labels', 'mixed', 'ts', 'floats', 'empty', 'ts_rev', 'dt']) |
104 | 104 |
|
105 | 105 | def setUp(self):
|
106 | 106 |
|
@@ -150,6 +150,13 @@ def setUp(self):
|
150 | 150 | self.series_empty = Series({})
|
151 | 151 | self.panel_empty = Panel({})
|
152 | 152 |
|
| 153 | + self.series_dt = Series(np.random.randn(4), |
| 154 | + index=to_timedelta(range(4), unit='s')) |
| 155 | + self.frame_dt = DataFrame(np.random.randn(4, 4), |
| 156 | + index=to_timedelta(range(4), unit='s')) |
| 157 | + self.panel_dt = Panel(np.random.randn(4, 4, 4), |
| 158 | + items=to_timedelta(range(4), unit='s')) |
| 159 | + |
153 | 160 | # form agglomerates
|
154 | 161 | for o in self._objs:
|
155 | 162 |
|
@@ -723,6 +730,15 @@ def test_loc_setitem_slice(self):
|
723 | 730 | dtype='uint64')
|
724 | 731 | tm.assert_frame_equal(df2, expected)
|
725 | 732 |
|
| 733 | + # GH 14946 |
| 734 | + # Setting time_delta |
| 735 | + |
| 736 | + df = DataFrame({'x': range(5)}, index=to_timedelta(range(5))) |
| 737 | + test_series = df.copy()['x'] |
| 738 | + test_series[test_series < 2] = 10 |
| 739 | + df.loc[df['x'] < 2, 'x'] = 10 |
| 740 | + tm.assert_series_equal(test_series, df['x']) |
| 741 | + |
726 | 742 | def test_ix_loc_setitem_consistency(self):
|
727 | 743 |
|
728 | 744 | # GH 5771
|
@@ -1214,7 +1230,7 @@ def test_loc_getitem_bool(self):
|
1214 | 1230 | # boolean indexers
|
1215 | 1231 | b = [True, False, True, False]
|
1216 | 1232 | self.check_result('bool', 'loc', b, 'ix', b,
|
1217 |
| - typs=['ints', 'labels', 'mixed', 'ts', 'floats']) |
| 1233 | + typs=['ints', 'labels', 'mixed', 'ts', 'floats', 'dt']) |
1218 | 1234 | self.check_result('bool', 'loc', b, 'ix', b, typs=['empty'],
|
1219 | 1235 | fails=KeyError)
|
1220 | 1236 |
|
|
0 commit comments