Skip to content

Commit 024270a

Browse files
authored
TST/REF: collect indexing tests by method (#37590)
1 parent c583144 commit 024270a

File tree

6 files changed

+289
-295
lines changed

6 files changed

+289
-295
lines changed

pandas/tests/frame/indexing/test_indexing.py

-26
Original file line numberDiff line numberDiff line change
@@ -1327,32 +1327,6 @@ def test_getitem_list_duplicates(self):
13271327
expected = df.iloc[:, 2:]
13281328
tm.assert_frame_equal(result, expected)
13291329

1330-
def test_set_value_with_index_dtype_change(self):
1331-
df_orig = DataFrame(np.random.randn(3, 3), index=range(3), columns=list("ABC"))
1332-
1333-
# this is actually ambiguous as the 2 is interpreted as a positional
1334-
# so column is not created
1335-
df = df_orig.copy()
1336-
df._set_value("C", 2, 1.0)
1337-
assert list(df.index) == list(df_orig.index) + ["C"]
1338-
# assert list(df.columns) == list(df_orig.columns) + [2]
1339-
1340-
df = df_orig.copy()
1341-
df.loc["C", 2] = 1.0
1342-
assert list(df.index) == list(df_orig.index) + ["C"]
1343-
# assert list(df.columns) == list(df_orig.columns) + [2]
1344-
1345-
# create both new
1346-
df = df_orig.copy()
1347-
df._set_value("C", "D", 1.0)
1348-
assert list(df.index) == list(df_orig.index) + ["C"]
1349-
assert list(df.columns) == list(df_orig.columns) + ["D"]
1350-
1351-
df = df_orig.copy()
1352-
df.loc["C", "D"] = 1.0
1353-
assert list(df.index) == list(df_orig.index) + ["C"]
1354-
assert list(df.columns) == list(df_orig.columns) + ["D"]
1355-
13561330
# TODO: rename? remove?
13571331
def test_single_element_ix_dont_upcast(self, float_frame):
13581332
float_frame["E"] = 1

pandas/tests/frame/indexing/test_set_value.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from pandas.core.dtypes.common import is_float_dtype
55

6-
from pandas import isna
6+
from pandas import DataFrame, isna
77

88

99
class TestSetValue:
@@ -38,3 +38,29 @@ def test_set_value_resize(self, float_frame):
3838
msg = "could not convert string to float: 'sam'"
3939
with pytest.raises(ValueError, match=msg):
4040
res._set_value("foobar", "baz", "sam")
41+
42+
def test_set_value_with_index_dtype_change(self):
43+
df_orig = DataFrame(np.random.randn(3, 3), index=range(3), columns=list("ABC"))
44+
45+
# this is actually ambiguous as the 2 is interpreted as a positional
46+
# so column is not created
47+
df = df_orig.copy()
48+
df._set_value("C", 2, 1.0)
49+
assert list(df.index) == list(df_orig.index) + ["C"]
50+
# assert list(df.columns) == list(df_orig.columns) + [2]
51+
52+
df = df_orig.copy()
53+
df.loc["C", 2] = 1.0
54+
assert list(df.index) == list(df_orig.index) + ["C"]
55+
# assert list(df.columns) == list(df_orig.columns) + [2]
56+
57+
# create both new
58+
df = df_orig.copy()
59+
df._set_value("C", "D", 1.0)
60+
assert list(df.index) == list(df_orig.index) + ["C"]
61+
assert list(df.columns) == list(df_orig.columns) + ["D"]
62+
63+
df = df_orig.copy()
64+
df.loc["C", "D"] = 1.0
65+
assert list(df.index) == list(df_orig.index) + ["C"]
66+
assert list(df.columns) == list(df_orig.columns) + ["D"]

pandas/tests/indexing/test_callable.py

-254
This file was deleted.

0 commit comments

Comments
 (0)