Skip to content

Commit 72b7ee5

Browse files
committed
1 parent 1250500 commit 72b7ee5

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

doc/source/whatsnew/v0.24.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,7 @@ Indexing
13031303
- Bug where setting a timedelta column by ``Index`` causes it to be casted to double, and therefore lose precision (:issue:`23511`)
13041304
- Bug in :func:`Index.union` and :func:`Index.intersection` where name of the ``Index`` of the result was not computed correctly for certain cases (:issue:`9943`, :issue:`9862`)
13051305
- Bug in :class:`Index` slicing with boolean :class:`Index` may raise ``TypeError`` (:issue:`22533`)
1306+
- Bug when :class:`Series` was created from :class:`DatetimeIndex`, the series shares the same underneath data with that index (:issue:`21907`)
13061307

13071308
Missing
13081309
^^^^^^^

pandas/core/series.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,11 @@ def __init__(self, data=None, index=None, dtype=None, name=None,
182182
data = data.astype(dtype)
183183
else:
184184
# need to copy to avoid aliasing issues
185-
data = data._values.copy()
185+
# GH21907
186+
if isinstance(data, DatetimeIndex):
187+
data = data.copy(deep=True)
188+
else:
189+
data = data._values.copy()
186190
copy = False
187191

188192
elif isinstance(data, np.ndarray):

0 commit comments

Comments
 (0)