@@ -30,7 +30,7 @@ def test_series_from_series(dtype, using_copy_on_write):
30
30
result = Series (ser , dtype = dtype )
31
31
32
32
# the shallow copy still shares memory
33
- assert np .shares_memory (ser . values , result . values )
33
+ assert np .shares_memory (get_array ( ser ), get_array ( result ) )
34
34
35
35
if using_copy_on_write :
36
36
assert result ._mgr .blocks [0 ].refs .has_reference ()
@@ -40,13 +40,13 @@ def test_series_from_series(dtype, using_copy_on_write):
40
40
result .iloc [0 ] = 0
41
41
assert ser .iloc [0 ] == 1
42
42
# mutating triggered a copy-on-write -> no longer shares memory
43
- assert not np .shares_memory (ser . values , result . values )
43
+ assert not np .shares_memory (get_array ( ser ), get_array ( result ) )
44
44
else :
45
45
# mutating shallow copy does mutate original
46
46
result .iloc [0 ] = 0
47
47
assert ser .iloc [0 ] == 0
48
48
# and still shares memory
49
- assert np .shares_memory (ser . values , result . values )
49
+ assert np .shares_memory (get_array ( ser ), get_array ( result ) )
50
50
51
51
# the same when modifying the parent
52
52
result = Series (ser , dtype = dtype )
@@ -90,6 +90,38 @@ def test_series_from_series_with_reindex(using_copy_on_write):
90
90
assert not result ._mgr .blocks [0 ].refs .has_reference ()
91
91
92
92
93
+ @pytest .mark .parametrize ("fastpath" , [False , True ])
94
+ @pytest .mark .parametrize ("dtype" , [None , "int64" ])
95
+ @pytest .mark .parametrize ("idx" , [None , pd .RangeIndex (start = 0 , stop = 3 , step = 1 )])
96
+ @pytest .mark .parametrize (
97
+ "arr" , [np .array ([1 , 2 , 3 ], dtype = "int64" ), pd .array ([1 , 2 , 3 ], dtype = "Int64" )]
98
+ )
99
+ def test_series_from_array (using_copy_on_write , idx , dtype , fastpath , arr ):
100
+ if idx is None or dtype is not None :
101
+ fastpath = False
102
+ ser = Series (arr , dtype = dtype , index = idx , fastpath = fastpath )
103
+ ser_orig = ser .copy ()
104
+ data = getattr (arr , "_data" , arr )
105
+ if using_copy_on_write :
106
+ assert not np .shares_memory (get_array (ser ), data )
107
+ else :
108
+ assert np .shares_memory (get_array (ser ), data )
109
+
110
+ arr [0 ] = 100
111
+ if using_copy_on_write :
112
+ tm .assert_series_equal (ser , ser_orig )
113
+ else :
114
+ expected = Series ([100 , 2 , 3 ], dtype = dtype if dtype is not None else arr .dtype )
115
+ tm .assert_series_equal (ser , expected )
116
+
117
+
118
+ @pytest .mark .parametrize ("copy" , [True , False , None ])
119
+ def test_series_from_array_different_dtype (using_copy_on_write , copy ):
120
+ arr = np .array ([1 , 2 , 3 ], dtype = "int64" )
121
+ ser = Series (arr , dtype = "int32" , copy = copy )
122
+ assert not np .shares_memory (get_array (ser ), arr )
123
+
124
+
93
125
@pytest .mark .parametrize (
94
126
"idx" ,
95
127
[
0 commit comments