-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Issues with DatetimeTZ values in where and combine_first (#21469 + #21546) #21660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ac2f836
770a22e
04a0538
6e6c619
8c022d9
96a59f6
deda82c
71a4fd4
7c14643
3d072c5
f812e78
f177ec5
09fe18f
c97b951
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1476,14 +1476,16 @@ def where(self, other, cond, align=True, errors='raise', | |
if transpose: | ||
values = values.T | ||
|
||
other = getattr(other, 'values', other) | ||
other = getattr(other, '_values', getattr(other, 'values', other)) | ||
cond = getattr(cond, 'values', cond) | ||
|
||
# If the default broadcasting would go in the wrong direction, then | ||
# explicitly reshape other instead | ||
if getattr(other, 'ndim', 0) >= 1: | ||
if values.ndim - 1 == other.ndim and axis == 1: | ||
other = other.reshape(tuple(other.shape + (1, ))) | ||
elif transpose and values.ndim == self.ndim - 1: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we really need this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without lines 1487-1488 The issue is DatetimeTZBlock._try_coerce_args returns However, we don't run _try_coerce_args until the interior of func at 1499. Thus lines 1476-1477 ( An alternative would be changing `DatetimeTZBlock._try_coerce_args to return 1-D arrays for values and values_mask (changing 2875-2877). But if I do that it breaks setitem. |
||
cond = cond.T | ||
|
||
if not hasattr(cond, 'shape'): | ||
raise ValueError("where must have a condition that is ndarray " | ||
|
@@ -2888,8 +2890,8 @@ def _try_coerce_args(self, values, other): | |
elif isinstance(other, self._holder): | ||
if other.tz != self.values.tz: | ||
raise ValueError("incompatible or non tz-aware value") | ||
other = other.asi8 | ||
other_mask = isna(other) | ||
other_mask = _block_shape(isna(other), ndim=self.ndim) | ||
other = _block_shape(other.asi8, ndim=self.ndim) | ||
elif isinstance(other, (np.datetime64, datetime, date)): | ||
other = tslib.Timestamp(other) | ||
tz = getattr(other, 'tz', None) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -580,12 +580,11 @@ def test_where_series_datetime64(self, fill_val, exp_dtype): | |
values = pd.Series(pd.date_range(fill_val, periods=4)) | ||
if fill_val.tz: | ||
exp = pd.Series([pd.Timestamp('2011-01-01'), | ||
pd.Timestamp('2012-01-02 05:00'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what changed here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previous behavior was was treating |
||
pd.Timestamp('2012-01-02 00:00', tz='US/Eastern'), | ||
pd.Timestamp('2011-01-03'), | ||
pd.Timestamp('2012-01-04 05:00')]) | ||
self._assert_where_conversion(obj, cond, values, exp, | ||
'datetime64[ns]') | ||
pytest.xfail("ToDo: do not coerce to UTC, must be object") | ||
pd.Timestamp('2012-01-04 00:00', | ||
tz='US/Eastern')]) | ||
self._assert_where_conversion(obj, cond, values, exp, exp_dtype) | ||
|
||
exp = pd.Series([pd.Timestamp('2011-01-01'), values[1], | ||
pd.Timestamp('2011-01-03'), values[3]]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!