Skip to content

TST add test for dtype consistency with pd replace #23305 #35234

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 10 commits into from
Jul 16, 2020

Conversation

mathurk1
Copy link
Contributor

@mathurk1 mathurk1 commented Jul 11, 2020

@pep8speaks
Copy link

pep8speaks commented Jul 11, 2020

Hello @mathurk1! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-07-14 03:48:26 UTC

@jreback jreback added the Categorical Categorical Data Type label Jul 13, 2020
@@ -1420,3 +1478,31 @@ def test_replace_period_ignore_float(self):
result = df.replace(1.0, 0.0)
expected = pd.DataFrame({"Per": [pd.Period("2020-01")] * 3})
tm.assert_frame_equal(expected, result)

def test_replace_value_category_type(self, input_category_df, expected_category_df):
Copy link
Contributor

Choose a reason for hiding this comment

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

i would just inline the source and expected frame as you are only using them inside this test

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

looks good some comments; ping on green

)

# replace values in input dataframe using a dict
input_df = input_df.replace({"a": "z", "obj1": "obj9", "cat1": "catX"})
Copy link
Contributor

Choose a reason for hiding this comment

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

can u call this result

# create expected dataframe
expected_dict = {"col1": ["z"], "col2": ["obj9"], "col3": ["catX"]}
# explicitly cast columns as category
expected_df = pd.DataFrame(data=expected_dict).astype(
Copy link
Contributor

Choose a reason for hiding this comment

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

can u call this expected

input_df = input_df.replace("obj1", "obj9")
input_df = input_df.replace("cat2", "catX")

tm.assert_frame_equal(input_df, expected_df)
Copy link
Contributor

Choose a reason for hiding this comment

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

similar to below
call this result and expected

@jreback jreback added this to the 1.1 milestone Jul 16, 2020
@jreback jreback added the Testing pandas testing functions or related to the test suite label Jul 16, 2020
@jreback jreback merged commit 88d81cc into pandas-dev:master Jul 16, 2020
@jreback
Copy link
Contributor

jreback commented Jul 16, 2020

thanks @mathurk1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Categorical Categorical Data Type Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Columns lose category dtype after calling replace on the dataframe
3 participants