From 374d1ad00820e429362e1c9ba9c78ed84416e3dd Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Wed, 23 Jan 2019 09:33:26 -0800 Subject: [PATCH 1/3] inline empty_frame --- pandas/tests/frame/conftest.py | 8 -------- pandas/tests/frame/test_analytics.py | 4 +++- pandas/tests/frame/test_api.py | 7 +++++-- pandas/tests/frame/test_apply.py | 12 +++++++++--- pandas/tests/frame/test_block_internals.py | 4 +++- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/pandas/tests/frame/conftest.py b/pandas/tests/frame/conftest.py index 377e737a53158..2d779483bf0f7 100644 --- a/pandas/tests/frame/conftest.py +++ b/pandas/tests/frame/conftest.py @@ -165,14 +165,6 @@ def timezone_frame(): return df -@pytest.fixture -def empty_frame(): - """ - Fixture for empty DataFrame - """ - return DataFrame({}) - - @pytest.fixture def datetime_series(): """ diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index f2c3f50c291c3..1a5ffea2f593f 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -1199,7 +1199,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) diff --git a/pandas/tests/frame/test_api.py b/pandas/tests/frame/test_api.py index 0934dd20638e4..4f52023fa70d4 100644 --- a/pandas/tests/frame/test_api.py +++ b/pandas/tests/frame/test_api.py @@ -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) @@ -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 diff --git a/pandas/tests/frame/test_apply.py b/pandas/tests/frame/test_apply.py index ade527a16c902..778f2e77e4f5a 100644 --- a/pandas/tests/frame/test_apply.py +++ b/pandas/tests/frame/test_apply.py @@ -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 @@ -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) @@ -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) diff --git a/pandas/tests/frame/test_block_internals.py b/pandas/tests/frame/test_block_internals.py index 5419f4d5127f6..f586c9ece13d8 100644 --- a/pandas/tests/frame/test_block_internals.py +++ b/pandas/tests/frame/test_block_internals.py @@ -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) From cfc26995eeaf49205fc036ad013906693f5355e4 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Wed, 23 Jan 2019 09:34:50 -0800 Subject: [PATCH 2/3] inline empty_series --- pandas/tests/series/conftest.py | 9 --------- pandas/tests/series/test_constructors.py | 4 +++- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/pandas/tests/series/conftest.py b/pandas/tests/series/conftest.py index 431aacb1c8d56..367e7a1baa7f3 100644 --- a/pandas/tests/series/conftest.py +++ b/pandas/tests/series/conftest.py @@ -1,6 +1,5 @@ import pytest -from pandas import Series import pandas.util.testing as tm @@ -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=[]) diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index d92ca48751d0a..952b5e0e6da95 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -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([], index=[]) + assert datetime_series.index.is_all_dates # Pass in Series From 6dd212057bf21da6b9f186ae30dae8ae6ad8682a Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Sun, 3 Mar 2019 08:57:51 -0800 Subject: [PATCH 3/3] remove empty list/dict --- pandas/tests/frame/common.py | 2 +- pandas/tests/frame/test_analytics.py | 2 +- pandas/tests/frame/test_api.py | 4 ++-- pandas/tests/frame/test_apply.py | 6 +++--- pandas/tests/frame/test_block_internals.py | 2 +- pandas/tests/frame/test_constructors.py | 2 +- pandas/tests/frame/test_reshape.py | 2 +- pandas/tests/series/test_constructors.py | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pandas/tests/frame/common.py b/pandas/tests/frame/common.py index 2ea087c0510bf..5624f7c1303b6 100644 --- a/pandas/tests/frame/common.py +++ b/pandas/tests/frame/common.py @@ -85,7 +85,7 @@ def tzframe(self): @cache_readonly def empty(self): - return pd.DataFrame({}) + return pd.DataFrame() @cache_readonly def ts1(self): diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index 3fe3a59df5d63..994187a62d862 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -1097,7 +1097,7 @@ def test_operators_timedelta64(self): assert df['off2'].dtype == 'timedelta64[ns]' def test_sum_corner(self): - empty_frame = DataFrame({}) + empty_frame = DataFrame() axis0 = empty_frame.sum(0) axis1 = empty_frame.sum(1) diff --git a/pandas/tests/frame/test_api.py b/pandas/tests/frame/test_api.py index 4f52023fa70d4..e561b327e4fb0 100644 --- a/pandas/tests/frame/test_api.py +++ b/pandas/tests/frame/test_api.py @@ -143,7 +143,7 @@ def test_tab_completion(self): assert isinstance(df.__getitem__('A'), pd.DataFrame) def test_not_hashable(self): - empty_frame = DataFrame({}) + empty_frame = DataFrame() df = self.klass([1]) pytest.raises(TypeError, hash, df) @@ -174,7 +174,7 @@ 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 = DataFrame({}) + empty_frame = DataFrame() assert empty_frame.empty assert not float_frame.empty diff --git a/pandas/tests/frame/test_apply.py b/pandas/tests/frame/test_apply.py index d4f26e7923db2..4d1e3e7ae1f38 100644 --- a/pandas/tests/frame/test_apply.py +++ b/pandas/tests/frame/test_apply.py @@ -76,7 +76,7 @@ def test_apply_mixed_datetimelike(self): def test_apply_empty(self, float_frame): # empty - empty_frame = DataFrame({}) + empty_frame = DataFrame() applied = empty_frame.apply(np.sqrt) assert applied.empty @@ -101,7 +101,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 = DataFrame() x = [] result = empty_frame.apply(x.append, axis=1, result_type='expand') @@ -121,7 +121,7 @@ def test_apply_with_reduce_empty(self): assert x == [] def test_apply_deprecate_reduce(self): - empty_frame = DataFrame({}) + empty_frame = DataFrame() x = [] with tm.assert_produces_warning(FutureWarning): diff --git a/pandas/tests/frame/test_block_internals.py b/pandas/tests/frame/test_block_internals.py index f586c9ece13d8..39d84f2e6086c 100644 --- a/pandas/tests/frame/test_block_internals.py +++ b/pandas/tests/frame/test_block_internals.py @@ -348,7 +348,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 = DataFrame() unpickled = tm.round_trip_pickle(float_string_frame) assert_frame_equal(float_string_frame, unpickled) diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index a8a78b26e317c..b32255da324f4 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -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 diff --git a/pandas/tests/frame/test_reshape.py b/pandas/tests/frame/test_reshape.py index daac084f657af..4fe5172fefbcd 100644 --- a/pandas/tests/frame/test_reshape.py +++ b/pandas/tests/frame/test_reshape.py @@ -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): diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index 952b5e0e6da95..8525b877618c9 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -48,7 +48,7 @@ def test_scalar_conversion(self): assert long(Series([1.])) == 1 def test_constructor(self, datetime_series): - empty_series = Series([], index=[]) + empty_series = Series() assert datetime_series.index.is_all_dates