Skip to content

Commit 673b247

Browse files
authored
Merge branch 'main' into avoid_copy_categoricls
2 parents b9b1d25 + d4ae649 commit 673b247

File tree

15 files changed

+58
-24
lines changed

15 files changed

+58
-24
lines changed

.github/workflows/unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
# It will be temporarily activated during tests with locale.setlocale
7272
extra_loc: "zh_CN"
7373
platform: ubuntu-24.04
74-
- name: "Past no infer strings"
74+
- name: "PANDAS_FUTURE_INFER_STRING=0"
7575
env_file: actions-312.yaml
7676
pandas_future_infer_string: "0"
7777
platform: ubuntu-24.04

pandas/errors/cow.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
_chained_assignment_msg = (
22
"A value is trying to be set on a copy of a DataFrame or Series "
33
"through chained assignment.\n"
4-
"When using the Copy-on-Write mode, such chained assignment never works "
5-
"to update the original DataFrame or Series, because the intermediate "
6-
"object on which we are setting values always behaves as a copy.\n\n"
4+
"Such chained assignment never works to update the original DataFrame or "
5+
"Series, because the intermediate object on which we are setting values "
6+
"always behaves as a copy (due to Copy-on-Write).\n\n"
77
"Try using '.loc[row_indexer, col_indexer] = value' instead, to perform "
88
"the assignment in a single step.\n\n"
9-
"See the caveats in the documentation: "
9+
"See the documentation for a more detailed explanation: "
1010
"https://pandas.pydata.org/pandas-docs/stable/user_guide/"
11-
"copy_on_write.html"
11+
"copy_on_write.html#chained-assignment"
1212
)
1313

1414

1515
_chained_assignment_method_msg = (
1616
"A value is trying to be set on a copy of a DataFrame or Series "
1717
"through chained assignment using an inplace method.\n"
18-
"When using the Copy-on-Write mode, such inplace method never works "
19-
"to update the original DataFrame or Series, because the intermediate "
20-
"object on which we are setting values always behaves as a copy.\n\n"
18+
"Such inplace method never works to update the original DataFrame or Series, "
19+
"because the intermediate object on which we are setting values always "
20+
"behaves as a copy (due to Copy-on-Write).\n\n"
2121
"For example, when doing 'df[col].method(value, inplace=True)', try "
2222
"using 'df.method({col: value}, inplace=True)' instead, to perform "
23-
"the operation inplace on the original object.\n\n"
23+
"the operation inplace on the original object, or try to avoid an inplace "
24+
"operation using 'df[col] = df[col].method(value)'.\n\n"
25+
"See the documentation for a more detailed explanation: "
26+
"https://pandas.pydata.org/pandas-docs/stable/user_guide/"
27+
"copy_on_write.html"
2428
)

pandas/tests/arrays/test_datetimes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def test_simple_new_requires_match(self, unit):
100100
assert dta.dtype == dtype
101101

102102
wrong = DatetimeTZDtype("ns", "UTC")
103-
with pytest.raises(AssertionError, match=""):
103+
with pytest.raises(AssertionError, match="^$"):
104104
DatetimeArray._simple_new(arr, dtype=wrong)
105105

106106
def test_std_non_nano(self, unit):

pandas/tests/dtypes/test_dtypes.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,14 @@ def test_alias_to_unit_raises(self):
249249

250250
def test_alias_to_unit_bad_alias_raises(self):
251251
# 23990
252-
with pytest.raises(TypeError, match=""):
252+
with pytest.raises(
253+
TypeError, match="Cannot construct a 'DatetimeTZDtype' from"
254+
):
253255
DatetimeTZDtype("this is a bad string")
254256

255-
with pytest.raises(TypeError, match=""):
257+
with pytest.raises(
258+
TypeError, match="Cannot construct a 'DatetimeTZDtype' from"
259+
):
256260
DatetimeTZDtype("datetime64[ns, US/NotATZ]")
257261

258262
def test_hash_vs_equality(self, dtype):

pandas/tests/frame/test_ufunc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def test_unary_accumulate_axis():
191191

192192
def test_frame_outer_disallowed():
193193
df = pd.DataFrame({"A": [1, 2]})
194-
with pytest.raises(NotImplementedError, match=""):
194+
with pytest.raises(NotImplementedError, match="^$"):
195195
# deprecation enforced in 2.0
196196
np.subtract.outer(df, df)
197197

pandas/tests/indexes/numeric/test_indexing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,10 +585,10 @@ def test_slice_locs_na(self):
585585

586586
def test_slice_locs_na_raises(self):
587587
index = Index([np.nan, 1, 2])
588-
with pytest.raises(KeyError, match=""):
588+
with pytest.raises(KeyError, match="1.5"):
589589
index.slice_locs(start=1.5)
590590

591-
with pytest.raises(KeyError, match=""):
591+
with pytest.raises(KeyError, match="1.5"):
592592
index.slice_locs(end=1.5)
593593

594594

pandas/tests/indexes/test_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ def test_drop_by_str_label(self, index):
712712
)
713713
@pytest.mark.parametrize("keys", [["foo", "bar"], ["1", "bar"]])
714714
def test_drop_by_str_label_raises_missing_keys(self, index, keys):
715-
with pytest.raises(KeyError, match=""):
715+
with pytest.raises(KeyError, match=".* not found in axis"):
716716
index.drop(keys)
717717

718718
@pytest.mark.parametrize(
@@ -741,7 +741,7 @@ def test_drop_by_numeric_label_loc(self):
741741

742742
def test_drop_by_numeric_label_raises_missing_keys(self):
743743
index = Index([1, 2, 3])
744-
with pytest.raises(KeyError, match=""):
744+
with pytest.raises(KeyError, match=re.escape("[4] not found in axis")):
745745
index.drop([3, 4])
746746

747747
@pytest.mark.parametrize(

pandas/tests/indexing/multiindex/test_getitem.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,12 @@ def test_series_getitem_returns_scalar(
8989
(lambda s: s[(2000, 3, 4)], KeyError, r"^\(2000, 3, 4\)$"),
9090
(lambda s: s.loc[(2000, 3, 4)], KeyError, r"^\(2000, 3, 4\)$"),
9191
(lambda s: s.loc[(2000, 3, 4, 5)], IndexingError, "Too many indexers"),
92-
(lambda s: s.__getitem__(len(s)), KeyError, ""), # match should include len(s)
93-
(lambda s: s[len(s)], KeyError, ""), # match should include len(s)
92+
(
93+
lambda s: s.__getitem__(len(s)),
94+
KeyError,
95+
"100",
96+
), # match should include len(s)
97+
(lambda s: s[len(s)], KeyError, "100"), # match should include len(s)
9498
(
9599
lambda s: s.iloc[len(s)],
96100
IndexError,

pandas/tests/io/json/test_normalize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def test_empty_array(self):
172172
)
173173
def test_accepted_input(self, data, record_path, exception_type):
174174
if exception_type is not None:
175-
with pytest.raises(exception_type, match=""):
175+
with pytest.raises(exception_type, match="^$"):
176176
json_normalize(data, record_path=record_path)
177177
else:
178178
result = json_normalize(data, record_path=record_path)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def test_read_chunksize_and_nrows_changing_size(all_parsers):
129129
tm.assert_frame_equal(reader.get_chunk(size=2), expected.iloc[:2])
130130
tm.assert_frame_equal(reader.get_chunk(size=4), expected.iloc[2:5])
131131

132-
with pytest.raises(StopIteration, match=""):
132+
with pytest.raises(StopIteration, match="^$"):
133133
reader.get_chunk(size=3)
134134

135135

0 commit comments

Comments
 (0)