Skip to content

Commit ea443de

Browse files
authored
TST/REF: collect tests by method (#37434)
1 parent 5ce3989 commit ea443de

File tree

4 files changed

+37
-44
lines changed

4 files changed

+37
-44
lines changed

pandas/tests/frame/methods/test_values.py

+29
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,35 @@
55

66

77
class TestDataFrameValues:
8+
def test_values(self, float_frame):
9+
float_frame.values[:, 0] = 5.0
10+
assert (float_frame.values[:, 0] == 5).all()
11+
12+
def test_more_values(self, float_string_frame):
13+
values = float_string_frame.values
14+
assert values.shape[1] == len(float_string_frame.columns)
15+
16+
def test_values_mixed_dtypes(self, float_frame, float_string_frame):
17+
frame = float_frame
18+
arr = frame.values
19+
20+
frame_cols = frame.columns
21+
for i, row in enumerate(arr):
22+
for j, value in enumerate(row):
23+
col = frame_cols[j]
24+
if np.isnan(value):
25+
assert np.isnan(frame[col][i])
26+
else:
27+
assert value == frame[col][i]
28+
29+
# mixed type
30+
arr = float_string_frame[["foo", "A"]].values
31+
assert arr[0, 0] == "bar"
32+
33+
df = DataFrame({"complex": [1j, 2j, 3j], "real": [1, 2, 3]})
34+
arr = df.values
35+
assert arr[0, 0] == 1j
36+
837
def test_values_duplicates(self):
938
df = DataFrame(
1039
[[1, 2, "a", "b"], [1, 2, "a", "b"]], columns=["one", "one", "two", "two"]

pandas/tests/frame/test_api.py

-44
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@ def test_getitem_pop_assign_name(self, float_frame):
3939
s2 = s.loc[:]
4040
assert s2.name == "B"
4141

42-
def test_get_value(self, float_frame):
43-
for idx in float_frame.index:
44-
for col in float_frame.columns:
45-
result = float_frame._get_value(idx, col)
46-
expected = float_frame[col][idx]
47-
tm.assert_almost_equal(result, expected)
48-
4942
def test_add_prefix_suffix(self, float_frame):
5043
with_prefix = float_frame.add_prefix("foo#")
5144
expected = pd.Index([f"foo#{c}" for c in float_frame.columns])
@@ -315,27 +308,6 @@ def test_sequence_like_with_categorical(self):
315308
def test_len(self, float_frame):
316309
assert len(float_frame) == len(float_frame.index)
317310

318-
def test_values_mixed_dtypes(self, float_frame, float_string_frame):
319-
frame = float_frame
320-
arr = frame.values
321-
322-
frame_cols = frame.columns
323-
for i, row in enumerate(arr):
324-
for j, value in enumerate(row):
325-
col = frame_cols[j]
326-
if np.isnan(value):
327-
assert np.isnan(frame[col][i])
328-
else:
329-
assert value == frame[col][i]
330-
331-
# mixed type
332-
arr = float_string_frame[["foo", "A"]].values
333-
assert arr[0, 0] == "bar"
334-
335-
df = DataFrame({"complex": [1j, 2j, 3j], "real": [1, 2, 3]})
336-
arr = df.values
337-
assert arr[0, 0] == 1j
338-
339311
# single block corner case
340312
arr = float_frame[["A", "B"]].values
341313
expected = float_frame.reindex(columns=["A", "B"]).values
@@ -394,18 +366,6 @@ def test_class_axis(self):
394366
assert pydoc.getdoc(DataFrame.index)
395367
assert pydoc.getdoc(DataFrame.columns)
396368

397-
def test_more_values(self, float_string_frame):
398-
values = float_string_frame.values
399-
assert values.shape[1] == len(float_string_frame.columns)
400-
401-
def test_repr_with_mi_nat(self, float_string_frame):
402-
df = DataFrame(
403-
{"X": [1, 2]}, index=[[pd.NaT, pd.Timestamp("20130101")], ["a", "b"]]
404-
)
405-
result = repr(df)
406-
expected = " X\nNaT a 1\n2013-01-01 b 2"
407-
assert result == expected
408-
409369
def test_items_names(self, float_string_frame):
410370
for k, v in float_string_frame.items():
411371
assert v.name == k
@@ -447,10 +407,6 @@ def test_with_datetimelikes(self):
447407
expected = Series({np.dtype("object"): 10})
448408
tm.assert_series_equal(result, expected)
449409

450-
def test_values(self, float_frame):
451-
float_frame.values[:, 0] = 5.0
452-
assert (float_frame.values[:, 0] == 5).all()
453-
454410
def test_deepcopy(self, float_frame):
455411
cp = deepcopy(float_frame)
456412
series = cp["A"]

pandas/tests/frame/test_repr_info.py

+8
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
Categorical,
1010
DataFrame,
1111
MultiIndex,
12+
NaT,
1213
PeriodIndex,
1314
Series,
15+
Timestamp,
1416
date_range,
1517
option_context,
1618
period_range,
@@ -36,6 +38,12 @@ def test_assign_index_sequences(self):
3638
df.index = index
3739
repr(df)
3840

41+
def test_repr_with_mi_nat(self, float_string_frame):
42+
df = DataFrame({"X": [1, 2]}, index=[[NaT, Timestamp("20130101")], ["a", "b"]])
43+
result = repr(df)
44+
expected = " X\nNaT a 1\n2013-01-01 b 2"
45+
assert result == expected
46+
3947
def test_multiindex_na_repr(self):
4048
# only an issue with long columns
4149
df3 = DataFrame(

0 commit comments

Comments
 (0)