Skip to content
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

BUG: setitem with boolean mask and tz-aware DTI #16897

Merged
merged 1 commit into from
Jul 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/source/whatsnew/v0.21.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ Indexing
- Fix :func:`MultiIndex.sort_index` ordering when ``ascending`` argument is a list, but not all levels are specified, or are in a different order (:issue:`16934`).
- Fixes bug where indexing with ``np.inf`` caused an ``OverflowError`` to be raised (:issue:`16957`)
- Bug in reindexing on an empty ``CategoricalIndex`` (:issue:`16770`)

- Fixes ``DataFrame.loc`` for setting with alignment and tz-aware ``DatetimeIndex`` (:issue:`16889`)

I/O
^^^

Expand Down
6 changes: 4 additions & 2 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,10 +760,12 @@ def _align_frame(self, indexer, df):
for i, ix in enumerate(indexer):
ax = self.obj.axes[i]
if is_sequence(ix) or isinstance(ix, slice):
if isinstance(ix, np.ndarray):
ix = ix.ravel()
if idx is None:
idx = ax[ix].ravel()
idx = ax[ix]
elif cols is None:
cols = ax[ix].ravel()
cols = ax[ix]
else:
break
else:
Expand Down
27 changes: 27 additions & 0 deletions pandas/tests/indexing/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,33 @@

class TestDatetimeIndex(object):

def test_setitem_with_datetime_tz(self):
# 16889
# support .loc with alignment and tz-aware DatetimeIndex
mask = np.array([True, False, True, False])

idx = pd.date_range('20010101', periods=4, tz='UTC')
df = pd.DataFrame({'a': np.arange(4)}, index=idx).astype('float64')

result = df.copy()
result.loc[mask, :] = df.loc[mask, :]
tm.assert_frame_equal(result, df)

result = df.copy()
result.loc[mask] = df.loc[mask]
tm.assert_frame_equal(result, df)

idx = pd.date_range('20010101', periods=4)
df = pd.DataFrame({'a': np.arange(4)}, index=idx).astype('float64')

result = df.copy()
result.loc[mask, :] = df.loc[mask, :]
tm.assert_frame_equal(result, df)

result = df.copy()
result.loc[mask] = df.loc[mask]
tm.assert_frame_equal(result, df)

def test_indexing_with_datetime_tz(self):

# 8260
Expand Down