-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
TST add test for dtype consistency with pd replace #23305 #35234
Conversation
@@ -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): |
There was a problem hiding this comment.
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
There was a problem hiding this 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"}) |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
thanks @mathurk1 |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff