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 all 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
45 changes: 45 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,48 @@ def test_diff_sparse(self):
)

tm.assert_frame_equal(result, expected)

@pytest.mark.parametrize(
"axis,expected",
[
(
0,
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",
),
),
(
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",
),
),
],
)
def test_diff_integer_na(self, axis, expected):
# 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 = df.diff(axis=axis)
tm.assert_frame_equal(result, expected)