Skip to content

Commit df90e71

Browse files
SaturnFromTitanproost
authored andcommitted
Remove TestData in frame tests in multiple files (pandas-dev#29172)
1 parent adb7ec3 commit df90e71

File tree

5 files changed

+62
-66
lines changed

5 files changed

+62
-66
lines changed

pandas/tests/frame/test_convert_to.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
Timestamp,
1414
date_range,
1515
)
16-
from pandas.tests.frame.common import TestData
1716
import pandas.util.testing as tm
1817

1918

20-
class TestDataFrameConvertTo(TestData):
19+
class TestDataFrameConvertTo:
2120
def test_to_dict_timestamp(self):
2221

2322
# GH11247

pandas/tests/frame/test_nonunique_indexes.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33

44
import pandas as pd
55
from pandas import DataFrame, MultiIndex, Series, date_range
6-
from pandas.tests.frame.common import TestData
76
import pandas.util.testing as tm
87
from pandas.util.testing import assert_frame_equal, assert_series_equal
98

109

11-
class TestDataFrameNonuniqueIndexes(TestData):
10+
class TestDataFrameNonuniqueIndexes:
1211
def test_column_dups_operations(self):
1312
def check(result, expected=None):
1413
if expected is not None:

pandas/tests/frame/test_query_eval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def test_query_numexpr(self):
8282
df.eval("A+1", engine="numexpr")
8383

8484

85-
class TestDataFrameEval(TestData):
85+
class TestDataFrameEval:
8686
def test_ops(self):
8787

8888
# tst ops and reversed ops in evaluation

pandas/tests/frame/test_replace.py

+41-42
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import pandas as pd
1010
from pandas import DataFrame, Index, Series, Timestamp, date_range
11-
from pandas.tests.frame.common import TestData
1211
from pandas.util.testing import assert_frame_equal, assert_series_equal
1312

1413

@@ -22,27 +21,27 @@ def mix_abc() -> Dict[str, list]:
2221
return {"a": list(range(4)), "b": list("ab.."), "c": ["a", "b", np.nan, "d"]}
2322

2423

25-
class TestDataFrameReplace(TestData):
26-
def test_replace_inplace(self):
27-
self.tsframe["A"][:5] = np.nan
28-
self.tsframe["A"][-5:] = np.nan
24+
class TestDataFrameReplace:
25+
def test_replace_inplace(self, datetime_frame, float_string_frame):
26+
datetime_frame["A"][:5] = np.nan
27+
datetime_frame["A"][-5:] = np.nan
2928

30-
tsframe = self.tsframe.copy()
29+
tsframe = datetime_frame.copy()
3130
tsframe.replace(np.nan, 0, inplace=True)
32-
assert_frame_equal(tsframe, self.tsframe.fillna(0))
31+
assert_frame_equal(tsframe, datetime_frame.fillna(0))
3332

3433
# mixed type
35-
mf = self.mixed_frame
34+
mf = float_string_frame
3635
mf.iloc[5:20, mf.columns.get_loc("foo")] = np.nan
3736
mf.iloc[-10:, mf.columns.get_loc("A")] = np.nan
3837

39-
result = self.mixed_frame.replace(np.nan, 0)
40-
expected = self.mixed_frame.fillna(value=0)
38+
result = float_string_frame.replace(np.nan, 0)
39+
expected = float_string_frame.fillna(value=0)
4140
assert_frame_equal(result, expected)
4241

43-
tsframe = self.tsframe.copy()
42+
tsframe = datetime_frame.copy()
4443
tsframe.replace([np.nan], [0], inplace=True)
45-
assert_frame_equal(tsframe, self.tsframe.fillna(0))
44+
assert_frame_equal(tsframe, datetime_frame.fillna(0))
4645

4746
def test_regex_replace_scalar(self, mix_ab):
4847
obj = {"a": list("ab.."), "b": list("efgh")}
@@ -583,17 +582,17 @@ def test_replace_regex_metachar(self, metachar):
583582
expected = DataFrame({"a": ["paren", "else"]})
584583
assert_frame_equal(result, expected)
585584

586-
def test_replace(self):
587-
self.tsframe["A"][:5] = np.nan
588-
self.tsframe["A"][-5:] = np.nan
585+
def test_replace(self, datetime_frame):
586+
datetime_frame["A"][:5] = np.nan
587+
datetime_frame["A"][-5:] = np.nan
589588

590-
zero_filled = self.tsframe.replace(np.nan, -1e8)
591-
assert_frame_equal(zero_filled, self.tsframe.fillna(-1e8))
592-
assert_frame_equal(zero_filled.replace(-1e8, np.nan), self.tsframe)
589+
zero_filled = datetime_frame.replace(np.nan, -1e8)
590+
assert_frame_equal(zero_filled, datetime_frame.fillna(-1e8))
591+
assert_frame_equal(zero_filled.replace(-1e8, np.nan), datetime_frame)
593592

594-
self.tsframe["A"][:5] = np.nan
595-
self.tsframe["A"][-5:] = np.nan
596-
self.tsframe["B"][:5] = -1e8
593+
datetime_frame["A"][:5] = np.nan
594+
datetime_frame["A"][-5:] = np.nan
595+
datetime_frame["B"][:5] = -1e8
597596

598597
# empty
599598
df = DataFrame(index=["a", "b"])
@@ -684,20 +683,20 @@ def test_replace_convert(self):
684683
res = rep.dtypes
685684
assert_series_equal(expec, res)
686685

687-
def test_replace_mixed(self):
688-
mf = self.mixed_frame
686+
def test_replace_mixed(self, float_string_frame):
687+
mf = float_string_frame
689688
mf.iloc[5:20, mf.columns.get_loc("foo")] = np.nan
690689
mf.iloc[-10:, mf.columns.get_loc("A")] = np.nan
691690

692-
result = self.mixed_frame.replace(np.nan, -18)
693-
expected = self.mixed_frame.fillna(value=-18)
691+
result = float_string_frame.replace(np.nan, -18)
692+
expected = float_string_frame.fillna(value=-18)
694693
assert_frame_equal(result, expected)
695-
assert_frame_equal(result.replace(-18, np.nan), self.mixed_frame)
694+
assert_frame_equal(result.replace(-18, np.nan), float_string_frame)
696695

697-
result = self.mixed_frame.replace(np.nan, -1e8)
698-
expected = self.mixed_frame.fillna(value=-1e8)
696+
result = float_string_frame.replace(np.nan, -1e8)
697+
expected = float_string_frame.fillna(value=-1e8)
699698
assert_frame_equal(result, expected)
700-
assert_frame_equal(result.replace(-1e8, np.nan), self.mixed_frame)
699+
assert_frame_equal(result.replace(-1e8, np.nan), float_string_frame)
701700

702701
# int block upcasting
703702
df = DataFrame(
@@ -793,30 +792,30 @@ def test_replace_simple_nested_dict_with_nonexistent_value(self):
793792
result = df.replace({"col": {-1: "-", 1: "a", 4: "b"}})
794793
assert_frame_equal(expected, result)
795794

796-
def test_replace_value_is_none(self):
797-
orig_value = self.tsframe.iloc[0, 0]
798-
orig2 = self.tsframe.iloc[1, 0]
795+
def test_replace_value_is_none(self, datetime_frame):
796+
orig_value = datetime_frame.iloc[0, 0]
797+
orig2 = datetime_frame.iloc[1, 0]
799798

800-
self.tsframe.iloc[0, 0] = np.nan
801-
self.tsframe.iloc[1, 0] = 1
799+
datetime_frame.iloc[0, 0] = np.nan
800+
datetime_frame.iloc[1, 0] = 1
802801

803-
result = self.tsframe.replace(to_replace={np.nan: 0})
804-
expected = self.tsframe.T.replace(to_replace={np.nan: 0}).T
802+
result = datetime_frame.replace(to_replace={np.nan: 0})
803+
expected = datetime_frame.T.replace(to_replace={np.nan: 0}).T
805804
assert_frame_equal(result, expected)
806805

807-
result = self.tsframe.replace(to_replace={np.nan: 0, 1: -1e8})
808-
tsframe = self.tsframe.copy()
806+
result = datetime_frame.replace(to_replace={np.nan: 0, 1: -1e8})
807+
tsframe = datetime_frame.copy()
809808
tsframe.iloc[0, 0] = 0
810809
tsframe.iloc[1, 0] = -1e8
811810
expected = tsframe
812811
assert_frame_equal(expected, result)
813-
self.tsframe.iloc[0, 0] = orig_value
814-
self.tsframe.iloc[1, 0] = orig2
812+
datetime_frame.iloc[0, 0] = orig_value
813+
datetime_frame.iloc[1, 0] = orig2
815814

816-
def test_replace_for_new_dtypes(self):
815+
def test_replace_for_new_dtypes(self, datetime_frame):
817816

818817
# dtypes
819-
tsframe = self.tsframe.copy().astype(np.float32)
818+
tsframe = datetime_frame.copy().astype(np.float32)
820819
tsframe["A"][:5] = np.nan
821820
tsframe["A"][-5:] = np.nan
822821

pandas/tests/frame/test_repr_info.py

+18-19
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
option_context,
1919
period_range,
2020
)
21-
from pandas.tests.frame.common import TestData
2221
import pandas.util.testing as tm
2322

2423
import pandas.io.formats.format as fmt
@@ -27,21 +26,21 @@
2726
# structure
2827

2928

30-
class TestDataFrameReprInfoEtc(TestData):
29+
class TestDataFrameReprInfoEtc:
3130
def test_repr_empty(self):
3231
# empty
33-
foo = repr(self.empty) # noqa
32+
foo = repr(DataFrame()) # noqa
3433

3534
# empty with index
3635
frame = DataFrame(index=np.arange(1000))
3736
foo = repr(frame) # noqa
3837

39-
def test_repr_mixed(self):
38+
def test_repr_mixed(self, float_string_frame):
4039
buf = StringIO()
4140

4241
# mixed
43-
foo = repr(self.mixed_frame) # noqa
44-
self.mixed_frame.info(verbose=False, buf=buf)
42+
foo = repr(float_string_frame) # noqa
43+
float_string_frame.info(verbose=False, buf=buf)
4544

4645
@pytest.mark.slow
4746
def test_repr_mixed_big(self):
@@ -54,16 +53,16 @@ def test_repr_mixed_big(self):
5453

5554
foo = repr(biggie) # noqa
5655

57-
def test_repr(self):
56+
def test_repr(self, float_frame):
5857
buf = StringIO()
5958

6059
# small one
61-
foo = repr(self.frame)
62-
self.frame.info(verbose=False, buf=buf)
60+
foo = repr(float_frame)
61+
float_frame.info(verbose=False, buf=buf)
6362

6463
# even smaller
65-
self.frame.reindex(columns=["A"]).info(verbose=False, buf=buf)
66-
self.frame.reindex(columns=["A", "B"]).info(verbose=False, buf=buf)
64+
float_frame.reindex(columns=["A"]).info(verbose=False, buf=buf)
65+
float_frame.reindex(columns=["A", "B"]).info(verbose=False, buf=buf)
6766

6867
# exhausting cases in DataFrame.info
6968

@@ -72,7 +71,7 @@ def test_repr(self):
7271
foo = repr(no_index) # noqa
7372

7473
# no columns or index
75-
self.empty.info(buf=buf)
74+
DataFrame().info(buf=buf)
7675

7776
df = DataFrame(["a\n\r\tb"], columns=["a\n\r\td"], index=["a\n\r\tf"])
7877
assert "\t" not in repr(df)
@@ -96,7 +95,7 @@ def test_repr_big(self):
9695
biggie = DataFrame(np.zeros((200, 4)), columns=range(4), index=range(200))
9796
repr(biggie)
9897

99-
def test_repr_unsortable(self):
98+
def test_repr_unsortable(self, float_frame):
10099
# columns are not sortable
101100
import warnings
102101

@@ -115,13 +114,13 @@ def test_repr_unsortable(self):
115114
repr(unsortable)
116115

117116
fmt.set_option("display.precision", 3, "display.column_space", 10)
118-
repr(self.frame)
117+
repr(float_frame)
119118

120119
fmt.set_option("display.max_rows", 10, "display.max_columns", 2)
121-
repr(self.frame)
120+
repr(float_frame)
122121

123122
fmt.set_option("display.max_rows", 1000, "display.max_columns", 1000)
124-
repr(self.frame)
123+
repr(float_frame)
125124

126125
tm.reset_display_options()
127126

@@ -196,10 +195,10 @@ def test_latex_repr(self):
196195
# GH 12182
197196
assert df._repr_latex_() is None
198197

199-
def test_info(self):
198+
def test_info(self, float_frame, datetime_frame):
200199
io = StringIO()
201-
self.frame.info(buf=io)
202-
self.tsframe.info(buf=io)
200+
float_frame.info(buf=io)
201+
datetime_frame.info(buf=io)
203202

204203
frame = DataFrame(np.random.randn(5, 3))
205204

0 commit comments

Comments
 (0)