Skip to content

Commit e0dd81a

Browse files
authored
CLN: json_table_schema remove unused arg, annotate (#33375)
1 parent b8f30ca commit e0dd81a

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

pandas/io/json/_table_schema.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import warnings
77

88
import pandas._libs.json as json
9+
from pandas._typing import DtypeObj
910

1011
from pandas.core.dtypes.common import (
1112
is_bool_dtype,
@@ -26,17 +27,17 @@
2627
loads = json.loads
2728

2829

29-
def as_json_table_type(x):
30+
def as_json_table_type(x: DtypeObj) -> str:
3031
"""
3132
Convert a NumPy / pandas type to its corresponding json_table.
3233
3334
Parameters
3435
----------
35-
x : array or dtype
36+
x : np.dtype or ExtensionDtype
3637
3738
Returns
3839
-------
39-
t : str
40+
str
4041
the Table Schema data types
4142
4243
Notes
@@ -96,8 +97,8 @@ def set_default_names(data):
9697
return data
9798

9899

99-
def convert_pandas_type_to_json_field(arr, dtype=None):
100-
dtype = dtype or arr.dtype
100+
def convert_pandas_type_to_json_field(arr):
101+
dtype = arr.dtype
101102
if arr.name is None:
102103
name = "values"
103104
else:

pandas/tests/io/json/test_json_table_schema.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,23 @@ class TestTableSchemaType:
103103
@pytest.mark.parametrize("int_type", [np.int, np.int16, np.int32, np.int64])
104104
def test_as_json_table_type_int_data(self, int_type):
105105
int_data = [1, 2, 3]
106-
assert as_json_table_type(np.array(int_data, dtype=int_type)) == "integer"
106+
assert as_json_table_type(np.array(int_data, dtype=int_type).dtype) == "integer"
107107

108108
@pytest.mark.parametrize(
109109
"float_type", [np.float, np.float16, np.float32, np.float64]
110110
)
111111
def test_as_json_table_type_float_data(self, float_type):
112112
float_data = [1.0, 2.0, 3.0]
113-
assert as_json_table_type(np.array(float_data, dtype=float_type)) == "number"
113+
assert (
114+
as_json_table_type(np.array(float_data, dtype=float_type).dtype) == "number"
115+
)
114116

115117
@pytest.mark.parametrize("bool_type", [bool, np.bool])
116118
def test_as_json_table_type_bool_data(self, bool_type):
117119
bool_data = [True, False]
118-
assert as_json_table_type(np.array(bool_data, dtype=bool_type)) == "boolean"
120+
assert (
121+
as_json_table_type(np.array(bool_data, dtype=bool_type).dtype) == "boolean"
122+
)
119123

120124
@pytest.mark.parametrize(
121125
"date_data",
@@ -128,11 +132,11 @@ def test_as_json_table_type_bool_data(self, bool_type):
128132
],
129133
)
130134
def test_as_json_table_type_date_data(self, date_data):
131-
assert as_json_table_type(date_data) == "datetime"
135+
assert as_json_table_type(date_data.dtype) == "datetime"
132136

133137
@pytest.mark.parametrize("str_data", [pd.Series(["a", "b"]), pd.Index(["a", "b"])])
134138
def test_as_json_table_type_string_data(self, str_data):
135-
assert as_json_table_type(str_data) == "string"
139+
assert as_json_table_type(str_data.dtype) == "string"
136140

137141
@pytest.mark.parametrize(
138142
"cat_data",
@@ -145,7 +149,7 @@ def test_as_json_table_type_string_data(self, str_data):
145149
],
146150
)
147151
def test_as_json_table_type_categorical_data(self, cat_data):
148-
assert as_json_table_type(cat_data) == "any"
152+
assert as_json_table_type(cat_data.dtype) == "any"
149153

150154
# ------
151155
# dtypes
@@ -189,7 +193,7 @@ def test_as_json_table_type_categorical_dtypes(self):
189193
# TODO: I think before is_categorical_dtype(Categorical)
190194
# returned True, but now it's False. Figure out why or
191195
# if it matters
192-
assert as_json_table_type(pd.Categorical(["a"])) == "any"
196+
assert as_json_table_type(pd.Categorical(["a"]).dtype) == "any"
193197
assert as_json_table_type(CategoricalDtype()) == "any"
194198

195199

0 commit comments

Comments
 (0)