diff --git a/pandas/tests/frame/indexing/test_indexing.py b/pandas/tests/frame/indexing/test_indexing.py index 4fa5e4196ae5b..274057da76b2b 100644 --- a/pandas/tests/frame/indexing/test_indexing.py +++ b/pandas/tests/frame/indexing/test_indexing.py @@ -44,7 +44,7 @@ def test_get(self, float_frame): @pytest.mark.parametrize( "df", [ - DataFrame(), + empty_frame(), DataFrame(columns=list("AB")), DataFrame(columns=list("AB"), index=range(3)), ], @@ -842,7 +842,7 @@ def test_setitem_with_empty_listlike(self): def test_setitem_scalars_no_index(self): # GH16823 / 17894 - df = DataFrame() + df = empty_frame() df["foo"] = 1 expected = DataFrame(columns=["foo"]).astype(np.int64) tm.assert_frame_equal(df, expected) @@ -1669,7 +1669,7 @@ def test_reindex_subclass(self): class MyDataFrame(DataFrame): pass - expected = DataFrame() + expected = empty_frame() df = MyDataFrame() result = df.reindex_like(expected) diff --git a/pandas/tests/frame/indexing/test_insert.py b/pandas/tests/frame/indexing/test_insert.py index 622c93d1c2fdc..dc3ae63dc229e 100644 --- a/pandas/tests/frame/indexing/test_insert.py +++ b/pandas/tests/frame/indexing/test_insert.py @@ -58,7 +58,7 @@ def test_insert_column_bug_4032(self): def test_insert_with_columns_dups(self): # GH#14291 - df = DataFrame() + df = empty_frame() df.insert(0, "A", ["g", "h", "i"], allow_duplicates=True) df.insert(0, "A", ["d", "e", "f"], allow_duplicates=True) df.insert(0, "A", ["a", "b", "c"], allow_duplicates=True) diff --git a/pandas/tests/frame/methods/test_append.py b/pandas/tests/frame/methods/test_append.py index 9fc3629e794e2..455101982daa2 100644 --- a/pandas/tests/frame/methods/test_append.py +++ b/pandas/tests/frame/methods/test_append.py @@ -9,7 +9,7 @@ class TestDataFrameAppend: def test_append_empty_list(self): # GH 28769 - df = DataFrame() + df = empty_frame() result = df.append([]) expected = df tm.assert_frame_equal(result, expected) @@ -96,29 +96,29 @@ def test_append_missing_cols(self): def test_append_empty_dataframe(self): # Empty df append empty df - df1 = DataFrame() - df2 = DataFrame() + df1 = empty_frame() + df2 = empty_frame() result = df1.append(df2) expected = df1.copy() tm.assert_frame_equal(result, expected) # Non-empty df append empty df df1 = DataFrame(np.random.randn(5, 2)) - df2 = DataFrame() + df2 = empty_frame() result = df1.append(df2) expected = df1.copy() tm.assert_frame_equal(result, expected) # Empty df with columns append empty df df1 = DataFrame(columns=["bar", "foo"]) - df2 = DataFrame() + df2 = empty_frame() result = df1.append(df2) expected = df1.copy() tm.assert_frame_equal(result, expected) # Non-Empty df with columns append empty df df1 = DataFrame(np.random.randn(5, 2), columns=["bar", "foo"]) - df2 = DataFrame() + df2 = empty_frame() result = df1.append(df2) expected = df1.copy() tm.assert_frame_equal(result, expected) @@ -130,7 +130,7 @@ def test_append_dtypes(self): # can sometimes infer the correct type df1 = DataFrame({"bar": Timestamp("20130101")}, index=range(5)) - df2 = DataFrame() + df2 = empty_frame() result = df1.append(df2) expected = df1.copy() tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/frame/methods/test_combine_first.py b/pandas/tests/frame/methods/test_combine_first.py index 7715cb1cb6eec..2ef76aa9f2c5a 100644 --- a/pandas/tests/frame/methods/test_combine_first.py +++ b/pandas/tests/frame/methods/test_combine_first.py @@ -73,7 +73,7 @@ def test_combine_first(self, float_frame): comb = float_frame.combine_first(DataFrame()) tm.assert_frame_equal(comb, float_frame) - comb = DataFrame().combine_first(float_frame) + comb = empty_frame().combine_first(float_frame) tm.assert_frame_equal(comb, float_frame) comb = float_frame.combine_first(DataFrame(index=["faz", "boo"])) diff --git a/pandas/tests/frame/methods/test_count.py b/pandas/tests/frame/methods/test_count.py index 13a93e3efc48c..3c09f0aa1916f 100644 --- a/pandas/tests/frame/methods/test_count.py +++ b/pandas/tests/frame/methods/test_count.py @@ -5,7 +5,7 @@ class TestDataFrameCount: def test_count(self): # corner case - frame = DataFrame() + frame = empty_frame() ct1 = frame.count(1) assert isinstance(ct1, Series) @@ -23,7 +23,7 @@ def test_count(self): expected = Series(0, index=df.columns) tm.assert_series_equal(result, expected) - df = DataFrame() + df = empty_frame() result = df.count() expected = Series(0, index=[]) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/frame/methods/test_drop_duplicates.py b/pandas/tests/frame/methods/test_drop_duplicates.py index fd4bae26ade57..1b7a86bfdf09a 100644 --- a/pandas/tests/frame/methods/test_drop_duplicates.py +++ b/pandas/tests/frame/methods/test_drop_duplicates.py @@ -193,7 +193,7 @@ def test_drop_duplicates_tuple(): @pytest.mark.parametrize( "df", [ - DataFrame(), + empty_frame(), DataFrame(columns=[]), DataFrame(columns=["A", "B", "C"]), DataFrame(index=[]), diff --git a/pandas/tests/frame/methods/test_filter.py b/pandas/tests/frame/methods/test_filter.py index 569b2fe21d1c2..51b232ad09467 100644 --- a/pandas/tests/frame/methods/test_filter.py +++ b/pandas/tests/frame/methods/test_filter.py @@ -122,7 +122,7 @@ def test_filter_bytestring(self, name): tm.assert_frame_equal(df.filter(regex=name), expected) def test_filter_corner(self): - empty = DataFrame() + empty = empty_frame() result = empty.filter([]) tm.assert_frame_equal(result, empty) diff --git a/pandas/tests/frame/methods/test_head_tail.py b/pandas/tests/frame/methods/test_head_tail.py index 93763bc12ce0d..1f1b53c03f389 100644 --- a/pandas/tests/frame/methods/test_head_tail.py +++ b/pandas/tests/frame/methods/test_head_tail.py @@ -25,6 +25,6 @@ def test_head_tail(float_frame): tm.assert_frame_equal(df.head(-1), df.iloc[:-1]) tm.assert_frame_equal(df.tail(-1), df.iloc[1:]) # test empty dataframe - empty_df = DataFrame() + empty_df = empty_frame() tm.assert_frame_equal(empty_df.tail(), empty_df) tm.assert_frame_equal(empty_df.head(), empty_df) diff --git a/pandas/tests/frame/methods/test_isin.py b/pandas/tests/frame/methods/test_isin.py index 6307738021f68..a0c7ab4a72502 100644 --- a/pandas/tests/frame/methods/test_isin.py +++ b/pandas/tests/frame/methods/test_isin.py @@ -176,7 +176,7 @@ def test_isin_empty_datetimelike(self): df1_ts = DataFrame({"date": pd.to_datetime(["2014-01-01", "2014-01-02"])}) df1_td = DataFrame({"date": [pd.Timedelta(1, "s"), pd.Timedelta(2, "s")]}) df2 = DataFrame({"date": []}) - df3 = DataFrame() + df3 = empty_frame() expected = DataFrame({"date": [False, False]}) diff --git a/pandas/tests/frame/methods/test_round.py b/pandas/tests/frame/methods/test_round.py index 6dcdf49e93729..5e0cf3229ebd0 100644 --- a/pandas/tests/frame/methods/test_round.py +++ b/pandas/tests/frame/methods/test_round.py @@ -11,7 +11,7 @@ def test_round(self): # GH#2665 # Test that rounding an empty DataFrame does nothing - df = DataFrame() + df = empty_frame() tm.assert_frame_equal(df, df.round()) # Here's the test frame we'll be working with diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index 6525e93d89fce..e11045d7e1740 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -754,7 +754,7 @@ def test_operators_timedelta64(self): assert df["off2"].dtype == "timedelta64[ns]" def test_sum_corner(self): - empty_frame = DataFrame() + empty_frame = empty_frame() axis0 = empty_frame.sum(0) axis1 = empty_frame.sum(1) diff --git a/pandas/tests/frame/test_api.py b/pandas/tests/frame/test_api.py index 91627b46c2fee..82fe90e0c7f96 100644 --- a/pandas/tests/frame/test_api.py +++ b/pandas/tests/frame/test_api.py @@ -118,7 +118,7 @@ def test_tab_completion(self): assert isinstance(df.__getitem__("A"), pd.DataFrame) def test_not_hashable(self): - empty_frame = DataFrame() + empty_frame = empty_frame() df = DataFrame([1]) msg = "'DataFrame' objects are mutable, thus they cannot be hashed" @@ -162,7 +162,7 @@ def test_get_agg_axis(self, float_frame): float_frame._get_agg_axis(2) def test_nonzero(self, float_frame, float_string_frame): - empty_frame = DataFrame() + empty_frame = empty_frame() assert empty_frame.empty assert not float_frame.empty @@ -423,7 +423,7 @@ def test_empty_nonzero(self): assert df.empty assert df.T.empty empty_frames = [ - DataFrame(), + empty_frame(), DataFrame(index=[1]), DataFrame(columns=[1]), DataFrame({1: []}), diff --git a/pandas/tests/frame/test_apply.py b/pandas/tests/frame/test_apply.py index e328523253144..87fcebde8553c 100644 --- a/pandas/tests/frame/test_apply.py +++ b/pandas/tests/frame/test_apply.py @@ -74,7 +74,7 @@ def test_apply_mixed_datetimelike(self): def test_apply_empty(self, float_frame): # empty - empty_frame = DataFrame() + empty_frame = empty_frame() applied = empty_frame.apply(np.sqrt) assert applied.empty @@ -99,7 +99,7 @@ def test_apply_empty(self, float_frame): def test_apply_with_reduce_empty(self): # reduce with an empty DataFrame - empty_frame = DataFrame() + empty_frame = empty_frame() x = [] result = empty_frame.apply(x.append, axis=1, result_type="expand") @@ -760,7 +760,7 @@ def test_with_dictlike_columns(self): tm.assert_series_equal(result, expected) # GH 18775 - df = DataFrame() + df = empty_frame() df["author"] = ["X", "Y", "Z"] df["publisher"] = ["BBC", "NBC", "N24"] df["date"] = pd.to_datetime( @@ -1323,7 +1323,7 @@ def func(group_col): "df, func, expected", chain( tm.get_cython_table_params( - DataFrame(), + empty_frame(), [ ("sum", Series(dtype="float64")), ("max", Series(dtype="float64")), @@ -1365,7 +1365,7 @@ def test_agg_cython_table(self, df, func, expected, axis): "df, func, expected", chain( tm.get_cython_table_params( - DataFrame(), [("cumprod", DataFrame()), ("cumsum", DataFrame())] + empty_frame(), [("cumprod", empty_frame()), ("cumsum", empty_frame())] ), tm.get_cython_table_params( DataFrame([[np.nan, 1], [1, 2]]), diff --git a/pandas/tests/frame/test_arithmetic.py b/pandas/tests/frame/test_arithmetic.py index 89f8bc433419b..bc9e8feae40a1 100644 --- a/pandas/tests/frame/test_arithmetic.py +++ b/pandas/tests/frame/test_arithmetic.py @@ -990,13 +990,13 @@ def test_combineFrame(self, float_frame, mixed_float_frame, mixed_int_frame): # corner cases # empty - plus_empty = float_frame + DataFrame() + plus_empty = float_frame + empty_frame() assert np.isnan(plus_empty.values).all() - empty_plus = DataFrame() + float_frame + empty_plus = empty_frame() + float_frame assert np.isnan(empty_plus.values).all() - empty_empty = DataFrame() + DataFrame() + empty_empty = empty_frame() + empty_frame() assert empty_empty.empty # out of order @@ -1116,7 +1116,7 @@ def test_combineFunc(self, float_frame, mixed_float_frame): tm.assert_numpy_array_equal(s.values, mixed_float_frame[c].values * 2) _check_mixed_float(result, dtype=dict(C=None)) - result = DataFrame() * 2 + result = empty_frame() * 2 assert result.index.equals(DataFrame().index) assert len(result.columns) == 0 diff --git a/pandas/tests/frame/test_block_internals.py b/pandas/tests/frame/test_block_internals.py index e67fef9efef6d..bd008f08a6aa1 100644 --- a/pandas/tests/frame/test_block_internals.py +++ b/pandas/tests/frame/test_block_internals.py @@ -345,7 +345,7 @@ def test_copy(self, float_frame, float_string_frame): assert copy._data is not float_string_frame._data def test_pickle(self, float_string_frame, timezone_frame): - empty_frame = DataFrame() + empty_frame = empty_frame() unpickled = tm.round_trip_pickle(float_string_frame) tm.assert_frame_equal(float_string_frame, unpickled) diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index 9f40e8c6931c8..73fa67e6d8287 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -62,7 +62,7 @@ def test_series_with_name_not_matching_column(self): @pytest.mark.parametrize( "constructor", [ - lambda: DataFrame(), + lambda: empty_frame(), lambda: DataFrame(None), lambda: DataFrame({}), lambda: DataFrame(()), @@ -78,7 +78,7 @@ def test_series_with_name_not_matching_column(self): ], ) def test_empty_constructor(self, constructor): - expected = DataFrame() + expected = empty_frame() result = constructor() assert len(result.index) == 0 assert len(result.columns) == 0 @@ -1774,7 +1774,7 @@ def test_constructor_with_datetimes(self): i = date_range("1/1/2011", periods=5, freq="10s", tz="US/Eastern") expected = DataFrame({"a": i.to_series().reset_index(drop=True)}) - df = DataFrame() + df = empty_frame() df["a"] = i tm.assert_frame_equal(df, expected) diff --git a/pandas/tests/frame/test_missing.py b/pandas/tests/frame/test_missing.py index 7cb7115276f71..6dc77b835adf3 100644 --- a/pandas/tests/frame/test_missing.py +++ b/pandas/tests/frame/test_missing.py @@ -167,7 +167,7 @@ def test_dropna_multiple_axes(self): def test_dropna_tz_aware_datetime(self): # GH13407 - df = DataFrame() + df = empty_frame() dt1 = datetime.datetime(2015, 1, 1, tzinfo=dateutil.tz.tzutc()) dt2 = datetime.datetime(2015, 2, 2, tzinfo=dateutil.tz.tzutc()) df["Time"] = [dt1] diff --git a/pandas/tests/frame/test_repr_info.py b/pandas/tests/frame/test_repr_info.py index 6d786d9580542..e1edeb426a54b 100644 --- a/pandas/tests/frame/test_repr_info.py +++ b/pandas/tests/frame/test_repr_info.py @@ -63,7 +63,7 @@ def test_repr(self, float_frame): repr(no_index) # no columns or index - DataFrame().info(buf=buf) + empty_frame().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) diff --git a/pandas/tests/frame/test_reshape.py b/pandas/tests/frame/test_reshape.py index 9d3c40ce926d7..d2e72d376dbbc 100644 --- a/pandas/tests/frame/test_reshape.py +++ b/pandas/tests/frame/test_reshape.py @@ -53,7 +53,7 @@ def test_pivot_duplicates(self): def test_pivot_empty(self): df = DataFrame(columns=["a", "b", "c"]) result = df.pivot("a", "b", "c") - expected = DataFrame() + expected = empty_frame() tm.assert_frame_equal(result, expected, check_names=False) def test_pivot_integer_bug(self): diff --git a/pandas/tests/groupby/aggregate/test_aggregate.py b/pandas/tests/groupby/aggregate/test_aggregate.py index e860ea1a3d052..fe8e09256c334 100644 --- a/pandas/tests/groupby/aggregate/test_aggregate.py +++ b/pandas/tests/groupby/aggregate/test_aggregate.py @@ -223,7 +223,7 @@ def test_aggregate_item_by_item(df): def aggfun(ser): return ser.size - result = DataFrame().groupby(df.A).agg(aggfun) + result = empty_frame().groupby(df.A).agg(aggfun) assert isinstance(result, DataFrame) assert len(result) == 0 diff --git a/pandas/tests/groupby/test_apply.py b/pandas/tests/groupby/test_apply.py index 9fbcced75c327..3b9567dffe56c 100644 --- a/pandas/tests/groupby/test_apply.py +++ b/pandas/tests/groupby/test_apply.py @@ -658,7 +658,7 @@ def test_func(x): pass result = test_df.groupby("groups").apply(test_func) - expected = DataFrame() + expected = empty_frame() tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/groupby/test_counting.py b/pandas/tests/groupby/test_counting.py index b4239d7d34a90..36a910f6dfd0f 100644 --- a/pandas/tests/groupby/test_counting.py +++ b/pandas/tests/groupby/test_counting.py @@ -19,7 +19,7 @@ def test_cumcount(self): tm.assert_series_equal(expected, sg.cumcount()) def test_cumcount_empty(self): - ge = DataFrame().groupby(level=0) + ge = empty_frame().groupby(level=0) se = Series(dtype=object).groupby(level=0) # edge case, as this is usually considered float @@ -94,7 +94,7 @@ def test_ngroup_one_group(self): tm.assert_series_equal(expected, sg.ngroup()) def test_ngroup_empty(self): - ge = DataFrame().groupby(level=0) + ge = empty_frame().groupby(level=0) se = Series(dtype=object).groupby(level=0) # edge case, as this is usually considered float diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index b8d8f56512a69..6b19b47f1fe4f 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -310,7 +310,7 @@ def f1(x): def f2(x): y = x[(x.b % 2) == 1] ** 2 if y.empty: - return DataFrame() + return empty_frame() else: y = y.set_index(["b", "c"]) return y diff --git a/pandas/tests/indexes/datetimes/test_datetime.py b/pandas/tests/indexes/datetimes/test_datetime.py index 1529a259c49af..b28906d326667 100644 --- a/pandas/tests/indexes/datetimes/test_datetime.py +++ b/pandas/tests/indexes/datetimes/test_datetime.py @@ -236,7 +236,7 @@ def test_groupby_function_tuple_1677(self): def test_append_numpy_bug_1681(self): # another datetime64 bug dr = date_range("2011/1/1", "2012/1/1", freq="W-FRI") - a = DataFrame() + a = empty_frame() c = DataFrame({"A": "foo", "B": dr}, index=dr) result = a.append(c) diff --git a/pandas/tests/indexes/timedeltas/test_timedelta.py b/pandas/tests/indexes/timedeltas/test_timedelta.py index fa00b870ca757..649164f33e77d 100644 --- a/pandas/tests/indexes/timedeltas/test_timedelta.py +++ b/pandas/tests/indexes/timedeltas/test_timedelta.py @@ -171,7 +171,7 @@ def test_pass_TimedeltaIndex_to_index(self): def test_append_numpy_bug_1681(self): td = timedelta_range("1 days", "10 days", freq="2D") - a = DataFrame() + a = empty_frame() c = DataFrame({"A": "foo", "B": td}, index=td) str(c) diff --git a/pandas/tests/indexing/common.py b/pandas/tests/indexing/common.py index 9cc031001f81c..3aa520a5e42ea 100644 --- a/pandas/tests/indexing/common.py +++ b/pandas/tests/indexing/common.py @@ -89,7 +89,7 @@ def setup_method(self, method): self.series_ts_rev = Series(np.random.randn(4), index=dates_rev) self.frame_ts_rev = DataFrame(np.random.randn(4, 4), index=dates_rev) - self.frame_empty = DataFrame() + self.frame_empty = empty_frame() self.series_empty = Series(dtype=object) # form agglomerates diff --git a/pandas/tests/indexing/test_datetime.py b/pandas/tests/indexing/test_datetime.py index c8c2d1ed587cf..b73dfe7d0b0b6 100644 --- a/pandas/tests/indexing/test_datetime.py +++ b/pandas/tests/indexing/test_datetime.py @@ -211,7 +211,7 @@ def test_loc_setitem_datetime(self): lambda x: np.datetime64(x), ]: - df = DataFrame() + df = empty_frame() df.loc[conv(dt1), "one"] = 100 df.loc[conv(dt2), "one"] = 200 diff --git a/pandas/tests/indexing/test_indexing.py b/pandas/tests/indexing/test_indexing.py index a8a21b0610c14..6938a78003e6e 100644 --- a/pandas/tests/indexing/test_indexing.py +++ b/pandas/tests/indexing/test_indexing.py @@ -169,7 +169,7 @@ def test_inf_upcast(self): tm.assert_index_equal(result, expected) # Test with np.inf in columns - df = DataFrame() + df = empty_frame() df.loc[0, 0] = 1 df.loc[1, 1] = 2 df.loc[0, np.inf] = 3 @@ -566,7 +566,7 @@ def test_string_slice(self): with pytest.raises(KeyError, match="'2011'"): df.loc["2011", 0] - df = DataFrame() + df = empty_frame() assert not df.index.is_all_dates with pytest.raises(KeyError, match="'2011'"): df["2011"] diff --git a/pandas/tests/indexing/test_partial.py b/pandas/tests/indexing/test_partial.py index 2ce07ec41758f..3625dab843984 100644 --- a/pandas/tests/indexing/test_partial.py +++ b/pandas/tests/indexing/test_partial.py @@ -373,7 +373,7 @@ def test_partial_set_empty_frame(self): # partially set with an empty object # frame - df = DataFrame() + df = empty_frame() with pytest.raises(ValueError): df.loc[1] = 1 @@ -397,14 +397,14 @@ def f(): tm.assert_frame_equal(f(), expected) def f(): - df = DataFrame() + df = empty_frame() df["foo"] = Series(df.index) return df tm.assert_frame_equal(f(), expected) def f(): - df = DataFrame() + df = empty_frame() df["foo"] = df.index return df @@ -436,9 +436,9 @@ def f(): expected["foo"] = expected["foo"].astype("float64") tm.assert_frame_equal(f(), expected) - df = DataFrame() + df = empty_frame() tm.assert_index_equal(df.columns, Index([], dtype=object)) - df2 = DataFrame() + df2 = empty_frame() df2[1] = Series([1], index=["foo"]) df.loc[:, 1] = Series([1], index=["foo"]) tm.assert_frame_equal(df, DataFrame([[1]], index=["foo"], columns=[1])) diff --git a/pandas/tests/io/excel/test_readers.py b/pandas/tests/io/excel/test_readers.py index b1502ed3f3c09..53cb9e9ba0a32 100644 --- a/pandas/tests/io/excel/test_readers.py +++ b/pandas/tests/io/excel/test_readers.py @@ -503,7 +503,7 @@ def test_reading_all_sheets_with_blank(self, read_ext): # GH6403 def test_read_excel_blank(self, read_ext): actual = pd.read_excel("blank" + read_ext, "Sheet1") - tm.assert_frame_equal(actual, DataFrame()) + tm.assert_frame_equal(actual, empty_frame()) def test_read_excel_blank_with_header(self, read_ext): expected = DataFrame(columns=["col_1", "col_2"]) diff --git a/pandas/tests/io/formats/test_style.py b/pandas/tests/io/formats/test_style.py index ec4614538004c..a7ebb5c28c595 100644 --- a/pandas/tests/io/formats/test_style.py +++ b/pandas/tests/io/formats/test_style.py @@ -117,7 +117,7 @@ def test_render(self): # it worked? def test_render_empty_dfs(self): - empty_df = DataFrame() + empty_df = empty_frame() es = Styler(empty_df) es.render() # An index but no columns diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 9a14022d6f776..7b2ba62bfee4a 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -391,7 +391,7 @@ def test_to_html_justify(justify, datapath): ) def test_to_html_invalid_justify(justify): # GH 17527 - df = DataFrame() + df = empty_frame() msg = "Invalid value for justify parameter" with pytest.raises(ValueError, match=msg): @@ -439,7 +439,7 @@ def test_to_html_index(datapath): @pytest.mark.parametrize("classes", ["sortable draggable", ["sortable", "draggable"]]) def test_to_html_with_classes(classes, datapath): - df = DataFrame() + df = empty_frame() expected = expected_html(datapath, "with_classes") result = df.to_html(classes=classes) assert result == expected @@ -718,7 +718,7 @@ def test_ignore_display_max_colwidth(method, expected, max_colwidth): @pytest.mark.parametrize("classes", [True, 0]) def test_to_html_invalid_classes_type(classes): # GH 25608 - df = DataFrame() + df = empty_frame() msg = "classes must be a string, list, or tuple" with pytest.raises(TypeError, match=msg): diff --git a/pandas/tests/io/formats/test_to_latex.py b/pandas/tests/io/formats/test_to_latex.py index 509e5bcb33304..7cdc4d5e2ab61 100644 --- a/pandas/tests/io/formats/test_to_latex.py +++ b/pandas/tests/io/formats/test_to_latex.py @@ -79,7 +79,7 @@ def test_to_latex_format(self, float_frame): assert withindex_result == withindex_expected def test_to_latex_empty(self): - df = DataFrame() + df = empty_frame() result = df.to_latex() expected = r"""\begin{tabular}{l} \toprule diff --git a/pandas/tests/io/json/test_normalize.py b/pandas/tests/io/json/test_normalize.py index b7a9918ff46da..a0cf8f6ad1151 100644 --- a/pandas/tests/io/json/test_normalize.py +++ b/pandas/tests/io/json/test_normalize.py @@ -165,7 +165,7 @@ def test_simple_normalize(self, state_data): def test_empty_array(self): result = json_normalize([]) - expected = DataFrame() + expected = empty_frame() tm.assert_frame_equal(result, expected) def test_simple_normalize_with_separator(self, deep_nested): diff --git a/pandas/tests/io/parser/test_mangle_dupes.py b/pandas/tests/io/parser/test_mangle_dupes.py index 5c4e642115798..ab837f51e9bfa 100644 --- a/pandas/tests/io/parser/test_mangle_dupes.py +++ b/pandas/tests/io/parser/test_mangle_dupes.py @@ -121,7 +121,7 @@ def test_mangled_unnamed_placeholders(all_parsers): # This test recursively updates `df`. for i in range(3): - expected = DataFrame() + expected = empty_frame() for j in range(i + 1): expected["Unnamed: 0" + ".1" * j] = [0, 1, 2] diff --git a/pandas/tests/io/parser/test_usecols.py b/pandas/tests/io/parser/test_usecols.py index 979eb4702cc84..0ad9c54145d45 100644 --- a/pandas/tests/io/parser/test_usecols.py +++ b/pandas/tests/io/parser/test_usecols.py @@ -408,7 +408,7 @@ def test_usecols_with_multi_byte_characters(all_parsers, usecols): def test_empty_usecols(all_parsers): data = "a,b,c\n1,2,3\n4,5,6" - expected = DataFrame() + expected = empty_frame() parser = all_parsers result = parser.read_csv(StringIO(data), usecols=set()) @@ -443,7 +443,7 @@ def test_np_array_usecols(all_parsers): } ), ), - (lambda x: False, DataFrame()), + (lambda x: False, empty_frame()), ], ) def test_callable_usecols(all_parsers, usecols, expected): diff --git a/pandas/tests/io/pytables/test_store.py b/pandas/tests/io/pytables/test_store.py index 9a0788ea068ad..b9f49f3dfda54 100644 --- a/pandas/tests/io/pytables/test_store.py +++ b/pandas/tests/io/pytables/test_store.py @@ -2391,7 +2391,7 @@ def test_frame(self, compression, setup_path): def test_empty_series_frame(self, setup_path): s0 = Series(dtype=object) s1 = Series(name="myseries", dtype=object) - df0 = DataFrame() + df0 = empty_frame() df1 = DataFrame(index=["a", "b", "c"]) df2 = DataFrame(columns=["d", "e", "f"]) diff --git a/pandas/tests/io/test_sql.py b/pandas/tests/io/test_sql.py index 2f2ae8cd9d32b..f11147abf658a 100644 --- a/pandas/tests/io/test_sql.py +++ b/pandas/tests/io/test_sql.py @@ -885,7 +885,7 @@ def test_chunksize_read(self): res1 = sql.read_sql_query("select * from test_chunksize", self.conn) # reading the query in chunks with read_sql_query - res2 = DataFrame() + res2 = empty_frame() i = 0 sizes = [5, 5, 5, 5, 2] @@ -900,7 +900,7 @@ def test_chunksize_read(self): # reading the query in chunks with read_sql_query if self.mode == "sqlalchemy": - res3 = DataFrame() + res3 = empty_frame() i = 0 sizes = [5, 5, 5, 5, 2] diff --git a/pandas/tests/resample/test_base.py b/pandas/tests/resample/test_base.py index 6384c5f19c898..7d065a5029d64 100644 --- a/pandas/tests/resample/test_base.py +++ b/pandas/tests/resample/test_base.py @@ -83,7 +83,7 @@ def test_resample_interpolate(frame): def test_raises_on_non_datetimelike_index(): # this is a non datetimelike index - xp = DataFrame() + xp = empty_frame() msg = ( "Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, " "but got an instance of 'Index'" diff --git a/pandas/tests/reshape/merge/test_join.py b/pandas/tests/reshape/merge/test_join.py index dc1efa46403be..73980f7d5c24f 100644 --- a/pandas/tests/reshape/merge/test_join.py +++ b/pandas/tests/reshape/merge/test_join.py @@ -377,7 +377,7 @@ def test_join_index_mixed_overlap(self): def test_join_empty_bug(self): # generated an exception in 0.4.3 - x = DataFrame() + x = empty_frame() x.join(DataFrame([3], index=[0], columns=["A"]), how="outer") def test_join_unconsolidated(self): diff --git a/pandas/tests/reshape/test_concat.py b/pandas/tests/reshape/test_concat.py index a12395b32ab4e..a8dd58e827556 100644 --- a/pandas/tests/reshape/test_concat.py +++ b/pandas/tests/reshape/test_concat.py @@ -796,7 +796,7 @@ def test_append(self, sort, float_frame): ) def test_append_empty(self, float_frame): - empty = DataFrame() + empty = empty_frame() appended = float_frame.append(empty) tm.assert_frame_equal(float_frame, appended) @@ -1528,7 +1528,7 @@ def test_handle_empty_objects(self, sort): df = DataFrame( dict(A=range(10000)), index=date_range("20130101", periods=10000, freq="s") ) - empty = DataFrame() + empty = empty_frame() result = concat([df, empty], axis=1) tm.assert_frame_equal(result, df) result = concat([empty, df], axis=1) diff --git a/pandas/tests/reshape/test_crosstab.py b/pandas/tests/reshape/test_crosstab.py index 8795af2e11122..4c00b5660577b 100644 --- a/pandas/tests/reshape/test_crosstab.py +++ b/pandas/tests/reshape/test_crosstab.py @@ -231,7 +231,7 @@ def test_crosstab_no_overlap(self): s2 = Series([4, 5, 6], index=[4, 5, 6]) actual = crosstab(s1, s2) - expected = DataFrame() + expected = empty_frame() tm.assert_frame_equal(actual, expected) diff --git a/pandas/tests/test_strings.py b/pandas/tests/test_strings.py index 6289c2efea7f1..410cbd64f968d 100644 --- a/pandas/tests/test_strings.py +++ b/pandas/tests/test_strings.py @@ -1928,7 +1928,7 @@ def test_empty_str_methods(self): def test_empty_str_methods_to_frame(self): empty = Series(dtype=str) - empty_df = DataFrame() + empty_df = empty_frame() tm.assert_frame_equal(empty_df, empty.str.partition("a")) tm.assert_frame_equal(empty_df, empty.str.rpartition("a")) diff --git a/pandas/tests/util/test_hashing.py b/pandas/tests/util/test_hashing.py index 6411b9ab654f1..add40cb36036f 100644 --- a/pandas/tests/util/test_hashing.py +++ b/pandas/tests/util/test_hashing.py @@ -194,7 +194,7 @@ def test_multiindex_objects(): Index([1, 2, 3]), Index([True, False, True]), DataFrame({"x": ["a", "b", "c"], "y": [1, 2, 3]}), - DataFrame(), + empty_frame(), tm.makeMissingDataframe(), tm.makeMixedDataFrame(), tm.makeTimeDataFrame(), diff --git a/pandas/tests/window/common.py b/pandas/tests/window/common.py index 6aeada3152dbb..4850091c822ab 100644 --- a/pandas/tests/window/common.py +++ b/pandas/tests/window/common.py @@ -148,7 +148,7 @@ def create_series(): def create_dataframes(): return [ - DataFrame(), + empty_frame(), DataFrame(columns=["a"]), DataFrame(columns=["a", "a"]), DataFrame(columns=["a", "b"]), diff --git a/pandas/tests/window/moments/test_moments_expanding.py b/pandas/tests/window/moments/test_moments_expanding.py index 9dfaecee9caeb..8ab05ed5a8098 100644 --- a/pandas/tests/window/moments/test_moments_expanding.py +++ b/pandas/tests/window/moments/test_moments_expanding.py @@ -287,7 +287,7 @@ def test_moment_functions_zero_length(self, f): # GH 8056 s = Series(dtype=np.float64) s_expected = s - df1 = DataFrame() + df1 = empty_frame() df1_expected = df1 df2 = DataFrame(columns=["a"]) df2["a"] = df2["a"].astype("float64") @@ -311,7 +311,7 @@ def test_moment_functions_zero_length(self, f): ) def test_moment_functions_zero_length_pairwise(self, f): - df1 = DataFrame() + df1 = empty_frame() df2 = DataFrame(columns=Index(["a"], name="foo"), index=Index([], name="bar")) df2["a"] = df2["a"].astype("float64") diff --git a/pandas/tests/window/moments/test_moments_rolling.py b/pandas/tests/window/moments/test_moments_rolling.py index f3a14971ef2e7..2a189be7a04cc 100644 --- a/pandas/tests/window/moments/test_moments_rolling.py +++ b/pandas/tests/window/moments/test_moments_rolling.py @@ -1454,7 +1454,7 @@ def test_moment_functions_zero_length(self): # GH 8056 s = Series(dtype=np.float64) s_expected = s - df1 = DataFrame() + df1 = empty_frame() df1_expected = df1 df2 = DataFrame(columns=["a"]) df2["a"] = df2["a"].astype("float64") @@ -1495,7 +1495,7 @@ def test_moment_functions_zero_length(self): def test_moment_functions_zero_length_pairwise(self): - df1 = DataFrame() + df1 = empty_frame() df2 = DataFrame(columns=Index(["a"], name="foo"), index=Index([], name="bar")) df2["a"] = df2["a"].astype("float64") diff --git a/pandas/tests/window/test_expanding.py b/pandas/tests/window/test_expanding.py index 6b6367fd80b26..5d0555c23fd07 100644 --- a/pandas/tests/window/test_expanding.py +++ b/pandas/tests/window/test_expanding.py @@ -67,8 +67,8 @@ def test_empty_df_expanding(self, expander): # GH 15819 Verifies that datetime and integer expanding windows can be # applied to empty DataFrames - expected = DataFrame() - result = DataFrame().expanding(expander).sum() + expected = empty_frame() + result = empty_frame().expanding(expander).sum() tm.assert_frame_equal(result, expected) # Verifies that datetime and integer expanding windows can be applied diff --git a/pandas/tests/window/test_rolling.py b/pandas/tests/window/test_rolling.py index ab2c7fcb7a0dc..2fb4a583ccd43 100644 --- a/pandas/tests/window/test_rolling.py +++ b/pandas/tests/window/test_rolling.py @@ -250,8 +250,8 @@ def test_closed_median_quantile(self, closed, expected): def tests_empty_df_rolling(self, roller): # GH 15819 Verifies that datetime and integer rolling windows can be # applied to empty DataFrames - expected = DataFrame() - result = DataFrame().rolling(roller).sum() + expected = empty_frame() + result = empty_frame().rolling(roller).sum() tm.assert_frame_equal(result, expected) # Verifies that datetime and integer rolling windows can be applied to