Skip to content
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
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -11764,7 +11764,7 @@ def count(self, axis: Axis = 0, numeric_only: bool = False) -> Series:
axis : {0 or 'index', 1 or 'columns'}, default 0
If 0 or 'index' counts are generated for each column.
If 1 or 'columns' counts are generated for each row.
numeric_only : bool, default False
numeric_only : bool, default False.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be reverted?

Include only `float`, `int` or `boolean` data.

Returns
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/frame/methods/test_select_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,3 +483,10 @@ def test_select_dtypes_no_view(self):
result = df.select_dtypes(include=["number"])
result.iloc[0, 0] = 0
tm.assert_frame_equal(df, df_orig)

def test_select_dtypes_empty_frame():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please explain why this test is needed. I assume you have identified a gap in the testing, perhaps using code coverage tools or found an reported issue on the pandas issue tracker which is fixed on main and labelled Needs Tests to prevent regression?

A separate test is usually added at the end of the file when adding a regression test with a link to a known issue.

For general testing, the input dataframe could be added to the parameterisation used in the existing tests.

Or if having a dedicated test for an empty DataFrame, we would probably also want to test more than just the str type representation of a single dtype to include. For full coverage, we would want to test more dtypes, list like of dtypes and the same for the exclude parameter?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed review and guidance, @simonjayhawkins! I will revert the change in frame.py.

My apologies for adding a separate test function. I'm new to the testing suite and your suggestion to add the empty DataFrame to the existing parameterized tests makes a lot of sense. I will work on that now.

# Test that select_dtypes works on a completely empty DataFrame
df = DataFrame()
result = df.select_dtypes(include="int64")
expected = DataFrame()
tm.assert_frame_equal(result, expected)
Loading