diff --git a/pandas/tests/frame/test_convert_to.py b/pandas/tests/frame/test_convert_to.py index c9a7507969f5b..17edd48e36563 100644 --- a/pandas/tests/frame/test_convert_to.py +++ b/pandas/tests/frame/test_convert_to.py @@ -13,11 +13,10 @@ Timestamp, date_range, ) -from pandas.tests.frame.common import TestData import pandas.util.testing as tm -class TestDataFrameConvertTo(TestData): +class TestDataFrameConvertTo: def test_to_dict_timestamp(self): # GH11247 diff --git a/pandas/tests/frame/test_nonunique_indexes.py b/pandas/tests/frame/test_nonunique_indexes.py index 4faa0d0e3f941..430d9ad135c80 100644 --- a/pandas/tests/frame/test_nonunique_indexes.py +++ b/pandas/tests/frame/test_nonunique_indexes.py @@ -3,12 +3,11 @@ import pandas as pd from pandas import DataFrame, MultiIndex, Series, date_range -from pandas.tests.frame.common import TestData import pandas.util.testing as tm from pandas.util.testing import assert_frame_equal, assert_series_equal -class TestDataFrameNonuniqueIndexes(TestData): +class TestDataFrameNonuniqueIndexes: def test_column_dups_operations(self): def check(result, expected=None): if expected is not None: diff --git a/pandas/tests/frame/test_query_eval.py b/pandas/tests/frame/test_query_eval.py index f5f6c9ad6b3da..13b994d116c76 100644 --- a/pandas/tests/frame/test_query_eval.py +++ b/pandas/tests/frame/test_query_eval.py @@ -82,7 +82,7 @@ def test_query_numexpr(self): df.eval("A+1", engine="numexpr") -class TestDataFrameEval(TestData): +class TestDataFrameEval: def test_ops(self): # tst ops and reversed ops in evaluation diff --git a/pandas/tests/frame/test_replace.py b/pandas/tests/frame/test_replace.py index b341ed6a52ca5..fdb450da53137 100644 --- a/pandas/tests/frame/test_replace.py +++ b/pandas/tests/frame/test_replace.py @@ -8,7 +8,6 @@ import pandas as pd from pandas import DataFrame, Index, Series, Timestamp, date_range -from pandas.tests.frame.common import TestData from pandas.util.testing import assert_frame_equal, assert_series_equal @@ -22,27 +21,27 @@ def mix_abc() -> Dict[str, list]: return {"a": list(range(4)), "b": list("ab.."), "c": ["a", "b", np.nan, "d"]} -class TestDataFrameReplace(TestData): - def test_replace_inplace(self): - self.tsframe["A"][:5] = np.nan - self.tsframe["A"][-5:] = np.nan +class TestDataFrameReplace: + def test_replace_inplace(self, datetime_frame, float_string_frame): + datetime_frame["A"][:5] = np.nan + datetime_frame["A"][-5:] = np.nan - tsframe = self.tsframe.copy() + tsframe = datetime_frame.copy() tsframe.replace(np.nan, 0, inplace=True) - assert_frame_equal(tsframe, self.tsframe.fillna(0)) + assert_frame_equal(tsframe, datetime_frame.fillna(0)) # mixed type - mf = self.mixed_frame + mf = float_string_frame mf.iloc[5:20, mf.columns.get_loc("foo")] = np.nan mf.iloc[-10:, mf.columns.get_loc("A")] = np.nan - result = self.mixed_frame.replace(np.nan, 0) - expected = self.mixed_frame.fillna(value=0) + result = float_string_frame.replace(np.nan, 0) + expected = float_string_frame.fillna(value=0) assert_frame_equal(result, expected) - tsframe = self.tsframe.copy() + tsframe = datetime_frame.copy() tsframe.replace([np.nan], [0], inplace=True) - assert_frame_equal(tsframe, self.tsframe.fillna(0)) + assert_frame_equal(tsframe, datetime_frame.fillna(0)) def test_regex_replace_scalar(self, mix_ab): obj = {"a": list("ab.."), "b": list("efgh")} @@ -583,17 +582,17 @@ def test_replace_regex_metachar(self, metachar): expected = DataFrame({"a": ["paren", "else"]}) assert_frame_equal(result, expected) - def test_replace(self): - self.tsframe["A"][:5] = np.nan - self.tsframe["A"][-5:] = np.nan + def test_replace(self, datetime_frame): + datetime_frame["A"][:5] = np.nan + datetime_frame["A"][-5:] = np.nan - zero_filled = self.tsframe.replace(np.nan, -1e8) - assert_frame_equal(zero_filled, self.tsframe.fillna(-1e8)) - assert_frame_equal(zero_filled.replace(-1e8, np.nan), self.tsframe) + zero_filled = datetime_frame.replace(np.nan, -1e8) + assert_frame_equal(zero_filled, datetime_frame.fillna(-1e8)) + assert_frame_equal(zero_filled.replace(-1e8, np.nan), datetime_frame) - self.tsframe["A"][:5] = np.nan - self.tsframe["A"][-5:] = np.nan - self.tsframe["B"][:5] = -1e8 + datetime_frame["A"][:5] = np.nan + datetime_frame["A"][-5:] = np.nan + datetime_frame["B"][:5] = -1e8 # empty df = DataFrame(index=["a", "b"]) @@ -684,20 +683,20 @@ def test_replace_convert(self): res = rep.dtypes assert_series_equal(expec, res) - def test_replace_mixed(self): - mf = self.mixed_frame + def test_replace_mixed(self, float_string_frame): + mf = float_string_frame mf.iloc[5:20, mf.columns.get_loc("foo")] = np.nan mf.iloc[-10:, mf.columns.get_loc("A")] = np.nan - result = self.mixed_frame.replace(np.nan, -18) - expected = self.mixed_frame.fillna(value=-18) + result = float_string_frame.replace(np.nan, -18) + expected = float_string_frame.fillna(value=-18) assert_frame_equal(result, expected) - assert_frame_equal(result.replace(-18, np.nan), self.mixed_frame) + assert_frame_equal(result.replace(-18, np.nan), float_string_frame) - result = self.mixed_frame.replace(np.nan, -1e8) - expected = self.mixed_frame.fillna(value=-1e8) + result = float_string_frame.replace(np.nan, -1e8) + expected = float_string_frame.fillna(value=-1e8) assert_frame_equal(result, expected) - assert_frame_equal(result.replace(-1e8, np.nan), self.mixed_frame) + assert_frame_equal(result.replace(-1e8, np.nan), float_string_frame) # int block upcasting df = DataFrame( @@ -793,30 +792,30 @@ def test_replace_simple_nested_dict_with_nonexistent_value(self): result = df.replace({"col": {-1: "-", 1: "a", 4: "b"}}) assert_frame_equal(expected, result) - def test_replace_value_is_none(self): - orig_value = self.tsframe.iloc[0, 0] - orig2 = self.tsframe.iloc[1, 0] + def test_replace_value_is_none(self, datetime_frame): + orig_value = datetime_frame.iloc[0, 0] + orig2 = datetime_frame.iloc[1, 0] - self.tsframe.iloc[0, 0] = np.nan - self.tsframe.iloc[1, 0] = 1 + datetime_frame.iloc[0, 0] = np.nan + datetime_frame.iloc[1, 0] = 1 - result = self.tsframe.replace(to_replace={np.nan: 0}) - expected = self.tsframe.T.replace(to_replace={np.nan: 0}).T + result = datetime_frame.replace(to_replace={np.nan: 0}) + expected = datetime_frame.T.replace(to_replace={np.nan: 0}).T assert_frame_equal(result, expected) - result = self.tsframe.replace(to_replace={np.nan: 0, 1: -1e8}) - tsframe = self.tsframe.copy() + result = datetime_frame.replace(to_replace={np.nan: 0, 1: -1e8}) + tsframe = datetime_frame.copy() tsframe.iloc[0, 0] = 0 tsframe.iloc[1, 0] = -1e8 expected = tsframe assert_frame_equal(expected, result) - self.tsframe.iloc[0, 0] = orig_value - self.tsframe.iloc[1, 0] = orig2 + datetime_frame.iloc[0, 0] = orig_value + datetime_frame.iloc[1, 0] = orig2 - def test_replace_for_new_dtypes(self): + def test_replace_for_new_dtypes(self, datetime_frame): # dtypes - tsframe = self.tsframe.copy().astype(np.float32) + tsframe = datetime_frame.copy().astype(np.float32) tsframe["A"][:5] = np.nan tsframe["A"][-5:] = np.nan diff --git a/pandas/tests/frame/test_repr_info.py b/pandas/tests/frame/test_repr_info.py index 48f42b5f101ce..318b1c6add91e 100644 --- a/pandas/tests/frame/test_repr_info.py +++ b/pandas/tests/frame/test_repr_info.py @@ -18,7 +18,6 @@ option_context, period_range, ) -from pandas.tests.frame.common import TestData import pandas.util.testing as tm import pandas.io.formats.format as fmt @@ -27,21 +26,21 @@ # structure -class TestDataFrameReprInfoEtc(TestData): +class TestDataFrameReprInfoEtc: def test_repr_empty(self): # empty - foo = repr(self.empty) # noqa + foo = repr(DataFrame()) # noqa # empty with index frame = DataFrame(index=np.arange(1000)) foo = repr(frame) # noqa - def test_repr_mixed(self): + def test_repr_mixed(self, float_string_frame): buf = StringIO() # mixed - foo = repr(self.mixed_frame) # noqa - self.mixed_frame.info(verbose=False, buf=buf) + foo = repr(float_string_frame) # noqa + float_string_frame.info(verbose=False, buf=buf) @pytest.mark.slow def test_repr_mixed_big(self): @@ -54,16 +53,16 @@ def test_repr_mixed_big(self): foo = repr(biggie) # noqa - def test_repr(self): + def test_repr(self, float_frame): buf = StringIO() # small one - foo = repr(self.frame) - self.frame.info(verbose=False, buf=buf) + foo = repr(float_frame) + float_frame.info(verbose=False, buf=buf) # even smaller - self.frame.reindex(columns=["A"]).info(verbose=False, buf=buf) - self.frame.reindex(columns=["A", "B"]).info(verbose=False, buf=buf) + float_frame.reindex(columns=["A"]).info(verbose=False, buf=buf) + float_frame.reindex(columns=["A", "B"]).info(verbose=False, buf=buf) # exhausting cases in DataFrame.info @@ -72,7 +71,7 @@ def test_repr(self): foo = repr(no_index) # noqa # no columns or index - self.empty.info(buf=buf) + DataFrame().info(buf=buf) df = DataFrame(["a\n\r\tb"], columns=["a\n\r\td"], index=["a\n\r\tf"]) assert "\t" not in repr(df) @@ -96,7 +95,7 @@ def test_repr_big(self): biggie = DataFrame(np.zeros((200, 4)), columns=range(4), index=range(200)) repr(biggie) - def test_repr_unsortable(self): + def test_repr_unsortable(self, float_frame): # columns are not sortable import warnings @@ -115,13 +114,13 @@ def test_repr_unsortable(self): repr(unsortable) fmt.set_option("display.precision", 3, "display.column_space", 10) - repr(self.frame) + repr(float_frame) fmt.set_option("display.max_rows", 10, "display.max_columns", 2) - repr(self.frame) + repr(float_frame) fmt.set_option("display.max_rows", 1000, "display.max_columns", 1000) - repr(self.frame) + repr(float_frame) tm.reset_display_options() @@ -196,10 +195,10 @@ def test_latex_repr(self): # GH 12182 assert df._repr_latex_() is None - def test_info(self): + def test_info(self, float_frame, datetime_frame): io = StringIO() - self.frame.info(buf=io) - self.tsframe.info(buf=io) + float_frame.info(buf=io) + datetime_frame.info(buf=io) frame = DataFrame(np.random.randn(5, 3))