Skip to content
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

TST: inline empty_frame = DataFrame({}) fixture #24886

Merged
merged 5 commits into from
Mar 4, 2019
Merged
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
2 changes: 1 addition & 1 deletion pandas/tests/frame/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def tzframe(self):

@cache_readonly
def empty(self):
return pd.DataFrame({})
return pd.DataFrame()

@cache_readonly
def ts1(self):
Expand Down
8 changes: 0 additions & 8 deletions pandas/tests/frame/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,6 @@ def timezone_frame():
return df


@pytest.fixture
def empty_frame():
"""
Fixture for empty DataFrame
"""
return DataFrame({})


@pytest.fixture
def simple_frame():
"""
Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/frame/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,9 @@ def test_operators_timedelta64(self):
assert df['off1'].dtype == 'timedelta64[ns]'
assert df['off2'].dtype == 'timedelta64[ns]'

def test_sum_corner(self, empty_frame):
def test_sum_corner(self):
empty_frame = DataFrame()

axis0 = empty_frame.sum(0)
axis1 = empty_frame.sum(1)
assert isinstance(axis0, Series)
Expand Down
7 changes: 5 additions & 2 deletions pandas/tests/frame/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ def test_tab_completion(self):
assert key not in dir(df)
assert isinstance(df.__getitem__('A'), pd.DataFrame)

def test_not_hashable(self, empty_frame):
def test_not_hashable(self):
empty_frame = DataFrame()

df = self.klass([1])
pytest.raises(TypeError, hash, df)
pytest.raises(TypeError, hash, empty_frame)
Expand Down Expand Up @@ -171,7 +173,8 @@ def test_get_agg_axis(self, float_frame):

pytest.raises(ValueError, float_frame._get_agg_axis, 2)

def test_nonzero(self, float_frame, float_string_frame, empty_frame):
def test_nonzero(self, float_frame, float_string_frame):
empty_frame = DataFrame()
assert empty_frame.empty

assert not float_frame.empty
Expand Down
12 changes: 9 additions & 3 deletions pandas/tests/frame/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ def test_apply_mixed_datetimelike(self):
result = df.apply(lambda x: x, axis=1)
assert_frame_equal(result, df)

def test_apply_empty(self, float_frame, empty_frame):
def test_apply_empty(self, float_frame):
# empty
empty_frame = DataFrame()

applied = empty_frame.apply(np.sqrt)
assert applied.empty

Expand All @@ -97,8 +99,10 @@ def test_apply_empty(self, float_frame, empty_frame):
result = expected.apply(lambda x: x['a'], axis=1)
assert_frame_equal(expected, result)

def test_apply_with_reduce_empty(self, empty_frame):
def test_apply_with_reduce_empty(self):
# reduce with an empty DataFrame
empty_frame = DataFrame()

x = []
result = empty_frame.apply(x.append, axis=1, result_type='expand')
assert_frame_equal(result, empty_frame)
Expand All @@ -116,7 +120,9 @@ def test_apply_with_reduce_empty(self, empty_frame):
# Ensure that x.append hasn't been called
assert x == []

def test_apply_deprecate_reduce(self, empty_frame):
def test_apply_deprecate_reduce(self):
empty_frame = DataFrame()

x = []
with tm.assert_produces_warning(FutureWarning):
empty_frame.apply(x.append, axis=1, reduce=True)
Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/frame/test_block_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,9 @@ def test_copy(self, float_frame, float_string_frame):
copy = float_string_frame.copy()
assert copy._data is not float_string_frame._data

def test_pickle(self, float_string_frame, empty_frame, timezone_frame):
def test_pickle(self, float_string_frame, timezone_frame):
empty_frame = DataFrame()

unpickled = tm.round_trip_pickle(float_string_frame)
assert_frame_equal(float_string_frame, unpickled)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def test_constructor_dict(self):
assert isna(frame['col3']).all()

# Corner cases
assert len(DataFrame({})) == 0
assert len(DataFrame()) == 0

# mix dict and array, wrong size - no spec for which error should raise
# first
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 @@ -58,7 +58,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 = DataFrame()
tm.assert_frame_equal(result, expected, check_names=False)

def test_pivot_integer_bug(self):
Expand Down
9 changes: 0 additions & 9 deletions pandas/tests/series/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest

from pandas import Series
import pandas.util.testing as tm


Expand Down Expand Up @@ -32,11 +31,3 @@ def object_series():
s = tm.makeObjectSeries()
s.name = 'objects'
return s


@pytest.fixture
def empty_series():
"""
Fixture for empty Series
"""
return Series([], index=[])
4 changes: 3 additions & 1 deletion pandas/tests/series/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def test_scalar_conversion(self):
assert int(Series([1.])) == 1
assert long(Series([1.])) == 1

def test_constructor(self, datetime_series, empty_series):
def test_constructor(self, datetime_series):
empty_series = Series()

assert datetime_series.index.is_all_dates

# Pass in Series
Expand Down