Skip to content

Add new test for None values on string columns on a Dataframe #52523

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 3 commits into from
Apr 10, 2023

Conversation

GrammatikakisDimitris
Copy link
Contributor

Although this issue seems to be gone, i noticed in the comments that a test for this would be appreciated, so this basically checks that Dataframe behaves as it should.

@@ -2698,6 +2698,14 @@ def test_frame_from_dict_with_mixed_tzaware_indexes(self):


class TestDataFrameConstructorWithDtypeCoercion:
def test_none_values_on_string_columns(self):
Copy link
Member

@mroeschke mroeschke Apr 7, 2023

Choose a reason for hiding this comment

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

Can you move this to pandas/tests/indexing/test_loc.py in the class TestLoc class?

@@ -2698,6 +2698,14 @@ def test_frame_from_dict_with_mixed_tzaware_indexes(self):


class TestDataFrameConstructorWithDtypeCoercion:
def test_none_values_on_string_columns(self):
# Creating DataFrame with column "a" as string and a None value
Copy link
Member

Choose a reason for hiding this comment

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

These comments are not needed. Instead could you add a comment with the github issue number?

df = DataFrame(data=data, dtype="str")

# Checking that the value of the third row in column "a" is actually None
assert isna(df.loc[2, "a"])
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assert isna(df.loc[2, "a"])
assert df.loc[2, "a"] is None

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Greetings @mroeschke, i made the changes as requested

@mroeschke mroeschke added Testing pandas testing functions or related to the test suite Indexing Related to indexing on series/frames, not to indexes themselves labels Apr 7, 2023
def test_none_values_on_string_columns(self):
# Issue #32218
data = {"a": ["1", "2", None]}
df = DataFrame(data=data, dtype="str")
Copy link
Member

Choose a reason for hiding this comment

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

From the issue df = pd.DataFrame(["1", "2", None], columns=["a"], dtype="str") should be the DataFrame being tested here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pre-commit check fails if i write pd.Dataframe, is it ok to write Dataframe instead?

Copy link
Member

Choose a reason for hiding this comment

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

Yes

@mroeschke mroeschke added this to the 2.1 milestone Apr 10, 2023
@mroeschke mroeschke merged commit 7321a46 into pandas-dev:main Apr 10, 2023
@mroeschke
Copy link
Member

Thanks @GrammatikakisDimitris

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants