Skip to content

Conversation

deepith-18
Copy link

This PR adds a new test to verify the behavior of DataFrame.select_dtypes when called on an empty DataFrame.

The test confirms that the function correctly returns an empty DataFrame with the original index, which is the expected behavior.

@deepith-18 deepith-18 force-pushed the test-select-dtypes-empty branch from 3e19eeb to 59712b5 Compare September 17, 2025 09:56
Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

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

Thanks @deepith-18 for the PR

CI is failing.

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?

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.

@simonjayhawkins
Copy link
Member

I'm new to the testing suite

in that case, maybe better to, in the first instance, have a go at addressing an open issue that is tagged Needs Tests and Good First Issue.

https://github.com/pandas-dev/pandas/issues?q=is%3Aissue%20state%3Aopen%20label%3A%22good%20first%20issue%22%20label%3A%22Needs%20Tests%22

I'll close this PR for now.

@deepith-18 deepith-18 deleted the test-select-dtypes-empty branch September 21, 2025 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants