Skip to content

TST: IntegerNA Support for DataFrame.diff() #34889

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
Jun 20, 2020
Merged
Changes from 2 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
38 changes: 38 additions & 0 deletions pandas/tests/frame/methods/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,41 @@ def test_diff_sparse(self):
)

tm.assert_frame_equal(result, expected)

def test_diff_integer_na(self):
# GH#24171 IntegerNA Support for DataFrame.diff()
df = pd.DataFrame(
{
"a": np.repeat([0, 1, np.nan, 2], 2),
"b": np.tile([0, 1, np.nan, 2], 2),
"c": np.repeat(np.nan, 8),
"d": np.arange(1, 9) ** 2,
},
dtype="Int64",
)

# Test case for default behaviour of diff
result_default = df.diff()
Copy link
Contributor

Choose a reason for hiding this comment

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

hate to be pendantic about this, but can you use result & expected for both cases (the variable names)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Didn't want to overwrite the variable names here. Would you suggest to overwrite, or create a separate test function?

Copy link
Member

Choose a reason for hiding this comment

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

just overwriting the same names is fine 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.

I parameterized the test so overwriting is not necessary anymore.

Copy link
Member

Choose a reason for hiding this comment

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

I parameterized the test so overwriting is not necessary anymore.

Did you push these changes? Currently I can't see any parametrisation

expected_default = pd.DataFrame(
{
"a": [np.nan, 0, 1, 0, np.nan, np.nan, np.nan, 0],
"b": [np.nan, 1, np.nan, np.nan, -2, 1, np.nan, np.nan],
"c": np.repeat(np.nan, 8),
"d": [np.nan, 3, 5, 7, 9, 11, 13, 15],
},
dtype="Int64",
)
tm.assert_frame_equal(result_default, expected_default)

# Test case for behaviour with arg: axis=1
result_axis_1 = df.diff(axis=1)
expected_axis_1 = pd.DataFrame(
{
"a": np.repeat(np.nan, 8),
"b": [0, 1, np.nan, 1, np.nan, np.nan, np.nan, 0],
"c": np.repeat(np.nan, 8),
"d": np.repeat(np.nan, 8),
},
dtype="Int64",
)
tm.assert_frame_equal(result_axis_1, expected_axis_1)