16
16
### interface to/from ###
17
17
18
18
def to_json (path_or_buf , obj , orient = None , date_format = 'epoch' , double_precision = 10 , force_ascii = True ):
19
-
19
+
20
20
if isinstance (obj , Series ):
21
- s = SeriesWriter (obj , orient = orient , date_format = date_format , double_precision = double_precision ,
21
+ s = SeriesWriter (obj , orient = orient , date_format = date_format , double_precision = double_precision ,
22
22
ensure_ascii = force_ascii ).write ()
23
23
elif isinstance (obj , DataFrame ):
24
24
s = FrameWriter (obj , orient = orient , date_format = date_format , double_precision = double_precision ,
@@ -41,7 +41,7 @@ def __init__(self, obj, orient, date_format, double_precision, ensure_ascii):
41
41
42
42
if orient is None :
43
43
orient = self ._default_orient
44
-
44
+
45
45
self .orient = orient
46
46
self .date_format = date_format
47
47
self .double_precision = double_precision
@@ -64,7 +64,7 @@ def _format_to_date(self, data):
64
64
if self ._needs_to_date (data ):
65
65
return data .apply (lambda x : x .isoformat ())
66
66
return data
67
-
67
+
68
68
def copy_if_needed (self ):
69
69
""" copy myself if necessary """
70
70
if not self .is_copy :
@@ -155,8 +155,10 @@ def read_json(path_or_buf=None, orient=None, typ='frame', dtype=True,
155
155
default is True
156
156
keep_default_dates : boolean, default True. If parsing dates,
157
157
then parse the default datelike columns
158
- numpy: direct decoding to numpy arrays. default is False.Note that the JSON ordering MUST be the same
158
+ numpy : direct decoding to numpy arrays. default is False.Note that the JSON ordering MUST be the same
159
159
for each term if numpy=True.
160
+ precise_float : boolean, default False. Set to enable usage of higher precision (strtod) function
161
+ when decoding string to double values. Default (False) is to use fast but less precise builtin functionality
160
162
161
163
Returns
162
164
-------
@@ -187,15 +189,15 @@ def read_json(path_or_buf=None, orient=None, typ='frame', dtype=True,
187
189
return obj
188
190
189
191
class Parser (object ):
190
-
192
+
191
193
def __init__ (self , json , orient , dtype = True , convert_axes = True ,
192
194
convert_dates = True , keep_default_dates = False , numpy = False ,
193
195
precise_float = False ):
194
196
self .json = json
195
197
196
198
if orient is None :
197
199
orient = self ._default_orient
198
-
200
+
199
201
self .orient = orient
200
202
self .dtype = dtype
201
203
@@ -211,7 +213,7 @@ def __init__(self, json, orient, dtype=True, convert_axes=True,
211
213
212
214
def parse (self ):
213
215
214
- # try numpy
216
+ # try numpy
215
217
numpy = self .numpy
216
218
if numpy :
217
219
self ._parse_numpy ()
@@ -273,7 +275,7 @@ def _try_convert_data(self, name, data, use_dtypes=True, convert_dates=True):
273
275
pass
274
276
275
277
if data .dtype == 'float' :
276
-
278
+
277
279
# coerce floats to 64
278
280
try :
279
281
data = data .astype ('float64' )
@@ -295,7 +297,7 @@ def _try_convert_data(self, name, data, use_dtypes=True, convert_dates=True):
295
297
296
298
# coerce ints to 64
297
299
if data .dtype == 'int' :
298
-
300
+
299
301
# coerce floats to 64
300
302
try :
301
303
data = data .astype ('int64' )
@@ -326,7 +328,7 @@ def _try_convert_to_date(self, data):
326
328
if issubclass (new_data .dtype .type ,np .number ):
327
329
if not ((new_data == iNaT ) | (new_data > 31536000000000000L )).all ():
328
330
return data , False
329
-
331
+
330
332
try :
331
333
new_data = to_datetime (new_data )
332
334
except :
@@ -346,7 +348,7 @@ class SeriesParser(Parser):
346
348
_default_orient = 'index'
347
349
348
350
def _parse_no_numpy (self ):
349
-
351
+
350
352
json = self .json
351
353
orient = self .orient
352
354
if orient == "split" :
0 commit comments