Skip to content

Commit 21672ed

Browse files
committed
More hints in _json
1 parent d11e47f commit 21672ed

File tree

1 file changed

+41
-39
lines changed

1 file changed

+41
-39
lines changed

pandas/io/json/_json.py

+41-39
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
TABLE_SCHEMA_VERSION = "0.20.0"
3434

35+
Serializable = Union[int, str, List, Dict]
36+
3537

3638
# interface to/from
3739
def to_json(
@@ -42,7 +44,7 @@ def to_json(
4244
double_precision: int = 10,
4345
force_ascii: bool =True,
4446
date_unit: str = "ms",
45-
default_handler: Optional[Callable[[Any], Union[int, str, List, Dict]]]=None,
47+
default_handler: Optional[Callable[[Any], Serializable]]=None,
4648
lines: bool =False,
4749
compression: Optional[str] = "infer",
4850
index: bool = True,
@@ -101,19 +103,19 @@ class Writer:
101103
def __init__(
102104
self,
103105
obj,
104-
orient,
105-
date_format,
106-
double_precision,
107-
ensure_ascii,
108-
date_unit,
109-
index,
110-
default_handler=None,
111-
indent=0,
106+
orient: Optional[str],
107+
date_format: str,
108+
double_precision: int,
109+
ensure_ascii: bool,
110+
date_unit: str,
111+
index: bool,
112+
default_handler: Optional[Callable[[Any], Serializable]]=None,
113+
indent: int = 0,
112114
):
113115
self.obj = obj
114116

115117
if orient is None:
116-
orient = self._default_orient
118+
orient = self._default_orient # type: ignore
117119

118120
self.orient = orient
119121
self.date_format = date_format
@@ -145,13 +147,13 @@ def write(self):
145147
def _write(
146148
self,
147149
obj,
148-
orient,
149-
double_precision,
150-
ensure_ascii,
151-
date_unit,
152-
iso_dates,
153-
default_handler,
154-
indent,
150+
orient: Optional[str],
151+
double_precision: int,
152+
ensure_ascii: bool,
153+
date_unit: str,
154+
iso_dates: bool,
155+
default_handler: Optional[Callable[[Any], Serializable]],
156+
indent: int,
155157
):
156158
return dumps(
157159
obj,
@@ -178,13 +180,13 @@ def _format_axes(self):
178180
def _write(
179181
self,
180182
obj,
181-
orient,
182-
double_precision,
183-
ensure_ascii,
184-
date_unit,
185-
iso_dates,
186-
default_handler,
187-
indent,
183+
orient: Optional[str],
184+
double_precision: int,
185+
ensure_ascii: bool,
186+
date_unit: str,
187+
iso_dates: bool,
188+
default_handler: Optional[Callable[[Any], Serializable]],
189+
indent: int,
188190
):
189191
if not self.index and orient == "split":
190192
obj = {"name": obj.name, "data": obj.values}
@@ -225,13 +227,13 @@ def _format_axes(self):
225227
def _write(
226228
self,
227229
obj,
228-
orient,
229-
double_precision,
230-
ensure_ascii,
231-
date_unit,
232-
iso_dates,
233-
default_handler,
234-
indent,
230+
orient: Optional[str],
231+
double_precision: int,
232+
ensure_ascii: bool,
233+
date_unit: str,
234+
iso_dates: bool,
235+
default_handler: Optional[Callable[[Any], Serializable]],
236+
indent: int,
235237
):
236238
if not self.index and orient == "split":
237239
obj = obj.to_dict(orient="split")
@@ -254,14 +256,14 @@ class JSONTableWriter(FrameWriter):
254256
def __init__(
255257
self,
256258
obj,
257-
orient,
258-
date_format,
259-
double_precision,
260-
ensure_ascii,
261-
date_unit,
262-
index,
263-
default_handler=None,
264-
indent=0,
259+
orient: Optional[str],
260+
date_format: str,
261+
double_precision: int,
262+
ensure_ascii: bool,
263+
date_unit: str,
264+
index: bool,
265+
default_handler: Optional[Callable[[Any], Serializable]]=None,
266+
indent: int=0,
265267
):
266268
"""
267269
Adds a `schema` attribute with the Table Schema, resets

0 commit comments

Comments
 (0)