Skip to content

Commit 1856dea

Browse files
committed
Fix Bug #21907
1 parent 63eff04 commit 1856dea

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

doc/source/whatsnew/v0.24.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ Indexing
434434
- Fixed ``DataFrame[np.nan]`` when columns are non-unique (:issue:`21428`)
435435
- Bug when indexing :class:`DatetimeIndex` with nanosecond resolution dates and timezones (:issue:`11679`)
436436
- Bug where indexing with a Numpy array containing negative values would mutate the indexer (:issue:`21867`)
437-
437+
- Bug when :class:`Series` was created from :class:`DatetimeIndex`, the series shares the same underneath data with that index (:issue:`21907`)
438438
Missing
439439
^^^^^^^
440440

pandas/core/series.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,11 @@ def __init__(self, data=None, index=None, dtype=None, name=None,
206206
data = data.astype(dtype)
207207
else:
208208
# need to copy to avoid aliasing issues
209-
data = data._values.copy()
209+
# GH21907
210+
if isinstance(data, DatetimeIndex):
211+
data = data.copy(deep=True)
212+
else:
213+
data = data._values.copy()
210214
copy = False
211215

212216
elif isinstance(data, np.ndarray):

0 commit comments

Comments
 (0)