forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BUG: fix mutation of DTI backing Series/DataFrame (pandas-dev#24096)
- Loading branch information
1 parent
aead29b
commit cb862e4
Showing
5 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import pandas as pd | ||
|
||
# Segregated collection of methods that require the BlockManager internal data | ||
# structure | ||
|
||
|
||
class TestSeriesBlockInternals(object): | ||
|
||
def test_setitem_invalidates_datetime_index_freq(self): | ||
# GH#24096 altering a datetime64tz Series inplace invalidates the | ||
# `freq` attribute on the underlying DatetimeIndex | ||
|
||
dti = pd.date_range('20130101', periods=3, tz='US/Eastern') | ||
ts = dti[1] | ||
ser = pd.Series(dti) | ||
assert ser._values is not dti | ||
assert ser._values._data.base is not dti._data.base | ||
assert dti.freq == 'D' | ||
ser.iloc[1] = pd.NaT | ||
assert ser._values.freq is None | ||
|
||
# check that the DatetimeIndex was not altered in place | ||
assert ser._values is not dti | ||
assert ser._values._data.base is not dti._data.base | ||
assert dti[1] == ts | ||
assert dti.freq == 'D' | ||
|
||
def test_dt64tz_setitem_does_not_mutate_dti(self): | ||
# GH#21907, GH#24096 | ||
dti = pd.date_range('2016-01-01', periods=10, tz='US/Pacific') | ||
ts = dti[0] | ||
ser = pd.Series(dti) | ||
assert ser._values is not dti | ||
assert ser._values._data.base is not dti._data.base | ||
assert ser._data.blocks[0].values is not dti | ||
assert ser._data.blocks[0].values._data.base is not dti._data.base | ||
|
||
ser[::3] = pd.NaT | ||
assert ser[0] is pd.NaT | ||
assert dti[0] == ts |