Skip to content

TST: Test empty method and simplify logic #15043

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

Merged
merged 1 commit into from
Jan 4, 2017
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/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ def empty(self):
pandas.Series.dropna
pandas.DataFrame.dropna
"""
return not all(len(self._get_axis(a)) > 0 for a in self._AXIS_ORDERS)
return any(len(self._get_axis(a)) == 0 for a in self._AXIS_ORDERS)

def __nonzero__(self):
raise ValueError("The truth value of a {0} is ambiguous. "
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/frame/test_misc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,18 @@ def test_series_put_names(self):
def test_empty_nonzero(self):
df = DataFrame([1, 2, 3])
self.assertFalse(df.empty)
df = pd.DataFrame(index=[1], columns=[1])
self.assertFalse(df.empty)
df = DataFrame(index=['a', 'b'], columns=['c', 'd']).dropna()
self.assertTrue(df.empty)
self.assertTrue(df.T.empty)
empty_frames = [pd.DataFrame(),
pd.DataFrame(index=[1]),
pd.DataFrame(columns=[1]),
pd.DataFrame({1: []})]
for df in empty_frames:
self.assertTrue(df.empty)
self.assertTrue(df.T.empty)

def test_inplace_return_self(self):
# re #1893
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/series/test_misc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,10 @@ def test_str_attribute(self):
s = Series(range(5))
with self.assertRaisesRegexp(AttributeError, 'only use .str accessor'):
s.str.repeat(2)

def test_empty_method(self):
s_empty = pd.Series()
tm.assert_equal(s_empty.empty, True)

for full_series in [pd.Series([1]), pd.Series(index=[1])]:
tm.assert_equal(full_series.empty, False)