Skip to content

Commit 2617822

Browse files
authored
CoW: Remove remaining cow occurrences from tests (pandas-dev#57477)
1 parent a4cdf1e commit 2617822

File tree

10 files changed

+413
-913
lines changed

10 files changed

+413
-913
lines changed

pandas/conftest.py

-8
Original file line numberDiff line numberDiff line change
@@ -1987,14 +1987,6 @@ def indexer_ial(request):
19871987
return request.param
19881988

19891989

1990-
@pytest.fixture
1991-
def using_copy_on_write() -> bool:
1992-
"""
1993-
Fixture to check if Copy-on-Write is enabled.
1994-
"""
1995-
return True
1996-
1997-
19981990
@pytest.fixture
19991991
def using_infer_string() -> bool:
20001992
"""

pandas/tests/copy_view/test_functions.py

+91-177
Large diffs are not rendered by default.

pandas/tests/copy_view/test_methods.py

+300-642
Large diffs are not rendered by default.

pandas/tests/generic/test_duplicate_labels.py

-10
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,6 @@ def test_preserve_getitem(self):
8989
assert df.loc[[0]].flags.allows_duplicate_labels is False
9090
assert df.loc[0, ["A"]].flags.allows_duplicate_labels is False
9191

92-
def test_ndframe_getitem_caching_issue(self, request, using_copy_on_write):
93-
if not using_copy_on_write:
94-
request.applymarker(pytest.mark.xfail(reason="Unclear behavior."))
95-
# NDFrame.__getitem__ will cache the first df['A']. May need to
96-
# invalidate that cache? Update the cached entries?
97-
df = pd.DataFrame({"A": [0]}).set_flags(allows_duplicate_labels=False)
98-
assert df["A"].flags.allows_duplicate_labels is False
99-
df.flags.allows_duplicate_labels = True
100-
assert df["A"].flags.allows_duplicate_labels is True
101-
10292
@pytest.mark.parametrize(
10393
"objs, kwargs",
10494
[

pandas/tests/indexes/period/test_partial_slicing.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
class TestPeriodIndex:
15-
def test_getitem_periodindex_duplicates_string_slice(self, using_copy_on_write):
15+
def test_getitem_periodindex_duplicates_string_slice(self):
1616
# monotonic
1717
idx = PeriodIndex([2000, 2007, 2007, 2009, 2009], freq="Y-JUN")
1818
ts = Series(np.random.default_rng(2).standard_normal(len(idx)), index=idx)
@@ -22,10 +22,7 @@ def test_getitem_periodindex_duplicates_string_slice(self, using_copy_on_write):
2222
expected = ts[1:3]
2323
tm.assert_series_equal(result, expected)
2424
result[:] = 1
25-
if using_copy_on_write:
26-
tm.assert_series_equal(ts, original)
27-
else:
28-
assert (ts[1:3] == 1).all()
25+
tm.assert_series_equal(ts, original)
2926

3027
# not monotonic
3128
idx = PeriodIndex([2000, 2007, 2007, 2009, 2007], freq="Y-JUN")

pandas/tests/indexes/test_common.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
class TestCommon:
3434
@pytest.mark.parametrize("name", [None, "new_name"])
35-
def test_to_frame(self, name, index_flat, using_copy_on_write):
35+
def test_to_frame(self, name, index_flat):
3636
# see GH#15230, GH#22580
3737
idx = index_flat
3838

@@ -46,8 +46,6 @@ def test_to_frame(self, name, index_flat, using_copy_on_write):
4646
assert df.index is idx
4747
assert len(df.columns) == 1
4848
assert df.columns[0] == idx_name
49-
if not using_copy_on_write:
50-
assert df[idx_name].values is not idx.values
5149

5250
df = idx.to_frame(index=False, name=idx_name)
5351
assert df.index is not idx

pandas/tests/internals/test_internals.py

+10-22
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ def test_reindex_items(self):
753753
mgr.iget(3).internal_values(), reindexed.iget(3).internal_values()
754754
)
755755

756-
def test_get_numeric_data(self, using_copy_on_write):
756+
def test_get_numeric_data(self):
757757
mgr = create_mgr(
758758
"int: int; float: float; complex: complex;"
759759
"str: object; bool: bool; obj: object; dt: datetime",
@@ -774,18 +774,12 @@ def test_get_numeric_data(self, using_copy_on_write):
774774
np.array([100.0, 200.0, 300.0]),
775775
inplace=True,
776776
)
777-
if using_copy_on_write:
778-
tm.assert_almost_equal(
779-
mgr.iget(mgr.items.get_loc("float")).internal_values(),
780-
np.array([1.0, 1.0, 1.0]),
781-
)
782-
else:
783-
tm.assert_almost_equal(
784-
mgr.iget(mgr.items.get_loc("float")).internal_values(),
785-
np.array([100.0, 200.0, 300.0]),
786-
)
777+
tm.assert_almost_equal(
778+
mgr.iget(mgr.items.get_loc("float")).internal_values(),
779+
np.array([1.0, 1.0, 1.0]),
780+
)
787781

788-
def test_get_bool_data(self, using_copy_on_write):
782+
def test_get_bool_data(self):
789783
mgr = create_mgr(
790784
"int: int; float: float; complex: complex;"
791785
"str: object; bool: bool; obj: object; dt: datetime",
@@ -801,16 +795,10 @@ def test_get_bool_data(self, using_copy_on_write):
801795
)
802796

803797
bools.iset(0, np.array([True, False, True]), inplace=True)
804-
if using_copy_on_write:
805-
tm.assert_numpy_array_equal(
806-
mgr.iget(mgr.items.get_loc("bool")).internal_values(),
807-
np.array([True, True, True]),
808-
)
809-
else:
810-
tm.assert_numpy_array_equal(
811-
mgr.iget(mgr.items.get_loc("bool")).internal_values(),
812-
np.array([True, False, True]),
813-
)
798+
tm.assert_numpy_array_equal(
799+
mgr.iget(mgr.items.get_loc("bool")).internal_values(),
800+
np.array([True, True, True]),
801+
)
814802

815803
def test_unicode_repr_doesnt_raise(self):
816804
repr(create_mgr("b,\u05d0: object"))

pandas/tests/io/parser/common/test_file_buffer_url.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ def test_context_manageri_user_provided(all_parsers, datapath):
438438

439439

440440
@skip_pyarrow # ParserError: Empty CSV file
441-
def test_file_descriptor_leak(all_parsers, using_copy_on_write):
441+
def test_file_descriptor_leak(all_parsers):
442442
# GH 31488
443443
parser = all_parsers
444444
with tm.ensure_clean() as path:

pandas/tests/io/test_parquet.py

+5-36
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import numpy as np
99
import pytest
1010

11-
from pandas._config import using_copy_on_write
12-
1311
from pandas.compat import is_platform_windows
1412
from pandas.compat.pyarrow import (
1513
pa_version_under11p0,
@@ -425,15 +423,10 @@ def test_read_filters(self, engine, tmp_path):
425423
repeat=1,
426424
)
427425

428-
def test_write_index(self, engine, using_copy_on_write, request):
429-
check_names = engine != "fastparquet"
430-
if using_copy_on_write and engine == "fastparquet":
431-
request.applymarker(
432-
pytest.mark.xfail(reason="fastparquet write into index")
433-
)
434-
426+
def test_write_index(self):
427+
pytest.importorskip("pyarrow")
435428
df = pd.DataFrame({"A": [1, 2, 3]})
436-
check_round_trip(df, engine)
429+
check_round_trip(df, "pyarrow")
437430

438431
indexes = [
439432
[2, 3, 4],
@@ -446,12 +439,12 @@ def test_write_index(self, engine, using_copy_on_write, request):
446439
df.index = index
447440
if isinstance(index, pd.DatetimeIndex):
448441
df.index = df.index._with_freq(None) # freq doesn't round-trip
449-
check_round_trip(df, engine, check_names=check_names)
442+
check_round_trip(df, "pyarrow")
450443

451444
# index with meta-data
452445
df.index = [0, 1, 2]
453446
df.index.name = "foo"
454-
check_round_trip(df, engine)
447+
check_round_trip(df, "pyarrow")
455448

456449
def test_write_multiindex(self, pa):
457450
# Not supported in fastparquet as of 0.1.3 or older pyarrow version
@@ -1256,23 +1249,6 @@ def test_error_on_using_partition_cols_and_partition_on(
12561249
partition_cols=partition_cols,
12571250
)
12581251

1259-
@pytest.mark.skipif(using_copy_on_write(), reason="fastparquet writes into Index")
1260-
def test_empty_dataframe(self, fp):
1261-
# GH #27339
1262-
df = pd.DataFrame()
1263-
expected = df.copy()
1264-
check_round_trip(df, fp, expected=expected)
1265-
1266-
@pytest.mark.skipif(using_copy_on_write(), reason="fastparquet writes into Index")
1267-
def test_timezone_aware_index(self, fp, timezone_aware_date_list):
1268-
idx = 5 * [timezone_aware_date_list]
1269-
1270-
df = pd.DataFrame(index=idx, data={"index_as_col": idx})
1271-
1272-
expected = df.copy()
1273-
expected.index.name = "index"
1274-
check_round_trip(df, fp, expected=expected)
1275-
12761252
def test_close_file_handle_on_read_error(self):
12771253
with tm.ensure_clean("test.parquet") as path:
12781254
pathlib.Path(path).write_bytes(b"breakit")
@@ -1361,10 +1337,3 @@ def test_invalid_dtype_backend(self, engine):
13611337
df.to_parquet(path)
13621338
with pytest.raises(ValueError, match=msg):
13631339
read_parquet(path, dtype_backend="numpy")
1364-
1365-
@pytest.mark.skipif(using_copy_on_write(), reason="fastparquet writes into Index")
1366-
def test_empty_columns(self, fp):
1367-
# GH 52034
1368-
df = pd.DataFrame(index=pd.Index(["a", "b", "c"], name="custom name"))
1369-
expected = pd.DataFrame(index=pd.Index(["a", "b", "c"], name="custom name"))
1370-
check_round_trip(df, fp, expected=expected)

pandas/tests/test_multilevel.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,20 @@ def test_reindex(self, multiindex_dataframe_random_data):
3636
tm.assert_frame_equal(reindexed, expected)
3737

3838
def test_reindex_preserve_levels(
39-
self, multiindex_year_month_day_dataframe_random_data, using_copy_on_write
39+
self, multiindex_year_month_day_dataframe_random_data
4040
):
4141
ymd = multiindex_year_month_day_dataframe_random_data
4242

4343
new_index = ymd.index[::10]
4444
chunk = ymd.reindex(new_index)
45-
if using_copy_on_write:
46-
assert chunk.index.is_(new_index)
47-
else:
48-
assert chunk.index is new_index
45+
assert chunk.index.is_(new_index)
4946

5047
chunk = ymd.loc[new_index]
5148
assert chunk.index.equals(new_index)
5249

5350
ymdT = ymd.T
5451
chunk = ymdT.reindex(columns=new_index)
55-
if using_copy_on_write:
56-
assert chunk.columns.is_(new_index)
57-
else:
58-
assert chunk.columns is new_index
52+
assert chunk.columns.is_(new_index)
5953

6054
chunk = ymdT.loc[:, new_index]
6155
assert chunk.columns.equals(new_index)

0 commit comments

Comments
 (0)