Skip to content

Commit f85f7a1

Browse files
jbrockmendeljreback
authored andcommitted
TST: inline empty_frame = DataFrame({}) fixture (#24886)
1 parent 705c442 commit f85f7a1

10 files changed

+26
-28
lines changed

pandas/tests/frame/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def tzframe(self):
8585

8686
@cache_readonly
8787
def empty(self):
88-
return pd.DataFrame({})
88+
return pd.DataFrame()
8989

9090
@cache_readonly
9191
def ts1(self):

pandas/tests/frame/conftest.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,6 @@ def timezone_frame():
127127
return df
128128

129129

130-
@pytest.fixture
131-
def empty_frame():
132-
"""
133-
Fixture for empty DataFrame
134-
"""
135-
return DataFrame({})
136-
137-
138130
@pytest.fixture
139131
def simple_frame():
140132
"""

pandas/tests/frame/test_analytics.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,9 @@ def test_operators_timedelta64(self):
10961096
assert df['off1'].dtype == 'timedelta64[ns]'
10971097
assert df['off2'].dtype == 'timedelta64[ns]'
10981098

1099-
def test_sum_corner(self, empty_frame):
1099+
def test_sum_corner(self):
1100+
empty_frame = DataFrame()
1101+
11001102
axis0 = empty_frame.sum(0)
11011103
axis1 = empty_frame.sum(1)
11021104
assert isinstance(axis0, Series)

pandas/tests/frame/test_api.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ def test_tab_completion(self):
142142
assert key not in dir(df)
143143
assert isinstance(df.__getitem__('A'), pd.DataFrame)
144144

145-
def test_not_hashable(self, empty_frame):
145+
def test_not_hashable(self):
146+
empty_frame = DataFrame()
147+
146148
df = self.klass([1])
147149
pytest.raises(TypeError, hash, df)
148150
pytest.raises(TypeError, hash, empty_frame)
@@ -171,7 +173,8 @@ def test_get_agg_axis(self, float_frame):
171173

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

174-
def test_nonzero(self, float_frame, float_string_frame, empty_frame):
176+
def test_nonzero(self, float_frame, float_string_frame):
177+
empty_frame = DataFrame()
175178
assert empty_frame.empty
176179

177180
assert not float_frame.empty

pandas/tests/frame/test_apply.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ def test_apply_mixed_datetimelike(self):
7474
result = df.apply(lambda x: x, axis=1)
7575
assert_frame_equal(result, df)
7676

77-
def test_apply_empty(self, float_frame, empty_frame):
77+
def test_apply_empty(self, float_frame):
7878
# empty
79+
empty_frame = DataFrame()
80+
7981
applied = empty_frame.apply(np.sqrt)
8082
assert applied.empty
8183

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

100-
def test_apply_with_reduce_empty(self, empty_frame):
102+
def test_apply_with_reduce_empty(self):
101103
# reduce with an empty DataFrame
104+
empty_frame = DataFrame()
105+
102106
x = []
103107
result = empty_frame.apply(x.append, axis=1, result_type='expand')
104108
assert_frame_equal(result, empty_frame)
@@ -116,7 +120,9 @@ def test_apply_with_reduce_empty(self, empty_frame):
116120
# Ensure that x.append hasn't been called
117121
assert x == []
118122

119-
def test_apply_deprecate_reduce(self, empty_frame):
123+
def test_apply_deprecate_reduce(self):
124+
empty_frame = DataFrame()
125+
120126
x = []
121127
with tm.assert_produces_warning(FutureWarning):
122128
empty_frame.apply(x.append, axis=1, reduce=True)

pandas/tests/frame/test_block_internals.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,9 @@ def test_copy(self, float_frame, float_string_frame):
347347
copy = float_string_frame.copy()
348348
assert copy._data is not float_string_frame._data
349349

350-
def test_pickle(self, float_string_frame, empty_frame, timezone_frame):
350+
def test_pickle(self, float_string_frame, timezone_frame):
351+
empty_frame = DataFrame()
352+
351353
unpickled = tm.round_trip_pickle(float_string_frame)
352354
assert_frame_equal(float_string_frame, unpickled)
353355

pandas/tests/frame/test_constructors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def test_constructor_dict(self):
247247
assert isna(frame['col3']).all()
248248

249249
# Corner cases
250-
assert len(DataFrame({})) == 0
250+
assert len(DataFrame()) == 0
251251

252252
# mix dict and array, wrong size - no spec for which error should raise
253253
# first

pandas/tests/frame/test_reshape.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_pivot_duplicates(self):
5858
def test_pivot_empty(self):
5959
df = DataFrame({}, columns=['a', 'b', 'c'])
6060
result = df.pivot('a', 'b', 'c')
61-
expected = DataFrame({})
61+
expected = DataFrame()
6262
tm.assert_frame_equal(result, expected, check_names=False)
6363

6464
def test_pivot_integer_bug(self):

pandas/tests/series/conftest.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import pytest
22

3-
from pandas import Series
43
import pandas.util.testing as tm
54

65

@@ -32,11 +31,3 @@ def object_series():
3231
s = tm.makeObjectSeries()
3332
s.name = 'objects'
3433
return s
35-
36-
37-
@pytest.fixture
38-
def empty_series():
39-
"""
40-
Fixture for empty Series
41-
"""
42-
return Series([], index=[])

pandas/tests/series/test_constructors.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ def test_scalar_conversion(self):
4747
assert int(Series([1.])) == 1
4848
assert long(Series([1.])) == 1
4949

50-
def test_constructor(self, datetime_series, empty_series):
50+
def test_constructor(self, datetime_series):
51+
empty_series = Series()
52+
5153
assert datetime_series.index.is_all_dates
5254

5355
# Pass in Series

0 commit comments

Comments
 (0)