Skip to content

Commit 97d2399

Browse files
SaturnFromTitanjreback
authored andcommitted
Remove TestData in frame tests in multiple files - part 3 (#29226)
1 parent 1f67a70 commit 97d2399

File tree

3 files changed

+5
-134
lines changed

3 files changed

+5
-134
lines changed

pandas/tests/frame/common.py

-124
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,3 @@
1-
import numpy as np
2-
3-
from pandas.util._decorators import cache_readonly
4-
5-
import pandas as pd
6-
import pandas.util.testing as tm
7-
8-
_seriesd = tm.getSeriesData()
9-
_tsd = tm.getTimeSeriesData()
10-
11-
_frame = pd.DataFrame(_seriesd)
12-
_frame2 = pd.DataFrame(_seriesd, columns=["D", "C", "B", "A"])
13-
_intframe = pd.DataFrame({k: v.astype(int) for k, v in _seriesd.items()})
14-
15-
_tsframe = pd.DataFrame(_tsd)
16-
17-
_mixed_frame = _frame.copy()
18-
_mixed_frame["foo"] = "bar"
19-
20-
21-
class TestData:
22-
@cache_readonly
23-
def frame(self):
24-
return _frame.copy()
25-
26-
@cache_readonly
27-
def frame2(self):
28-
return _frame2.copy()
29-
30-
@cache_readonly
31-
def intframe(self):
32-
# force these all to int64 to avoid platform testing issues
33-
return pd.DataFrame({c: s for c, s in _intframe.items()}, dtype=np.int64)
34-
35-
@cache_readonly
36-
def tsframe(self):
37-
return _tsframe.copy()
38-
39-
@cache_readonly
40-
def mixed_frame(self):
41-
return _mixed_frame.copy()
42-
43-
@cache_readonly
44-
def mixed_float(self):
45-
return pd.DataFrame(
46-
{
47-
"A": _frame["A"].copy().astype("float32"),
48-
"B": _frame["B"].copy().astype("float32"),
49-
"C": _frame["C"].copy().astype("float16"),
50-
"D": _frame["D"].copy().astype("float64"),
51-
}
52-
)
53-
54-
@cache_readonly
55-
def mixed_float2(self):
56-
return pd.DataFrame(
57-
{
58-
"A": _frame2["A"].copy().astype("float32"),
59-
"B": _frame2["B"].copy().astype("float32"),
60-
"C": _frame2["C"].copy().astype("float16"),
61-
"D": _frame2["D"].copy().astype("float64"),
62-
}
63-
)
64-
65-
@cache_readonly
66-
def mixed_int(self):
67-
return pd.DataFrame(
68-
{
69-
"A": _intframe["A"].copy().astype("int32"),
70-
"B": np.ones(len(_intframe["B"]), dtype="uint64"),
71-
"C": _intframe["C"].copy().astype("uint8"),
72-
"D": _intframe["D"].copy().astype("int64"),
73-
}
74-
)
75-
76-
@cache_readonly
77-
def all_mixed(self):
78-
return pd.DataFrame(
79-
{
80-
"a": 1.0,
81-
"b": 2,
82-
"c": "foo",
83-
"float32": np.array([1.0] * 10, dtype="float32"),
84-
"int32": np.array([1] * 10, dtype="int32"),
85-
},
86-
index=np.arange(10),
87-
)
88-
89-
@cache_readonly
90-
def tzframe(self):
91-
result = pd.DataFrame(
92-
{
93-
"A": pd.date_range("20130101", periods=3),
94-
"B": pd.date_range("20130101", periods=3, tz="US/Eastern"),
95-
"C": pd.date_range("20130101", periods=3, tz="CET"),
96-
}
97-
)
98-
result.iloc[1, 1] = pd.NaT
99-
result.iloc[1, 2] = pd.NaT
100-
return result
101-
102-
@cache_readonly
103-
def empty(self):
104-
return pd.DataFrame()
105-
106-
@cache_readonly
107-
def ts1(self):
108-
return tm.makeTimeSeries(nper=30)
109-
110-
@cache_readonly
111-
def ts2(self):
112-
return tm.makeTimeSeries(nper=30)[5:]
113-
114-
@cache_readonly
115-
def simple(self):
116-
arr = np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]])
117-
118-
return pd.DataFrame(arr, columns=["one", "two", "three"], index=["a", "b", "c"])
119-
120-
121-
# self.ts3 = tm.makeTimeSeries()[-5:]
122-
# self.ts4 = tm.makeTimeSeries()[1:-1]
123-
124-
1251
def _check_mixed_float(df, dtype=None):
1262
# float16 are most likely to be upcasted to float32
1273
dtypes = dict(A="float32", B="float32", C="float16", D="float64")

pandas/tests/frame/test_indexing.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
)
2626
import pandas.core.common as com
2727
from pandas.core.indexing import IndexingError
28-
from pandas.tests.frame.common import TestData
2928
import pandas.util.testing as tm
3029
from pandas.util.testing import (
3130
assert_almost_equal,
@@ -36,7 +35,7 @@
3635
from pandas.tseries.offsets import BDay
3736

3837

39-
class TestDataFrameIndexing(TestData):
38+
class TestDataFrameIndexing:
4039
def test_getitem(self, float_frame):
4140
# Slicing
4241
sl = float_frame[:20]
@@ -1167,8 +1166,8 @@ def test_setitem_fancy_mixed_2d(self, float_string_frame):
11671166

11681167
with catch_warnings(record=True):
11691168
simplefilter("ignore", FutureWarning)
1170-
self.mixed_frame.ix[:5, ["C", "B", "A"]] = 5
1171-
result = self.mixed_frame.ix[:5, ["C", "B", "A"]]
1169+
float_string_frame.ix[:5, ["C", "B", "A"]] = 5
1170+
result = float_string_frame.ix[:5, ["C", "B", "A"]]
11721171
assert (result.values == 5).all()
11731172

11741173
float_string_frame.ix[5] = np.nan
@@ -3402,7 +3401,7 @@ def test_interval_index(self):
34023401
assert_series_equal(result, expected)
34033402

34043403

3405-
class TestDataFrameIndexingDatetimeWithTZ(TestData):
3404+
class TestDataFrameIndexingDatetimeWithTZ:
34063405
def test_setitem(self, timezone_frame):
34073406

34083407
df = timezone_frame
@@ -3461,7 +3460,7 @@ def test_scalar_assignment(self):
34613460
tm.assert_frame_equal(df, expected)
34623461

34633462

3464-
class TestDataFrameIndexingUInt64(TestData):
3463+
class TestDataFrameIndexingUInt64:
34653464
def test_setitem(self, uint64_frame):
34663465

34673466
df = uint64_frame

pandas/tests/frame/test_query_eval.py

-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import pandas as pd
1010
from pandas import DataFrame, Index, MultiIndex, Series, date_range
1111
from pandas.core.computation.check import _NUMEXPR_INSTALLED
12-
from pandas.tests.frame.common import TestData
1312
from pandas.util.testing import (
1413
assert_frame_equal,
1514
assert_series_equal,
@@ -704,7 +703,6 @@ def setup_class(cls):
704703
super().setup_class()
705704
cls.engine = "numexpr"
706705
cls.parser = "python"
707-
cls.frame = TestData().frame
708706

709707
def test_date_query_no_attribute_access(self):
710708
engine, parser = self.engine, self.parser
@@ -808,7 +806,6 @@ def setup_class(cls):
808806
super().setup_class()
809807
cls.engine = "python"
810808
cls.parser = "pandas"
811-
cls.frame = TestData().frame
812809

813810
def test_query_builtin(self):
814811
engine, parser = self.engine, self.parser
@@ -827,7 +824,6 @@ class TestDataFrameQueryPythonPython(TestDataFrameQueryNumExprPython):
827824
def setup_class(cls):
828825
super().setup_class()
829826
cls.engine = cls.parser = "python"
830-
cls.frame = TestData().frame
831827

832828
def test_query_builtin(self):
833829
engine, parser = self.engine, self.parser

0 commit comments

Comments
 (0)