diff --git a/pandas/tests/frame/indexing/test_indexing.py b/pandas/tests/frame/indexing/test_indexing.py index 4fa5e4196ae5b..a7321104f2879 100644 --- a/pandas/tests/frame/indexing/test_indexing.py +++ b/pandas/tests/frame/indexing/test_indexing.py @@ -22,11 +22,13 @@ ) import pandas._testing as tm from pandas.arrays import SparseArray +from pandas.conftest import empty_frame import pandas.core.common as com from pandas.core.indexing import IndexingError from pandas.tseries.offsets import BDay + # We pass through a TypeError raised by numpy _slice_msg = "slice indices must be integers or None or have an __index__ method" @@ -842,7 +844,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 +1671,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..88fda6462a80f 100644 --- a/pandas/tests/frame/indexing/test_insert.py +++ b/pandas/tests/frame/indexing/test_insert.py @@ -8,6 +8,7 @@ from pandas import DataFrame, Index import pandas._testing as tm +from pandas.conftest import empty_frame class TestDataFrameInsert: @@ -58,7 +59,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..3d203774c31a6 100644 --- a/pandas/tests/frame/methods/test_append.py +++ b/pandas/tests/frame/methods/test_append.py @@ -4,12 +4,13 @@ import pandas as pd from pandas import DataFrame, Series, Timestamp import pandas._testing as tm +from pandas.conftest import empty_frame 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 +97,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 +131,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..e8db28c31e3dc 100644 --- a/pandas/tests/frame/methods/test_combine_first.py +++ b/pandas/tests/frame/methods/test_combine_first.py @@ -6,6 +6,7 @@ import pandas as pd from pandas import DataFrame, Index, Series import pandas._testing as tm +from pandas.conftest import empty_frame class TestDataFrameCombineFirst: @@ -73,7 +74,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..a3409e7fd8b8d 100644 --- a/pandas/tests/frame/methods/test_count.py +++ b/pandas/tests/frame/methods/test_count.py @@ -1,11 +1,12 @@ from pandas import DataFrame, Series import pandas._testing as tm +from pandas.conftest import empty_frame class TestDataFrameCount: def test_count(self): # corner case - frame = DataFrame() + frame = empty_frame() ct1 = frame.count(1) assert isinstance(ct1, Series) @@ -23,7 +24,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_filter.py b/pandas/tests/frame/methods/test_filter.py index 569b2fe21d1c2..9681fb7c17ce3 100644 --- a/pandas/tests/frame/methods/test_filter.py +++ b/pandas/tests/frame/methods/test_filter.py @@ -4,6 +4,7 @@ import pandas as pd from pandas import DataFrame import pandas._testing as tm +from pandas.conftest import empty_frame class TestDataFrameFilter: @@ -122,7 +123,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..e5bd7e5da3d74 100644 --- a/pandas/tests/frame/methods/test_head_tail.py +++ b/pandas/tests/frame/methods/test_head_tail.py @@ -1,7 +1,7 @@ import numpy as np -from pandas import DataFrame import pandas._testing as tm +from pandas.conftest import empty_frame def test_head_tail(float_frame): @@ -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..47a2b19939610 100644 --- a/pandas/tests/frame/methods/test_isin.py +++ b/pandas/tests/frame/methods/test_isin.py @@ -4,6 +4,7 @@ import pandas as pd from pandas import DataFrame, MultiIndex, Series import pandas._testing as tm +from pandas.conftest import empty_frame class TestDataFrameIsIn: @@ -176,7 +177,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..5889fe1e7288e 100644 --- a/pandas/tests/frame/methods/test_round.py +++ b/pandas/tests/frame/methods/test_round.py @@ -4,6 +4,7 @@ import pandas as pd from pandas import DataFrame, Series, date_range import pandas._testing as tm +from pandas.conftest import empty_frame class TestDataFrameRound: @@ -11,7 +12,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..5497330c7edd8 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -21,6 +21,7 @@ to_timedelta, ) import pandas._testing as tm +from pandas.conftest import empty_frame import pandas.core.algorithms as algorithms import pandas.core.nanops as nanops @@ -754,10 +755,10 @@ 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) + axis0 = empty_frame_.sum(0) + axis1 = empty_frame_.sum(1) assert isinstance(axis0, Series) assert isinstance(axis1, Series) assert len(axis0) == 0 diff --git a/pandas/tests/frame/test_api.py b/pandas/tests/frame/test_api.py index 91627b46c2fee..26fa238be0e13 100644 --- a/pandas/tests/frame/test_api.py +++ b/pandas/tests/frame/test_api.py @@ -11,6 +11,7 @@ import pandas as pd from pandas import Categorical, DataFrame, Series, compat, date_range, timedelta_range import pandas._testing as tm +from pandas.conftest import empty_frame class TestDataFrameMisc: @@ -118,14 +119,14 @@ 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" with pytest.raises(TypeError, match=msg): hash(df) with pytest.raises(TypeError, match=msg): - hash(empty_frame) + hash(empty_frame_) def test_column_name_contains_unicode_surrogate(self): # GH 25509 @@ -162,8 +163,8 @@ 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() - assert empty_frame.empty + empty_frame_ = empty_frame() + assert empty_frame_.empty assert not float_frame.empty assert not float_string_frame.empty diff --git a/pandas/tests/frame/test_apply.py b/pandas/tests/frame/test_apply.py index e328523253144..5709eb1c72a12 100644 --- a/pandas/tests/frame/test_apply.py +++ b/pandas/tests/frame/test_apply.py @@ -12,6 +12,7 @@ import pandas as pd from pandas import DataFrame, MultiIndex, Series, Timestamp, date_range, notna import pandas._testing as tm +from pandas.conftest import empty_frame from pandas.core.apply import frame_apply from pandas.core.base import SpecificationError @@ -74,12 +75,12 @@ 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) + applied = empty_frame_.apply(np.sqrt) assert applied.empty - applied = empty_frame.apply(np.mean) + applied = empty_frame_.apply(np.mean) assert applied.empty no_rows = float_frame[:0] @@ -99,7 +100,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 +761,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( diff --git a/pandas/tests/frame/test_arithmetic.py b/pandas/tests/frame/test_arithmetic.py index 89f8bc433419b..df0ce9a7f86cc 100644 --- a/pandas/tests/frame/test_arithmetic.py +++ b/pandas/tests/frame/test_arithmetic.py @@ -10,6 +10,7 @@ import pandas as pd from pandas import DataFrame, MultiIndex, Series import pandas._testing as tm +from pandas.conftest import empty_frame import pandas.core.common as com from pandas.tests.frame.common import _check_mixed_float, _check_mixed_int @@ -990,13 +991,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 +1117,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..efed9e5ded789 100644 --- a/pandas/tests/frame/test_block_internals.py +++ b/pandas/tests/frame/test_block_internals.py @@ -16,10 +16,12 @@ option_context, ) import pandas._testing as tm +from pandas.conftest import empty_frame from pandas.core.arrays import IntervalArray, integer_array from pandas.core.internals import ObjectBlock from pandas.core.internals.blocks import IntBlock + # Segregated collection of methods that require the BlockManager internal data # structure @@ -345,7 +347,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) @@ -354,7 +356,7 @@ def test_pickle(self, float_string_frame, timezone_frame): float_string_frame._data.ndim # empty - unpickled = tm.round_trip_pickle(empty_frame) + unpickled = tm.round_trip_pickle(empty_frame_) repr(unpickled) # tz frame diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index 9f40e8c6931c8..03a9ad2c57437 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -12,6 +12,7 @@ from pandas.compat import PY37, is_platform_little_endian from pandas.compat.numpy import _is_numpy_dev +from pandas.conftest import empty_frame from pandas.core.dtypes.common import is_integer_dtype @@ -78,7 +79,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 +1775,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..510fe30f1a665 100644 --- a/pandas/tests/frame/test_missing.py +++ b/pandas/tests/frame/test_missing.py @@ -7,6 +7,7 @@ import pandas as pd from pandas import Categorical, DataFrame, Series, Timestamp, date_range import pandas._testing as tm +from pandas.conftest import empty_frame from pandas.tests.frame.common import _check_mixed_float @@ -167,7 +168,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_reshape.py b/pandas/tests/frame/test_reshape.py index 9d3c40ce926d7..5bf3cf7906b10 100644 --- a/pandas/tests/frame/test_reshape.py +++ b/pandas/tests/frame/test_reshape.py @@ -7,6 +7,7 @@ import pandas as pd from pandas import DataFrame, Index, MultiIndex, Period, Series, Timedelta, date_range import pandas._testing as tm +from pandas.conftest import empty_frame class TestDataFrameReshape: @@ -53,7 +54,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..5c94c1440e2ae 100644 --- a/pandas/tests/groupby/aggregate/test_aggregate.py +++ b/pandas/tests/groupby/aggregate/test_aggregate.py @@ -11,6 +11,7 @@ import pandas as pd from pandas import DataFrame, Index, MultiIndex, Series, concat import pandas._testing as tm +from pandas.conftest import empty_frame from pandas.core.base import SpecificationError from pandas.core.groupby.grouper import Grouping @@ -223,7 +224,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..c69b4d0449fff 100644 --- a/pandas/tests/groupby/test_apply.py +++ b/pandas/tests/groupby/test_apply.py @@ -7,6 +7,7 @@ import pandas as pd from pandas import DataFrame, Index, MultiIndex, Series, bdate_range import pandas._testing as tm +from pandas.conftest import empty_frame def test_apply_issues(): @@ -658,7 +659,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..50883b525113d 100644 --- a/pandas/tests/groupby/test_counting.py +++ b/pandas/tests/groupby/test_counting.py @@ -5,6 +5,7 @@ from pandas import DataFrame, MultiIndex, Period, Series, Timedelta, Timestamp import pandas._testing as tm +from pandas.conftest import empty_frame class TestCounting: @@ -19,7 +20,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 +95,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/indexes/datetimes/test_datetime.py b/pandas/tests/indexes/datetimes/test_datetime.py index 1529a259c49af..2f0aea7de3772 100644 --- a/pandas/tests/indexes/datetimes/test_datetime.py +++ b/pandas/tests/indexes/datetimes/test_datetime.py @@ -7,6 +7,7 @@ import pandas as pd from pandas import DataFrame, DatetimeIndex, Index, NaT, Timestamp, date_range, offsets import pandas._testing as tm +from pandas.conftest import empty_frame randn = np.random.randn @@ -236,7 +237,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..59c0222691982 100644 --- a/pandas/tests/indexes/timedeltas/test_timedelta.py +++ b/pandas/tests/indexes/timedeltas/test_timedelta.py @@ -16,6 +16,7 @@ timedelta_range, ) import pandas._testing as tm +from pandas.conftest import empty_frame from ..datetimelike import DatetimeLike @@ -171,7 +172,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..d7c76305d325c 100644 --- a/pandas/tests/indexing/common.py +++ b/pandas/tests/indexing/common.py @@ -5,6 +5,7 @@ from pandas import DataFrame, Float64Index, MultiIndex, Series, UInt64Index, date_range import pandas._testing as tm +from pandas.conftest import empty_frame def _mklbl(prefix, n): @@ -89,7 +90,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..40c55b2371281 100644 --- a/pandas/tests/indexing/test_datetime.py +++ b/pandas/tests/indexing/test_datetime.py @@ -7,6 +7,7 @@ import pandas as pd from pandas import DataFrame, Index, Series, Timestamp, date_range import pandas._testing as tm +from pandas.conftest import empty_frame class TestDatetimeIndex: @@ -211,7 +212,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..37d97fab97700 100644 --- a/pandas/tests/indexing/test_indexing.py +++ b/pandas/tests/indexing/test_indexing.py @@ -12,6 +12,7 @@ import pandas as pd from pandas import DataFrame, Index, NaT, Series import pandas._testing as tm +from pandas.conftest import empty_frame from pandas.core.indexers import validate_indices from pandas.core.indexing import _maybe_numeric_slice, _non_reducing_slice from pandas.tests.indexing.common import _mklbl @@ -169,7 +170,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 +567,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..2386f6dcaccc2 100644 --- a/pandas/tests/indexing/test_partial.py +++ b/pandas/tests/indexing/test_partial.py @@ -10,6 +10,7 @@ import pandas as pd from pandas import DataFrame, Index, Series, date_range import pandas._testing as tm +from pandas.conftest import empty_frame class TestPartialSetting: @@ -373,7 +374,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 +398,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 +437,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/formats/test_style.py b/pandas/tests/io/formats/test_style.py index ec4614538004c..47e7079fdbbe6 100644 --- a/pandas/tests/io/formats/test_style.py +++ b/pandas/tests/io/formats/test_style.py @@ -12,6 +12,7 @@ import pandas._testing as tm jinja2 = pytest.importorskip("jinja2") +from pandas.conftest import empty_frame from pandas.io.formats.style import Styler, _get_level_lengths # noqa # isort:skip @@ -117,7 +118,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..551886281ca78 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -8,9 +8,10 @@ import pandas as pd from pandas import DataFrame, Index, MultiIndex, option_context import pandas._testing as tm - +from pandas.conftest import empty_frame import pandas.io.formats.format as fmt + lorem_ipsum = ( "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " @@ -391,7 +392,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 +440,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 +719,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..d1aaf9c3aa48f 100644 --- a/pandas/tests/io/formats/test_to_latex.py +++ b/pandas/tests/io/formats/test_to_latex.py @@ -6,6 +6,7 @@ import pandas as pd from pandas import DataFrame, Series import pandas._testing as tm +from pandas.conftest import empty_frame class TestToLatex: @@ -79,7 +80,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..ba37772540fb8 100644 --- a/pandas/tests/io/json/test_normalize.py +++ b/pandas/tests/io/json/test_normalize.py @@ -5,7 +5,7 @@ from pandas import DataFrame, Index, Series, json_normalize import pandas._testing as tm - +from pandas.conftest import empty_frame from pandas.io.json._normalize import nested_to_record @@ -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..c850ea28f77c3 100644 --- a/pandas/tests/io/parser/test_mangle_dupes.py +++ b/pandas/tests/io/parser/test_mangle_dupes.py @@ -9,6 +9,7 @@ from pandas import DataFrame import pandas._testing as tm +from pandas.conftest import empty_frame @pytest.mark.parametrize("kwargs", [dict(), dict(mangle_dupe_cols=True)]) @@ -121,7 +122,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..f05541ce4e0fb 100644 --- a/pandas/tests/io/parser/test_usecols.py +++ b/pandas/tests/io/parser/test_usecols.py @@ -11,6 +11,7 @@ from pandas import DataFrame, Index import pandas._testing as tm +from pandas.conftest import empty_frame _msg_validate_usecols_arg = ( "'usecols' must either be list-like " @@ -408,7 +409,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()) diff --git a/pandas/tests/io/pytables/test_store.py b/pandas/tests/io/pytables/test_store.py index 9a0788ea068ad..61c241d0984be 100644 --- a/pandas/tests/io/pytables/test_store.py +++ b/pandas/tests/io/pytables/test_store.py @@ -11,6 +11,7 @@ import pytest from pandas.compat import is_platform_little_endian, is_platform_windows +from pandas.conftest import empty_frame import pandas.util._test_decorators as td import pandas as pd @@ -2391,7 +2392,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..1913cdcb81c18 100644 --- a/pandas/tests/io/test_sql.py +++ b/pandas/tests/io/test_sql.py @@ -42,7 +42,7 @@ to_timedelta, ) import pandas._testing as tm - +from pandas.conftest import empty_frame import pandas.io.sql as sql from pandas.io.sql import read_sql_query, read_sql_table @@ -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..124b9980875e1 100644 --- a/pandas/tests/resample/test_base.py +++ b/pandas/tests/resample/test_base.py @@ -6,6 +6,7 @@ import pandas as pd from pandas import DataFrame, Series import pandas._testing as tm +from pandas.conftest import empty_frame from pandas.core.groupby.groupby import DataError from pandas.core.groupby.grouper import Grouper from pandas.core.indexes.datetimes import date_range @@ -83,7 +84,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..5c0222d0453c1 100644 --- a/pandas/tests/reshape/merge/test_join.py +++ b/pandas/tests/reshape/merge/test_join.py @@ -7,6 +7,7 @@ import pandas as pd from pandas import DataFrame, Index, MultiIndex, Series, concat, merge import pandas._testing as tm +from pandas.conftest import empty_frame from pandas.tests.reshape.merge.test_merge import NGROUPS, N, get_test_data a_ = np.array @@ -377,7 +378,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..59eb1261840ae 100644 --- a/pandas/tests/reshape/test_concat.py +++ b/pandas/tests/reshape/test_concat.py @@ -28,6 +28,7 @@ read_csv, ) import pandas._testing as tm +from pandas.conftest import empty_frame from pandas.core.arrays import SparseArray from pandas.core.construction import create_series_with_explicit_dtype from pandas.tests.extension.decimal import to_decimal @@ -796,7 +797,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 +1529,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..02d4af011af59 100644 --- a/pandas/tests/reshape/test_crosstab.py +++ b/pandas/tests/reshape/test_crosstab.py @@ -3,6 +3,7 @@ from pandas import CategoricalIndex, DataFrame, Index, MultiIndex, Series, crosstab import pandas._testing as tm +from pandas.conftest import empty_frame class TestCrosstab: @@ -231,7 +232,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..4d2a5eb3f3792 100644 --- a/pandas/tests/test_strings.py +++ b/pandas/tests/test_strings.py @@ -10,6 +10,7 @@ import pandas as pd from pandas import DataFrame, Index, MultiIndex, Series, concat, isna, notna import pandas._testing as tm +from pandas.conftest import empty_frame import pandas.core.strings as strings @@ -1928,7 +1929,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/window/moments/test_moments_expanding.py b/pandas/tests/window/moments/test_moments_expanding.py index 9dfaecee9caeb..eb4a8fae64360 100644 --- a/pandas/tests/window/moments/test_moments_expanding.py +++ b/pandas/tests/window/moments/test_moments_expanding.py @@ -6,6 +6,7 @@ from pandas import DataFrame, Index, MultiIndex, Series, isna, notna import pandas._testing as tm +from pandas.conftest import empty_frame from pandas.tests.window.common import ConsistencyBase @@ -287,7 +288,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 +312,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..89f9dc52fca98 100644 --- a/pandas/tests/window/moments/test_moments_rolling.py +++ b/pandas/tests/window/moments/test_moments_rolling.py @@ -11,6 +11,7 @@ import pandas as pd from pandas import DataFrame, Index, Series, isna, notna import pandas._testing as tm +from pandas.conftest import empty_frame from pandas.core.window.common import _flex_binary_moment from pandas.tests.window.common import Base, ConsistencyBase @@ -1454,7 +1455,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 +1496,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..60c614f75b4dd 100644 --- a/pandas/tests/window/test_expanding.py +++ b/pandas/tests/window/test_expanding.py @@ -6,6 +6,7 @@ import pandas as pd from pandas import DataFrame, Series import pandas._testing as tm +from pandas.conftest import empty_frame from pandas.core.window import Expanding from pandas.tests.window.common import Base @@ -67,8 +68,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..3e8c8c632c9cf 100644 --- a/pandas/tests/window/test_rolling.py +++ b/pandas/tests/window/test_rolling.py @@ -9,6 +9,7 @@ import pandas as pd from pandas import DataFrame, Index, Series import pandas._testing as tm +from pandas.conftest import empty_frame from pandas.core.window import Rolling from pandas.tests.window.common import Base @@ -250,8 +251,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