Skip to content

CLN: Replace DataFrame() with empty_frame() in tests #33165

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

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 3 additions & 3 deletions pandas/tests/frame/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
],
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/indexing/test_insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions pandas/tests/frame/methods/test_append.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/methods/test_combine_first.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]))
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/frame/methods/test_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/methods/test_drop_duplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[]),
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/methods/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/methods/test_head_tail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion pandas/tests/frame/methods/test_isin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]})

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/methods/test_round.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/frame/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: []}),
Expand Down
10 changes: 5 additions & 5 deletions pandas/tests/frame/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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")),
Expand Down Expand Up @@ -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]]),
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/frame/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/test_block_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(()),
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/test_repr_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/test_reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/aggregate/test_aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/groupby/test_counting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/datetimes/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/timedeltas/test_timedelta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading