-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Fix read_json category dtype #30728
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import pytest | ||
|
||
from pandas.compat import is_platform_32bit, is_platform_windows | ||
from pandas.core.dtypes.common import is_categorical | ||
import pandas.util._test_decorators as td | ||
|
||
import pandas as pd | ||
|
@@ -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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know about |
||
json = ( | ||
'{"a": 0, "b": "A"}\n' | ||
'{"a": 1, "b": "B"}\n' | ||
'{"a": 2, "b": "A"}\n' | ||
'{"a": 3, "b": "B"}\n' | ||
) | ||
json = StringIO(json) | ||
result = read_json(json, lines=True, dtype={"b": "category"}) | ||
assert is_categorical(result["b"]) | ||
|
||
def test_read_jsonl_unicode_chars(self): | ||
# GH15132: non-ascii unicode characters | ||
# \u201d == RIGHT DOUBLE QUOTATION MARK | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use pandas_dtype here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
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
andpandas_dtype
here; just the latter should be OK