Skip to content

TST: GH28813 test .diff() on Sparse dtype #34268

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
May 22, 2020
Merged

TST: GH28813 test .diff() on Sparse dtype #34268

merged 3 commits into from
May 22, 2020

Conversation

matteosantama
Copy link
Contributor

@matteosantama matteosantama commented May 20, 2020

  • closes Diff on sparse dtype #28813
  • tests added / passed
  • passes black pandas
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

Add a quick test to confirm that .diff() function handles sparse dataframes the same way as regular dataframes.

First time making a pandas PR so comments, advice, critiques are encouraged.

@@ -36,6 +36,14 @@ def test_diff(self, datetime_frame):
).astype("float64")
tm.assert_frame_equal(result, expected)

# Result should be the same for sparse df, see GH28813
Copy link
Member

Choose a reason for hiding this comment

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

Let's make a separate testing function for this test

normal = pd.DataFrame(arr)
sparse = pd.DataFrame(arr, dtype='Sparse[int]')
# we don't check dtype because one is sparse and the other isn't
tm.assert_frame_equal(normal.diff(), sparse.diff(), check_dtype=False)
Copy link
Member

Choose a reason for hiding this comment

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

Ideally we want to create the expected DataFrame with just the constructor:

result = sparse.diff()
expected = pd.DataFrame(...)
tm.assert_frame_equal(result, expected)

@mroeschke mroeschke added the Testing pandas testing functions or related to the test suite label May 20, 2020
@matteosantama
Copy link
Contributor Author

Gotcha ok. Updated the PR with your fixes

@mroeschke mroeschke added this to the 1.1 milestone May 21, 2020
@simonjayhawkins simonjayhawkins merged commit f26d3d5 into pandas-dev:master May 22, 2020
@simonjayhawkins
Copy link
Member

Thanks @matteosantama

@matteosantama matteosantama deleted the sparse_diff branch May 22, 2020 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Diff on sparse dtype
3 participants