Skip to content

Remove TestData in frame tests in multiple files - part 3 #29226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 0 additions & 124 deletions pandas/tests/frame/common.py
Original file line number Diff line number Diff line change
@@ -1,127 +1,3 @@
import numpy as np

from pandas.util._decorators import cache_readonly

import pandas as pd
import pandas.util.testing as tm

_seriesd = tm.getSeriesData()
_tsd = tm.getTimeSeriesData()

_frame = pd.DataFrame(_seriesd)
_frame2 = pd.DataFrame(_seriesd, columns=["D", "C", "B", "A"])
_intframe = pd.DataFrame({k: v.astype(int) for k, v in _seriesd.items()})

_tsframe = pd.DataFrame(_tsd)

_mixed_frame = _frame.copy()
_mixed_frame["foo"] = "bar"


class TestData:
@cache_readonly
def frame(self):
return _frame.copy()

@cache_readonly
def frame2(self):
return _frame2.copy()

@cache_readonly
def intframe(self):
# force these all to int64 to avoid platform testing issues
return pd.DataFrame({c: s for c, s in _intframe.items()}, dtype=np.int64)

@cache_readonly
def tsframe(self):
return _tsframe.copy()

@cache_readonly
def mixed_frame(self):
return _mixed_frame.copy()

@cache_readonly
def mixed_float(self):
return pd.DataFrame(
{
"A": _frame["A"].copy().astype("float32"),
"B": _frame["B"].copy().astype("float32"),
"C": _frame["C"].copy().astype("float16"),
"D": _frame["D"].copy().astype("float64"),
}
)

@cache_readonly
def mixed_float2(self):
return pd.DataFrame(
{
"A": _frame2["A"].copy().astype("float32"),
"B": _frame2["B"].copy().astype("float32"),
"C": _frame2["C"].copy().astype("float16"),
"D": _frame2["D"].copy().astype("float64"),
}
)

@cache_readonly
def mixed_int(self):
return pd.DataFrame(
{
"A": _intframe["A"].copy().astype("int32"),
"B": np.ones(len(_intframe["B"]), dtype="uint64"),
"C": _intframe["C"].copy().astype("uint8"),
"D": _intframe["D"].copy().astype("int64"),
}
)

@cache_readonly
def all_mixed(self):
return pd.DataFrame(
{
"a": 1.0,
"b": 2,
"c": "foo",
"float32": np.array([1.0] * 10, dtype="float32"),
"int32": np.array([1] * 10, dtype="int32"),
},
index=np.arange(10),
)

@cache_readonly
def tzframe(self):
result = pd.DataFrame(
{
"A": pd.date_range("20130101", periods=3),
"B": pd.date_range("20130101", periods=3, tz="US/Eastern"),
"C": pd.date_range("20130101", periods=3, tz="CET"),
}
)
result.iloc[1, 1] = pd.NaT
result.iloc[1, 2] = pd.NaT
return result

@cache_readonly
def empty(self):
return pd.DataFrame()

@cache_readonly
def ts1(self):
return tm.makeTimeSeries(nper=30)

@cache_readonly
def ts2(self):
return tm.makeTimeSeries(nper=30)[5:]

@cache_readonly
def simple(self):
arr = np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]])

return pd.DataFrame(arr, columns=["one", "two", "three"], index=["a", "b", "c"])


# self.ts3 = tm.makeTimeSeries()[-5:]
# self.ts4 = tm.makeTimeSeries()[1:-1]


def _check_mixed_float(df, dtype=None):
# float16 are most likely to be upcasted to float32
dtypes = dict(A="float32", B="float32", C="float16", D="float64")
Expand Down
11 changes: 5 additions & 6 deletions pandas/tests/frame/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
)
import pandas.core.common as com
from pandas.core.indexing import IndexingError
from pandas.tests.frame.common import TestData
import pandas.util.testing as tm
from pandas.util.testing import (
assert_almost_equal,
Expand All @@ -36,7 +35,7 @@
from pandas.tseries.offsets import BDay


class TestDataFrameIndexing(TestData):
class TestDataFrameIndexing:
def test_getitem(self, float_frame):
# Slicing
sl = float_frame[:20]
Expand Down Expand Up @@ -1167,8 +1166,8 @@ def test_setitem_fancy_mixed_2d(self, float_string_frame):

with catch_warnings(record=True):
simplefilter("ignore", FutureWarning)
self.mixed_frame.ix[:5, ["C", "B", "A"]] = 5
result = self.mixed_frame.ix[:5, ["C", "B", "A"]]
float_string_frame.ix[:5, ["C", "B", "A"]] = 5
result = float_string_frame.ix[:5, ["C", "B", "A"]]
assert (result.values == 5).all()

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


class TestDataFrameIndexingDatetimeWithTZ(TestData):
class TestDataFrameIndexingDatetimeWithTZ:
def test_setitem(self, timezone_frame):

df = timezone_frame
Expand Down Expand Up @@ -3461,7 +3460,7 @@ def test_scalar_assignment(self):
tm.assert_frame_equal(df, expected)


class TestDataFrameIndexingUInt64(TestData):
class TestDataFrameIndexingUInt64:
def test_setitem(self, uint64_frame):

df = uint64_frame
Expand Down
4 changes: 0 additions & 4 deletions pandas/tests/frame/test_query_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import pandas as pd
from pandas import DataFrame, Index, MultiIndex, Series, date_range
from pandas.core.computation.check import _NUMEXPR_INSTALLED
from pandas.tests.frame.common import TestData
from pandas.util.testing import (
assert_frame_equal,
assert_series_equal,
Expand Down Expand Up @@ -704,7 +703,6 @@ def setup_class(cls):
super().setup_class()
cls.engine = "numexpr"
cls.parser = "python"
cls.frame = TestData().frame

def test_date_query_no_attribute_access(self):
engine, parser = self.engine, self.parser
Expand Down Expand Up @@ -808,7 +806,6 @@ def setup_class(cls):
super().setup_class()
cls.engine = "python"
cls.parser = "pandas"
cls.frame = TestData().frame

def test_query_builtin(self):
engine, parser = self.engine, self.parser
Expand All @@ -827,7 +824,6 @@ class TestDataFrameQueryPythonPython(TestDataFrameQueryNumExprPython):
def setup_class(cls):
super().setup_class()
cls.engine = cls.parser = "python"
cls.frame = TestData().frame

def test_query_builtin(self):
engine, parser = self.engine, self.parser
Expand Down