32
32
33
33
TABLE_SCHEMA_VERSION = "0.20.0"
34
34
35
+ Serializable = Union [int , str , List , Dict ]
36
+
35
37
36
38
# interface to/from
37
39
def to_json (
@@ -42,7 +44,7 @@ def to_json(
42
44
double_precision : int = 10 ,
43
45
force_ascii : bool = True ,
44
46
date_unit : str = "ms" ,
45
- default_handler : Optional [Callable [[Any ], Union [ int , str , List , Dict ] ]]= None ,
47
+ default_handler : Optional [Callable [[Any ], Serializable ]]= None ,
46
48
lines : bool = False ,
47
49
compression : Optional [str ] = "infer" ,
48
50
index : bool = True ,
@@ -101,19 +103,19 @@ class Writer:
101
103
def __init__ (
102
104
self ,
103
105
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 ,
112
114
):
113
115
self .obj = obj
114
116
115
117
if orient is None :
116
- orient = self ._default_orient
118
+ orient = self ._default_orient # type: ignore
117
119
118
120
self .orient = orient
119
121
self .date_format = date_format
@@ -145,13 +147,13 @@ def write(self):
145
147
def _write (
146
148
self ,
147
149
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 ,
155
157
):
156
158
return dumps (
157
159
obj ,
@@ -178,13 +180,13 @@ def _format_axes(self):
178
180
def _write (
179
181
self ,
180
182
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 ,
188
190
):
189
191
if not self .index and orient == "split" :
190
192
obj = {"name" : obj .name , "data" : obj .values }
@@ -225,13 +227,13 @@ def _format_axes(self):
225
227
def _write (
226
228
self ,
227
229
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 ,
235
237
):
236
238
if not self .index and orient == "split" :
237
239
obj = obj .to_dict (orient = "split" )
@@ -254,14 +256,14 @@ class JSONTableWriter(FrameWriter):
254
256
def __init__ (
255
257
self ,
256
258
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 ,
265
267
):
266
268
"""
267
269
Adds a `schema` attribute with the Table Schema, resets
0 commit comments