Skip to content

Issue #33161 - Use empty_frame fixture #33177

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
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: 4 additions & 2 deletions pandas/tests/frame/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/frame/indexing/test_insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from pandas import DataFrame, Index
import pandas._testing as tm
from pandas.conftest import empty_frame


class TestDataFrameInsert:
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 8 additions & 7 deletions pandas/tests/frame/methods/test_append.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/frame/methods/test_combine_first.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"]))
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/frame/methods/test_count.py
Original file line number Diff line number Diff line change
@@ -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)

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

Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/frame/methods/test_round.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import pandas as pd
from pandas import DataFrame, Series, date_range
import pandas._testing as tm
from pandas.conftest import empty_frame


class TestDataFrameRound:
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
7 changes: 4 additions & 3 deletions pandas/tests/frame/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions pandas/tests/frame/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions pandas/tests/frame/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]
Expand All @@ -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")
Expand Down Expand Up @@ -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(
Expand Down
9 changes: 5 additions & 4 deletions pandas/tests/frame/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/frame/test_block_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
Loading