Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions pandas/io/json/_table_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ def as_json_table_type(x: DtypeObj) -> str:
return "datetime"
elif lib.is_np_dtype(x, "m"):
return "duration"
elif isinstance(x, ExtensionDtype):
return "any"
elif is_string_dtype(x):
return "string"
elif isinstance(x, ExtensionDtype):
return "any"
else:
return "any"

Expand Down Expand Up @@ -197,7 +197,7 @@ def convert_json_field_to_pandas_type(field) -> str | CategoricalDtype:
"""
typ = field["type"]
if typ == "string":
return "object"
return field.get("extDtype", "object")
elif typ == "integer":
return field.get("extDtype", "int64")
elif typ == "number":
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/io/json/test_json_table_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_build_table_schema(self, df_schema, using_infer_string):
"primaryKey": ["idx"],
}
if using_infer_string:
expected["fields"][2] = {"name": "B", "type": "any", "extDtype": "str"}
expected["fields"][2] = {"name": "B", "type": "string", "extDtype": "str"}
assert result == expected
result = build_table_schema(df_schema)
assert "pandas_version" in result
Expand Down Expand Up @@ -120,10 +120,10 @@ def test_multiindex(self, df_schema, using_infer_string):
if using_infer_string:
expected["fields"][0] = {
"name": "level_0",
"type": "any",
"type": "string",
"extDtype": "str",
}
expected["fields"][3] = {"name": "B", "type": "any", "extDtype": "str"}
expected["fields"][3] = {"name": "B", "type": "string", "extDtype": "str"}
assert result == expected

df.index.names = ["idx0", None]
Expand Down Expand Up @@ -303,7 +303,7 @@ def test_to_json(self, df_table, using_infer_string):
]

if using_infer_string:
fields[2] = {"name": "B", "type": "any", "extDtype": "str"}
fields[2] = {"name": "B", "type": "string", "extDtype": "str"}

schema = {"fields": fields, "primaryKey": ["idx"]}
data = [
Expand Down
10 changes: 5 additions & 5 deletions pandas/tests/io/json/test_json_table_schema_ext_dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_build_table_schema(self):
{"name": "index", "type": "integer"},
{"name": "A", "type": "any", "extDtype": "DateDtype"},
{"name": "B", "type": "number", "extDtype": "decimal"},
{"name": "C", "type": "any", "extDtype": "string"},
{"name": "C", "type": "string", "extDtype": "string"},
{"name": "D", "type": "integer", "extDtype": "Int64"},
],
"primaryKey": ["index"],
Expand Down Expand Up @@ -80,10 +80,10 @@ def test_as_json_table_type_ext_decimal_dtype(self):
@pytest.mark.parametrize("box", [lambda x: x, Series])
def test_as_json_table_type_ext_string_array_dtype(self, box):
string_data = box(array(["pandas"], dtype="string"))
assert as_json_table_type(string_data.dtype) == "any"
assert as_json_table_type(string_data.dtype) == "string"

def test_as_json_table_type_ext_string_dtype(self):
assert as_json_table_type(StringDtype()) == "any"
assert as_json_table_type(StringDtype()) == "string"

@pytest.mark.parametrize("box", [lambda x: x, Series])
def test_as_json_table_type_ext_integer_array_dtype(self, box):
Expand Down Expand Up @@ -176,7 +176,7 @@ def test_build_string_series(self, sa):

fields = [
{"name": "id", "type": "integer"},
{"name": "a", "type": "any", "extDtype": "string"},
{"name": "a", "type": "string", "extDtype": "string"},
]

schema = {"fields": fields, "primaryKey": ["id"]}
Expand Down Expand Up @@ -235,7 +235,7 @@ def test_to_json(self, da, dc, sa, ia):
OrderedDict({"name": "idx", "type": "integer"}),
OrderedDict({"name": "A", "type": "any", "extDtype": "DateDtype"}),
OrderedDict({"name": "B", "type": "number", "extDtype": "decimal"}),
OrderedDict({"name": "C", "type": "any", "extDtype": "string"}),
OrderedDict({"name": "C", "type": "string", "extDtype": "string"}),
OrderedDict({"name": "D", "type": "integer", "extDtype": "Int64"}),
]

Expand Down
Loading