@@ -260,26 +260,28 @@ def test_dataframe_from_dict_of_series_with_reindex(dtype):
260
260
assert np .shares_memory (arr_before , arr_after )
261
261
262
262
263
+ @pytest .mark .parametrize ("cons" , [Series , Index ])
263
264
@pytest .mark .parametrize (
264
265
"data, dtype" , [([1 , 2 ], None ), ([1 , 2 ], "int64" ), (["a" , "b" ], None )]
265
266
)
266
- def test_dataframe_from_series (using_copy_on_write , data , dtype ):
267
- ser = Series (data , dtype = dtype )
268
- ser_orig = ser .copy ()
269
- df = DataFrame (ser , dtype = dtype )
270
- assert np .shares_memory (get_array (ser ), get_array (df , 0 ))
267
+ def test_dataframe_from_series_or_index (using_copy_on_write , data , dtype , cons ):
268
+ obj = cons (data , dtype = dtype )
269
+ obj_orig = obj .copy ()
270
+ df = DataFrame (obj , dtype = dtype )
271
+ assert np .shares_memory (get_array (obj ), get_array (df , 0 ))
271
272
if using_copy_on_write :
272
273
assert not df ._mgr ._has_no_reference (0 )
273
274
274
275
df .iloc [0 , 0 ] = data [- 1 ]
275
276
if using_copy_on_write :
276
- tm .assert_series_equal ( ser , ser_orig )
277
+ tm .assert_equal ( obj , obj_orig )
277
278
278
279
279
- def test_dataframe_from_series_different_dtype (using_copy_on_write ):
280
- ser = Series ([1 , 2 ], dtype = "int64" )
281
- df = DataFrame (ser , dtype = "int32" )
282
- assert not np .shares_memory (get_array (ser ), get_array (df , 0 ))
280
+ @pytest .mark .parametrize ("cons" , [Series , Index ])
281
+ def test_dataframe_from_series_or_index_different_dtype (using_copy_on_write , cons ):
282
+ obj = cons ([1 , 2 ], dtype = "int64" )
283
+ df = DataFrame (obj , dtype = "int32" )
284
+ assert not np .shares_memory (get_array (obj ), get_array (df , 0 ))
283
285
if using_copy_on_write :
284
286
assert df ._mgr ._has_no_reference (0 )
285
287
0 commit comments