Skip to content

Commit f1de9c7

Browse files
authored
DEPR: Remove array manager branches from tests (#56621)
1 parent 58b1d12 commit f1de9c7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+171
-487
lines changed

pandas/conftest.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,14 +1877,6 @@ def indexer_ial(request):
18771877
return request.param
18781878

18791879

1880-
@pytest.fixture
1881-
def using_array_manager() -> bool:
1882-
"""
1883-
Fixture to check if the array manager is being used.
1884-
"""
1885-
return _get_option("mode.data_manager", silent=True) == "array"
1886-
1887-
18881880
@pytest.fixture
18891881
def using_copy_on_write() -> bool:
18901882
"""

pandas/tests/apply/test_frame_apply.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,7 @@ def test_apply_dtype(col):
14871487
tm.assert_series_equal(result, expected)
14881488

14891489

1490-
def test_apply_mutating(using_array_manager, using_copy_on_write, warn_copy_on_write):
1490+
def test_apply_mutating(using_copy_on_write, warn_copy_on_write):
14911491
# GH#35462 case where applied func pins a new BlockManager to a row
14921492
df = DataFrame({"a": range(100), "b": range(100, 200)})
14931493
df_orig = df.copy()
@@ -1505,7 +1505,7 @@ def func(row):
15051505
result = df.apply(func, axis=1)
15061506

15071507
tm.assert_frame_equal(result, expected)
1508-
if using_copy_on_write or using_array_manager:
1508+
if using_copy_on_write:
15091509
# INFO(CoW) With copy on write, mutating a viewing row doesn't mutate the parent
15101510
# INFO(ArrayManager) With BlockManager, the row is a view and mutated in place,
15111511
# with ArrayManager the row is not a view, and thus not mutated in place

pandas/tests/arithmetic/test_numeric.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -586,16 +586,12 @@ def test_df_div_zero_series_does_not_commute(self):
586586
# ------------------------------------------------------------------
587587
# Mod By Zero
588588

589-
def test_df_mod_zero_df(self, using_array_manager):
589+
def test_df_mod_zero_df(self):
590590
# GH#3590, modulo as ints
591591
df = pd.DataFrame({"first": [3, 4, 5, 8], "second": [0, 0, 0, 3]})
592592
# this is technically wrong, as the integer portion is coerced to float
593593
first = Series([0, 0, 0, 0])
594-
if not using_array_manager:
595-
# INFO(ArrayManager) BlockManager doesn't preserve dtype per column
596-
# while ArrayManager performs op column-wisedoes and thus preserves
597-
# dtype if possible
598-
first = first.astype("float64")
594+
first = first.astype("float64")
599595
second = Series([np.nan, np.nan, np.nan, 0])
600596
expected = pd.DataFrame({"first": first, "second": second})
601597
result = df % df

pandas/tests/arithmetic/test_timedelta64.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,9 +1736,7 @@ def test_td64_div_object_mixed_result(self, box_with_array):
17361736
# ------------------------------------------------------------------
17371737
# __floordiv__, __rfloordiv__
17381738

1739-
def test_td64arr_floordiv_td64arr_with_nat(
1740-
self, box_with_array, using_array_manager
1741-
):
1739+
def test_td64arr_floordiv_td64arr_with_nat(self, box_with_array):
17421740
# GH#35529
17431741
box = box_with_array
17441742
xbox = np.ndarray if box is pd.array else box
@@ -1751,11 +1749,6 @@ def test_td64arr_floordiv_td64arr_with_nat(
17511749

17521750
expected = np.array([1.0, 1.0, np.nan], dtype=np.float64)
17531751
expected = tm.box_expected(expected, xbox)
1754-
if box is DataFrame and using_array_manager:
1755-
# INFO(ArrayManager) floordiv returns integer, and ArrayManager
1756-
# performs ops column-wise and thus preserves int64 dtype for
1757-
# columns without missing values
1758-
expected[[0, 1]] = expected[[0, 1]].astype("int64")
17591752

17601753
with tm.maybe_produces_warning(
17611754
RuntimeWarning, box is pd.array, check_stacklevel=False

pandas/tests/copy_view/test_array.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_series_values(using_copy_on_write, method):
4848
[lambda df: df.values, lambda df: np.asarray(df)],
4949
ids=["values", "asarray"],
5050
)
51-
def test_dataframe_values(using_copy_on_write, using_array_manager, method):
51+
def test_dataframe_values(using_copy_on_write, method):
5252
df = DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
5353
df_orig = df.copy()
5454

@@ -70,10 +70,7 @@ def test_dataframe_values(using_copy_on_write, using_array_manager, method):
7070
else:
7171
assert arr.flags.writeable is True
7272
arr[0, 0] = 0
73-
if not using_array_manager:
74-
assert df.iloc[0, 0] == 0
75-
else:
76-
tm.assert_frame_equal(df, df_orig)
73+
assert df.iloc[0, 0] == 0
7774

7875

7976
def test_series_to_numpy(using_copy_on_write):
@@ -157,11 +154,10 @@ def test_dataframe_array_ea_dtypes(using_copy_on_write):
157154
assert arr.flags.writeable is True
158155

159156

160-
def test_dataframe_array_string_dtype(using_copy_on_write, using_array_manager):
157+
def test_dataframe_array_string_dtype(using_copy_on_write):
161158
df = DataFrame({"a": ["a", "b"]}, dtype="string")
162159
arr = np.asarray(df)
163-
if not using_array_manager:
164-
assert np.shares_memory(arr, get_array(df, "a"))
160+
assert np.shares_memory(arr, get_array(df, "a"))
165161
if using_copy_on_write:
166162
assert arr.flags.writeable is False
167163
else:

pandas/tests/copy_view/test_constructors.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -339,16 +339,11 @@ def test_dataframe_from_dict_of_series_with_dtype(index):
339339

340340

341341
@pytest.mark.parametrize("copy", [False, None, True])
342-
def test_frame_from_numpy_array(using_copy_on_write, copy, using_array_manager):
342+
def test_frame_from_numpy_array(using_copy_on_write, copy):
343343
arr = np.array([[1, 2], [3, 4]])
344344
df = DataFrame(arr, copy=copy)
345345

346-
if (
347-
using_copy_on_write
348-
and copy is not False
349-
or copy is True
350-
or (using_array_manager and copy is None)
351-
):
346+
if using_copy_on_write and copy is not False or copy is True:
352347
assert not np.shares_memory(get_array(df, 0), arr)
353348
else:
354349
assert np.shares_memory(get_array(df, 0), arr)

pandas/tests/copy_view/test_indexing.py

Lines changed: 23 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,11 @@ def test_subset_row_slice(backend, using_copy_on_write, warn_copy_on_write):
140140
@pytest.mark.parametrize(
141141
"dtype", ["int64", "float64"], ids=["single-block", "mixed-block"]
142142
)
143-
def test_subset_column_slice(
144-
backend, using_copy_on_write, warn_copy_on_write, using_array_manager, dtype
145-
):
143+
def test_subset_column_slice(backend, using_copy_on_write, warn_copy_on_write, dtype):
146144
# Case: taking a subset of the columns of a DataFrame using a slice
147145
# + afterwards modifying the subset
148146
dtype_backend, DataFrame, _ = backend
149-
single_block = (
150-
dtype == "int64" and dtype_backend == "numpy"
151-
) and not using_array_manager
147+
single_block = dtype == "int64" and dtype_backend == "numpy"
152148
df = DataFrame(
153149
{"a": [1, 2, 3], "b": [4, 5, 6], "c": np.array([7, 8, 9], dtype=dtype)}
154150
)
@@ -176,7 +172,7 @@ def test_subset_column_slice(
176172
tm.assert_frame_equal(subset, expected)
177173
# original parent dataframe is not modified (also not for BlockManager case,
178174
# except for single block)
179-
if not using_copy_on_write and (using_array_manager or single_block):
175+
if not using_copy_on_write and single_block:
180176
df_orig.iloc[0, 1] = 0
181177
tm.assert_frame_equal(df, df_orig)
182178
else:
@@ -201,7 +197,6 @@ def test_subset_loc_rows_columns(
201197
dtype,
202198
row_indexer,
203199
column_indexer,
204-
using_array_manager,
205200
using_copy_on_write,
206201
warn_copy_on_write,
207202
):
@@ -224,14 +219,7 @@ def test_subset_loc_rows_columns(
224219
mutate_parent = (
225220
isinstance(row_indexer, slice)
226221
and isinstance(column_indexer, slice)
227-
and (
228-
using_array_manager
229-
or (
230-
dtype == "int64"
231-
and dtype_backend == "numpy"
232-
and not using_copy_on_write
233-
)
234-
)
222+
and (dtype == "int64" and dtype_backend == "numpy" and not using_copy_on_write)
235223
)
236224

237225
# modifying the subset never modifies the parent
@@ -265,7 +253,6 @@ def test_subset_iloc_rows_columns(
265253
dtype,
266254
row_indexer,
267255
column_indexer,
268-
using_array_manager,
269256
using_copy_on_write,
270257
warn_copy_on_write,
271258
):
@@ -288,14 +275,7 @@ def test_subset_iloc_rows_columns(
288275
mutate_parent = (
289276
isinstance(row_indexer, slice)
290277
and isinstance(column_indexer, slice)
291-
and (
292-
using_array_manager
293-
or (
294-
dtype == "int64"
295-
and dtype_backend == "numpy"
296-
and not using_copy_on_write
297-
)
298-
)
278+
and (dtype == "int64" and dtype_backend == "numpy" and not using_copy_on_write)
299279
)
300280

301281
# modifying the subset never modifies the parent
@@ -422,7 +402,7 @@ def test_subset_set_column(backend, using_copy_on_write, warn_copy_on_write):
422402
"dtype", ["int64", "float64"], ids=["single-block", "mixed-block"]
423403
)
424404
def test_subset_set_column_with_loc(
425-
backend, using_copy_on_write, warn_copy_on_write, using_array_manager, dtype
405+
backend, using_copy_on_write, warn_copy_on_write, dtype
426406
):
427407
# Case: setting a single column with loc on a viewing subset
428408
# -> subset.loc[:, col] = value
@@ -440,10 +420,7 @@ def test_subset_set_column_with_loc(
440420
subset.loc[:, "a"] = np.array([10, 11], dtype="int64")
441421
else:
442422
with pd.option_context("chained_assignment", "warn"):
443-
with tm.assert_produces_warning(
444-
None,
445-
raise_on_extra_warnings=not using_array_manager,
446-
):
423+
with tm.assert_produces_warning(None):
447424
subset.loc[:, "a"] = np.array([10, 11], dtype="int64")
448425

449426
subset._mgr._verify_integrity()
@@ -461,9 +438,7 @@ def test_subset_set_column_with_loc(
461438
tm.assert_frame_equal(df, df_orig)
462439

463440

464-
def test_subset_set_column_with_loc2(
465-
backend, using_copy_on_write, warn_copy_on_write, using_array_manager
466-
):
441+
def test_subset_set_column_with_loc2(backend, using_copy_on_write, warn_copy_on_write):
467442
# Case: setting a single column with loc on a viewing subset
468443
# -> subset.loc[:, col] = value
469444
# separate test for case of DataFrame of a single column -> takes a separate
@@ -480,10 +455,7 @@ def test_subset_set_column_with_loc2(
480455
subset.loc[:, "a"] = 0
481456
else:
482457
with pd.option_context("chained_assignment", "warn"):
483-
with tm.assert_produces_warning(
484-
None,
485-
raise_on_extra_warnings=not using_array_manager,
486-
):
458+
with tm.assert_produces_warning(None):
487459
subset.loc[:, "a"] = 0
488460

489461
subset._mgr._verify_integrity()
@@ -600,7 +572,6 @@ def test_subset_chained_getitem(
600572
method,
601573
dtype,
602574
using_copy_on_write,
603-
using_array_manager,
604575
warn_copy_on_write,
605576
):
606577
# Case: creating a subset using multiple, chained getitem calls using views
@@ -614,17 +585,10 @@ def test_subset_chained_getitem(
614585
# when not using CoW, it depends on whether we have a single block or not
615586
# and whether we are slicing the columns -> in that case we have a view
616587
test_callspec = request.node.callspec.id
617-
if not using_array_manager:
618-
subset_is_view = test_callspec in (
619-
"numpy-single-block-column-iloc-slice",
620-
"numpy-single-block-column-loc-slice",
621-
)
622-
else:
623-
# with ArrayManager, it doesn't matter whether we have
624-
# single vs mixed block or numpy vs nullable dtypes
625-
subset_is_view = test_callspec.endswith(
626-
("column-iloc-slice", "column-loc-slice")
627-
)
588+
subset_is_view = test_callspec in (
589+
"numpy-single-block-column-iloc-slice",
590+
"numpy-single-block-column-loc-slice",
591+
)
628592

629593
# modify subset -> don't modify parent
630594
subset = method(df)
@@ -726,9 +690,7 @@ def test_subset_chained_getitem_series(
726690
assert subset.iloc[0] == 0
727691

728692

729-
def test_subset_chained_single_block_row(
730-
using_copy_on_write, using_array_manager, warn_copy_on_write
731-
):
693+
def test_subset_chained_single_block_row(using_copy_on_write, warn_copy_on_write):
732694
# not parametrizing this for dtype backend, since this explicitly tests single block
733695
df = DataFrame({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]})
734696
df_orig = df.copy()
@@ -737,7 +699,7 @@ def test_subset_chained_single_block_row(
737699
subset = df[:].iloc[0].iloc[0:2]
738700
with tm.assert_cow_warning(warn_copy_on_write):
739701
subset.iloc[0] = 0
740-
if using_copy_on_write or using_array_manager:
702+
if using_copy_on_write:
741703
tm.assert_frame_equal(df, df_orig)
742704
else:
743705
assert df.iloc[0, 0] == 0
@@ -747,7 +709,7 @@ def test_subset_chained_single_block_row(
747709
with tm.assert_cow_warning(warn_copy_on_write):
748710
df.iloc[0, 0] = 0
749711
expected = Series([1, 4], index=["a", "b"], name=0)
750-
if using_copy_on_write or using_array_manager:
712+
if using_copy_on_write:
751713
tm.assert_series_equal(subset, expected)
752714
else:
753715
assert subset.iloc[0] == 0
@@ -967,9 +929,7 @@ def test_del_series(backend):
967929
# Accessing column as Series
968930

969931

970-
def test_column_as_series(
971-
backend, using_copy_on_write, warn_copy_on_write, using_array_manager
972-
):
932+
def test_column_as_series(backend, using_copy_on_write, warn_copy_on_write):
973933
# Case: selecting a single column now also uses Copy-on-Write
974934
dtype_backend, DataFrame, Series = backend
975935
df = DataFrame({"a": [1, 2, 3], "b": [4, 5, 6], "c": [0.1, 0.2, 0.3]})
@@ -979,7 +939,7 @@ def test_column_as_series(
979939

980940
assert np.shares_memory(get_array(s, "a"), get_array(df, "a"))
981941

982-
if using_copy_on_write or using_array_manager:
942+
if using_copy_on_write:
983943
s[0] = 0
984944
else:
985945
if warn_copy_on_write:
@@ -1004,7 +964,7 @@ def test_column_as_series(
1004964

1005965

1006966
def test_column_as_series_set_with_upcast(
1007-
backend, using_copy_on_write, using_array_manager, warn_copy_on_write
967+
backend, using_copy_on_write, warn_copy_on_write
1008968
):
1009969
# Case: selecting a single column now also uses Copy-on-Write -> when
1010970
# setting a value causes an upcast, we don't need to update the parent
@@ -1019,7 +979,7 @@ def test_column_as_series_set_with_upcast(
1019979
with pytest.raises(TypeError, match="Invalid value"):
1020980
s[0] = "foo"
1021981
expected = Series([1, 2, 3], name="a")
1022-
elif using_copy_on_write or warn_copy_on_write or using_array_manager:
982+
elif using_copy_on_write or warn_copy_on_write:
1023983
# TODO(CoW-warn) assert the FutureWarning for CoW is also raised
1024984
with tm.assert_produces_warning(FutureWarning, match="incompatible dtype"):
1025985
s[0] = "foo"
@@ -1063,7 +1023,6 @@ def test_column_as_series_no_item_cache(
10631023
method,
10641024
using_copy_on_write,
10651025
warn_copy_on_write,
1066-
using_array_manager,
10671026
):
10681027
# Case: selecting a single column (which now also uses Copy-on-Write to protect
10691028
# the view) should always give a new object (i.e. not make use of a cache)
@@ -1080,7 +1039,7 @@ def test_column_as_series_no_item_cache(
10801039
else:
10811040
assert s1 is s2
10821041

1083-
if using_copy_on_write or using_array_manager:
1042+
if using_copy_on_write:
10841043
s1.iloc[0] = 0
10851044
elif warn_copy_on_write:
10861045
with tm.assert_cow_warning():
@@ -1181,18 +1140,15 @@ def test_series_midx_slice(using_copy_on_write, warn_copy_on_write):
11811140
tm.assert_series_equal(ser, expected)
11821141

11831142

1184-
def test_getitem_midx_slice(
1185-
using_copy_on_write, warn_copy_on_write, using_array_manager
1186-
):
1143+
def test_getitem_midx_slice(using_copy_on_write, warn_copy_on_write):
11871144
df = DataFrame({("a", "x"): [1, 2], ("a", "y"): 1, ("b", "x"): 2})
11881145
df_orig = df.copy()
11891146
new_df = df[("a",)]
11901147

11911148
if using_copy_on_write:
11921149
assert not new_df._mgr._has_no_reference(0)
11931150

1194-
if not using_array_manager:
1195-
assert np.shares_memory(get_array(df, ("a", "x")), get_array(new_df, "x"))
1151+
assert np.shares_memory(get_array(df, ("a", "x")), get_array(new_df, "x"))
11961152
if using_copy_on_write:
11971153
new_df.iloc[0, 0] = 100
11981154
tm.assert_frame_equal(df_orig, df)

0 commit comments

Comments
 (0)