Skip to content

Create helper function in pandas/tests/io/json/test_pandas.py #28555

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

Closed
WillAyd opened this issue Sep 21, 2019 · 6 comments · Fixed by #28626
Closed

Create helper function in pandas/tests/io/json/test_pandas.py #28555

WillAyd opened this issue Sep 21, 2019 · 6 comments · Fixed by #28626
Labels
good first issue IO JSON read_json, to_json, json_normalize Testing pandas testing functions or related to the test suite

Comments

@WillAyd
Copy link
Member

WillAyd commented Sep 21, 2019

A lot of the tests in that module repeat the following pattern:

if orient == "records" or orient == "values":
    expected = expected.reset_index(drop=True)
if orient == "values":
    expected.columns = range(len(expected.columns))

assert_frame_equal(result, expected)

This is because the records and values formats intentionally do not completely preserve the axes labels. It would be nice to refactor this into a dedicated helper function (assert_json_roundtrip_equal?)

@WillAyd WillAyd added good first issue IO JSON read_json, to_json, json_normalize Testing pandas testing functions or related to the test suite labels Sep 21, 2019
@WillAyd WillAyd added this to the Contributions Welcome milestone Sep 21, 2019
@bganglia
Copy link
Contributor

I am pretty new to Github but this sounds like something I can do.

First, let me check: Is this the kind of method you are looking for?

def assert_json_roundtrip_equal(self, result, expected, orient):
    if orient == "records" or orient == "values":
        expected = expected.reset_index(drop=True)
    if orient == "values":
        expected.columns = range(len(expected.columns))
    assert_frame_equal(result, expected)

Or should the function create "result" and "expected" from a passed dataframe?

@WillAyd
Copy link
Member Author

WillAyd commented Sep 22, 2019

@bganglia that looks good. Probably can just make at module level instead of class so no need for self. Want to make a PR?

@amcnulty93
Copy link

@bganglia @WillAyd I would like to contribute if help is needed. I am also looking to start contributing to open source but don't want to have a "too many chefs" situation.

@bganglia
Copy link
Contributor

@WillAyd Thank you. I will put the code at the module level instead.

@amcnulty93 We are both in the same boat, so there is probably a way that we can work on it together.
The task isn't very big, but I think we can split it up this way:
I just added the function definition to my fork. Maybe now you can fork my version, add the function calls to it, and submit a pull request to me. Then, I will accept your pull request and submit a pull request with both of our changes to the original repository. What do you think?

@WillAyd
Copy link
Member Author

WillAyd commented Sep 23, 2019

@bganglia if you already have a PR probably easiest to just push that against master here. This is a fairly simple change so don't want to overcomplicate things

@amcnulty93 great that you want to contribute! There are a ton of other good first issue labeled issues you might find interest in, particularly for the JSON stuff if that's an area of interest

@amcnulty93
Copy link

@bganglia I see you've taken care of everything :) No worries. I'll look to tackle other issues.

@WillAyd I'll look into other good first issue labels. I'm sure there's something I can help with there. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue IO JSON read_json, to_json, json_normalize Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants