Skip to content

Commit 1880400

Browse files
committed
REGR: Regression in .clip with tz-aware datetimes pandas-dev#11838
1 parent 22f0c7e commit 1880400

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

doc/source/whatsnew/v0.18.0.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ In addition, ``.round()`` will be available thru the ``.dt`` accessor of ``Serie
9292
Backwards incompatible API changes
9393
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9494

95-
- The parameter ``out`` has been removed from the ``Series.round()`` method. (:issue:`11763`)
95+
- The parameter ``out`` has been removed from the ``Series.round()`` method. (:issue:`11763`)
9696

9797
Bug in QuarterBegin with n=0
9898
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -189,7 +189,7 @@ Bug Fixes
189189

190190
- Bug in ``GroupBy.size`` when data-frame is empty. (:issue:`11699`)
191191
- Bug in ``Period.end_time`` when a multiple of time period is requested (:issue:`11738`)
192-
192+
- Regression in ``.clip`` with tz-aware datetimes (:issue:`11838`)
193193

194194

195195

pandas/core/internals.py

-4
Original file line numberDiff line numberDiff line change
@@ -1215,10 +1215,6 @@ def func(cond, values, other):
12151215
result = func(cond, values, other)
12161216
if self._can_hold_na or self.ndim == 1:
12171217

1218-
if not isinstance(result, np.ndarray):
1219-
raise TypeError('Could not compare [%s] with block values'
1220-
% repr(other))
1221-
12221218
if transpose:
12231219
result = result.T
12241220

pandas/tests/test_series.py

+21-3
Original file line numberDiff line numberDiff line change
@@ -3008,16 +3008,16 @@ def test_round(self):
30083008
name='ts')
30093009
assert_series_equal(result, expected)
30103010
self.assertEqual(result.name, self.ts.name)
3011-
3011+
30123012
def test_built_in_round(self):
30133013
if not compat.PY3:
30143014
raise nose.SkipTest('build in round cannot be overriden prior to Python 3')
3015-
3015+
30163016
s = Series([1.123, 2.123, 3.123], index=lrange(3))
30173017
result = round(s)
30183018
expected_rounded0 = Series([1., 2., 3.], index=lrange(3))
30193019
self.assert_series_equal(result, expected_rounded0)
3020-
3020+
30213021
decimals = 2
30223022
expected_rounded = Series([1.12, 2.12, 3.12], index=lrange(3))
30233023
result = round(s, decimals)
@@ -5844,6 +5844,24 @@ def test_clip_against_series(self):
58445844
assert_series_equal(s.clip(lower, upper), Series([1.0, 2.0, 3.5]))
58455845
assert_series_equal(s.clip(1.5, upper), Series([1.5, 1.5, 3.5]))
58465846

5847+
5848+
def test_clip_with_datetimes(self):
5849+
5850+
# GH 11838
5851+
# naive and tz-aware datetimes
5852+
5853+
t = Timestamp('2015-12-01 09:30:30')
5854+
s = Series([ Timestamp('2015-12-01 09:30:00'), Timestamp('2015-12-01 09:31:00') ])
5855+
result = s.clip(upper=t)
5856+
expected = Series([ Timestamp('2015-12-01 09:30:00'), Timestamp('2015-12-01 09:30:30') ])
5857+
assert_series_equal(result, expected)
5858+
5859+
t = Timestamp('2015-12-01 09:30:30', tz='US/Eastern')
5860+
s = Series([ Timestamp('2015-12-01 09:30:00', tz='US/Eastern'), Timestamp('2015-12-01 09:31:00', tz='US/Eastern') ])
5861+
result = s.clip(upper=t)
5862+
expected = Series([ Timestamp('2015-12-01 09:30:00', tz='US/Eastern'), Timestamp('2015-12-01 09:30:30', tz='US/Eastern') ])
5863+
assert_series_equal(result, expected)
5864+
58475865
def test_valid(self):
58485866
ts = self.ts.copy()
58495867
ts[::2] = np.NaN

0 commit comments

Comments
 (0)