Skip to content

Commit d359d3b

Browse files
committed
1 parent 2cea659 commit d359d3b

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

doc/source/whatsnew/v0.24.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,7 @@ Indexing
12281228
- Bug where setting a timedelta column by ``Index`` causes it to be casted to double, and therefore lose precision (:issue:`23511`)
12291229
- 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`)
12301230
- Bug in :class:`Index` slicing with boolean :class:`Index` may raise ``TypeError`` (:issue:`22533`)
1231+
- Bug when :class:`Series` was created from :class:`DatetimeIndex`, the series shares the same underneath data with that index (:issue:`21907`)
12311232

12321233
Missing
12331234
^^^^^^^

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)