diff --git a/doc/source/whatsnew/v0.18.0.txt b/doc/source/whatsnew/v0.18.0.txt index a534c3ec0017a..de5439885a6a7 100644 --- a/doc/source/whatsnew/v0.18.0.txt +++ b/doc/source/whatsnew/v0.18.0.txt @@ -92,7 +92,7 @@ In addition, ``.round()`` will be available thru the ``.dt`` accessor of ``Serie Backwards incompatible API changes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- The parameter ``out`` has been removed from the ``Series.round()`` method. (:issue:`11763`) +- The parameter ``out`` has been removed from the ``Series.round()`` method. (:issue:`11763`) Bug in QuarterBegin with n=0 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -189,7 +189,7 @@ Bug Fixes - Bug in ``GroupBy.size`` when data-frame is empty. (:issue:`11699`) - Bug in ``Period.end_time`` when a multiple of time period is requested (:issue:`11738`) - +- Regression in ``.clip`` with tz-aware datetimes (:issue:`11838`) diff --git a/pandas/core/internals.py b/pandas/core/internals.py index bf63e9a3cab45..123dca9f3ee5c 100644 --- a/pandas/core/internals.py +++ b/pandas/core/internals.py @@ -1215,10 +1215,6 @@ def func(cond, values, other): result = func(cond, values, other) if self._can_hold_na or self.ndim == 1: - if not isinstance(result, np.ndarray): - raise TypeError('Could not compare [%s] with block values' - % repr(other)) - if transpose: result = result.T diff --git a/pandas/tests/test_series.py b/pandas/tests/test_series.py index 34d2d0de35977..099e86a44d188 100644 --- a/pandas/tests/test_series.py +++ b/pandas/tests/test_series.py @@ -3008,16 +3008,16 @@ def test_round(self): name='ts') assert_series_equal(result, expected) self.assertEqual(result.name, self.ts.name) - + def test_built_in_round(self): if not compat.PY3: raise nose.SkipTest('build in round cannot be overriden prior to Python 3') - + s = Series([1.123, 2.123, 3.123], index=lrange(3)) result = round(s) expected_rounded0 = Series([1., 2., 3.], index=lrange(3)) self.assert_series_equal(result, expected_rounded0) - + decimals = 2 expected_rounded = Series([1.12, 2.12, 3.12], index=lrange(3)) result = round(s, decimals) @@ -5844,6 +5844,24 @@ def test_clip_against_series(self): assert_series_equal(s.clip(lower, upper), Series([1.0, 2.0, 3.5])) assert_series_equal(s.clip(1.5, upper), Series([1.5, 1.5, 3.5])) + + def test_clip_with_datetimes(self): + + # GH 11838 + # naive and tz-aware datetimes + + t = Timestamp('2015-12-01 09:30:30') + s = Series([ Timestamp('2015-12-01 09:30:00'), Timestamp('2015-12-01 09:31:00') ]) + result = s.clip(upper=t) + expected = Series([ Timestamp('2015-12-01 09:30:00'), Timestamp('2015-12-01 09:30:30') ]) + assert_series_equal(result, expected) + + t = Timestamp('2015-12-01 09:30:30', tz='US/Eastern') + s = Series([ Timestamp('2015-12-01 09:30:00', tz='US/Eastern'), Timestamp('2015-12-01 09:31:00', tz='US/Eastern') ]) + result = s.clip(upper=t) + expected = Series([ Timestamp('2015-12-01 09:30:00', tz='US/Eastern'), Timestamp('2015-12-01 09:30:30', tz='US/Eastern') ]) + assert_series_equal(result, expected) + def test_valid(self): ts = self.ts.copy() ts[::2] = np.NaN