Repository: pandas-dev/pandas

Issue:
REGR: .clip and datetime w/timezone
There seem to be some incompatibilities with timezones and timestamps in 0.17.1.

For example, here I'm trying to clip a timezone-aware column with a timezone-aware timestamp:

```
In [224]: import pandas

In [225]: u = pandas.Timestamp('2015-12-01 09:30:30', tz='US/Eastern')

In [226]: print u
2015-12-01 09:30:30-05:00

In [227]: df = pandas.DataFrame({ 'foo' : [ pandas.Timestamp('2015-12-01 09:30:00', tz='US/Eastern'), pandas.Timestamp('2015-12-01 09:31:00', tz='US/Eastern') ] })

In [228]: print df
                        foo
0 2015-12-01 09:30:00-05:00
1 2015-12-01 09:31:00-05:00

In [229]: df['foo'].clip(upper=u)

TypeError: Could not compare [Timestamp('2015-12-01 09:30:30-0500', tz='US/Eastern')] with block values
```

This code used to work on 0.16.2.



Discussion:
yep, a buggie. pull-requests to remedy are welcomed.


Resolving patch:
diff --git a/pandas/core/internals.py b/pandas/core/internals.py
--- 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
 


Test patch:
diff --git a/pandas/tests/test_series.py b/pandas/tests/test_series.py
--- 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