Skip to content

Commit 91e78da

Browse files
TST: Add regression tests for GH#63388 (PeriodIndex copy behavior)
1 parent b55f4a0 commit 91e78da

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

pandas/tests/copy_view/index/test_periodindex.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
import numpy as np
12
import pytest
23

34
from pandas import (
45
Period,
56
PeriodIndex,
67
Series,
78
period_range,
9+
array
810
)
911
import pandas._testing as tm
12+
from pandas.tests.copy_view.util import get_array
1013

1114
pytestmark = pytest.mark.filterwarnings(
1215
"ignore:Setting a value on a view:FutureWarning"
@@ -21,3 +24,24 @@ def test_periodindex(box):
2124
expected = idx.copy(deep=True)
2225
ser.iloc[0] = Period("2020-12-31")
2326
tm.assert_index_equal(idx, expected)
27+
28+
29+
def test_constructor_copy_input_period_ea_default():
30+
# GH 63388
31+
arr = array(['2020-01-01', '2020-01-02'], dtype='period[D]')
32+
idx = PeriodIndex(arr)
33+
assert not tm.shares_memory(arr, idx.array)
34+
35+
36+
def test_series_from_temporary_periodindex_readonly_data():
37+
# GH 63388
38+
arr = array(['2020-01-01', '2020-01-02'], dtype='period[D]')
39+
arr._ndarray.flags.writeable = False
40+
ser = Series(PeriodIndex(arr))
41+
assert not np.shares_memory(arr._ndarray, get_array(ser))
42+
ser.iloc[0] = Period('2022-01-01', freq='D')
43+
expected = Series(
44+
[Period('2022-01-01', freq='D'), Period('2020-01-02', freq='D')],
45+
dtype='period[D]'
46+
)
47+
tm.assert_series_equal(ser, expected)

0 commit comments

Comments
 (0)