8000 BUG: fix mutation of DTI backing Series/DataFrame by jbrockmendel · Pull Request #24096 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

BUG: fix mutation of DTI backing Series/DataFrame #24096

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

Merged
merged 8 commits into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

8000
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
GH references
  • Loading branch information
jbrockmendel committed Dec 4, 2018
commit 616aaf78f0389531faedf4d6e6e678c66904dae1
4 changes: 2 additions & 2 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ def setitem(self, indexer, value):

if (self._holder is not None and
issubclass(self._holder, ABCIndexClass)):
# avoid altering Index objects in place
# GH#24096 avoid altering Index objects in place
values = values.copy()

# value must be storeable at this moment
Expand Down Expand Up @@ -2929,7 +2929,7 @@ def _try_coerce_result(self, result):
if result.ndim > 1:
result = result.reshape(np.prod(result.shape))

# new values invalidates a frequency
# GH#24096 new values invalidates a frequency
result = self.values._shallow_copy(result, freq=None)

return result
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/frame/test_block_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

class TestDataFrameBlockInternals():
def test_setitem_invalidates_datetime_index_freq(self):
# altering a datetime64tz column inplace invalidates the `freq`
# attribute on the underlying DatetimeIndex
# GH#24096 altering a datetime64tz column inplace invalidates the
# `freq` attribute on the underlying DatetimeIndex

df = DataFrame({'B': date_range('20130101', periods=3,
tz='US/Eastern')})
Expand All @@ -52,7 +52,7 @@ def test_setitem_invalidates_datetime_index_freq(self):
assert dti[1] == ts

def test_dt64tz_setitem_does_not_mutate_dti(self):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is not a series.test_block_internals; not sure if there is somewhere else this might belong

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls create one

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

# GH#21907
# GH#21907, GH#24096
dti = pd.date_range('2016-01-01', periods=10, tz='US/Pacific')
ts = dti[0]
ser = pd.Series(dti)
Expand Down
0