Skip to content

Fix read_json category dtype #30728

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

Conversation

taoufik07
Copy link

@pep8speaks
Copy link

pep8speaks commented Jan 6, 2020

Hello @taoufik07! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-01-06 12:30:52 UTC

@taoufik07 taoufik07 force-pushed the fix-read-json-category-dtype branch from 55b101f to 8de37e9 Compare January 6, 2020 10:49
@@ -892,7 +892,8 @@ def _try_convert_data(self, name, data, use_dtypes=True, convert_dates=True):
)
if dtype is not None:
try:
dtype = np.dtype(dtype)
if not is_categorical_dtype(dtype):
Copy link
Contributor

Choose a reason for hiding this comment

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

use pandas_dtype here

Copy link
Author

Choose a reason for hiding this comment

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

done

Copy link
Member

Choose a reason for hiding this comment

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

I don't think you need both the is_categorical_dtype and pandas_dtype here; just the latter should be OK

@jreback jreback added the IO JSON read_json, to_json, json_normalize label Jan 6, 2020
@@ -1197,6 +1198,17 @@ def test_read_local_jsonl(self):
expected = DataFrame([[1, 2], [1, 2]], columns=["a", "b"])
tm.assert_frame_equal(result, expected)

def test_read_json_category_dtype(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

this will need to test all extension dtypes that we support, pls parametrize this over interval, period, categorical, datetime w/tz

Copy link
Author

Choose a reason for hiding this comment

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

Hey, according to you, what's the best way to deal/pass different input dfs and expected dfs ?

Copy link
Member

Choose a reason for hiding this comment

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

@taoufik07 have a go using https://docs.pytest.org/en/latest/parametrize.html, there's lots of examples of it being used it other parts of the test suite

Copy link
Author

Choose a reason for hiding this comment

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

I know about parametrize, but I find having multiple lines (type, input, expected) unpleasant to the eye and I tought that there was some magic function that handles the data generations for all these types, maybe I will just go with the naive way

@MarcoGorelli
Copy link
Member

Hi @taoufik07 - sorry to chase you up, just wanted to ask whether you're still working on this :)

@taoufik07
Copy link
Author

Hey @MarcoGorelli, sorry I'm kinda busy right now, yes I would love to keep working on this, I'll try finish the tests in the couple days

@MarcoGorelli
Copy link
Member

Thanks - no hurry, just checking it's not gone stale

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

@taoufik07 is this still active?

@@ -892,7 +892,8 @@ def _try_convert_data(self, name, data, use_dtypes=True, convert_dates=True):
)
if dtype is not None:
try:
dtype = np.dtype(dtype)
if not is_categorical_dtype(dtype):
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you need both the is_categorical_dtype and pandas_dtype here; just the latter should be OK

@simonjayhawkins
Copy link
Member

@taoufik07 closing as stale. ping if you want to continue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO JSON read_json, to_json, json_normalize
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pd.read_json ignores 'category' dtypes
6 participants