Skip to content

Commit 4e72d46

Browse files
committed
DOC: docs for precise_float option in read_json
1 parent d8dc8ee commit 4e72d46

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

doc/source/io.rst

+2
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,8 @@ is ``None``. To explicity force ``Series`` parsing, pass ``typ=series``
10601060
- ``keep_default_dates`` : boolean, default True. If parsing dates, then parse the default datelike columns
10611061
- ``numpy`` : direct decoding to numpy arrays. default is False;
10621062
Note that the JSON ordering **MUST** be the same for each term if ``numpy=True``
1063+
- ``precise_float`` : boolean, default ``False``. Set to enable usage of higher precision (strtod) function
1064+
when decoding string to double values. Default (``False``) is to use fast but less precise builtin functionality
10631065

10641066
The parser will raise one of ``ValueError/TypeError/AssertionError`` if the JSON is
10651067
not parsable.

doc/source/release.rst

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ pandas 0.12
3535
list of ``DataFrame`` s courtesy of @cpcloud. (:issue:`3477`,
3636
:issue:`3605`, :issue:`3606`)
3737
- Support for reading Amazon S3 files. (:issue:`3504`)
38+
- Added module for reading and writing JSON strings/files: pandas.io.json
39+
includes ``to_json`` DataFrame/Series method, and a ``read_json`` top-level reader
40+
various issues (:issue:`1226`, :issue:`3804`, :issue:`3876`, :issue:`3867`, :issue:`1305`)
3841
- Added module for reading and writing Stata files: pandas.io.stata (:issue:`1512`)
3942
includes ``to_stata`` DataFrame method, and a ``read_stata`` top-level reader
4043
- Added support for writing in ``to_csv`` and reading in ``read_csv``,

doc/source/v0.12.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ I/O Enhancements
206206
- Added module for reading and writing json format files: ``pandas.io.json``
207207
accessable via ``read_json`` top-level function for reading,
208208
and ``to_json`` DataFrame method for writing, :ref:`See the docs<io.json>`
209+
various issues (:issue:`1226`, :issue:`3804`, :issue:`3876`, :issue:`3867`, :issue:`1305`)
209210

210211
- ``MultiIndex`` column support for reading and writing csv format files
211212

pandas/io/json.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
### interface to/from ###
1717

1818
def to_json(path_or_buf, obj, orient=None, date_format='epoch', double_precision=10, force_ascii=True):
19-
19+
2020
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,
2222
ensure_ascii=force_ascii).write()
2323
elif isinstance(obj, DataFrame):
2424
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):
4141

4242
if orient is None:
4343
orient = self._default_orient
44-
44+
4545
self.orient = orient
4646
self.date_format = date_format
4747
self.double_precision = double_precision
@@ -64,7 +64,7 @@ def _format_to_date(self, data):
6464
if self._needs_to_date(data):
6565
return data.apply(lambda x: x.isoformat())
6666
return data
67-
67+
6868
def copy_if_needed(self):
6969
""" copy myself if necessary """
7070
if not self.is_copy:
@@ -155,8 +155,10 @@ def read_json(path_or_buf=None, orient=None, typ='frame', dtype=True,
155155
default is True
156156
keep_default_dates : boolean, default True. If parsing dates,
157157
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
159159
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
160162
161163
Returns
162164
-------
@@ -187,15 +189,15 @@ def read_json(path_or_buf=None, orient=None, typ='frame', dtype=True,
187189
return obj
188190

189191
class Parser(object):
190-
192+
191193
def __init__(self, json, orient, dtype=True, convert_axes=True,
192194
convert_dates=True, keep_default_dates=False, numpy=False,
193195
precise_float=False):
194196
self.json = json
195197

196198
if orient is None:
197199
orient = self._default_orient
198-
200+
199201
self.orient = orient
200202
self.dtype = dtype
201203

@@ -211,7 +213,7 @@ def __init__(self, json, orient, dtype=True, convert_axes=True,
211213

212214
def parse(self):
213215

214-
# try numpy
216+
# try numpy
215217
numpy = self.numpy
216218
if numpy:
217219
self._parse_numpy()
@@ -273,7 +275,7 @@ def _try_convert_data(self, name, data, use_dtypes=True, convert_dates=True):
273275
pass
274276

275277
if data.dtype == 'float':
276-
278+
277279
# coerce floats to 64
278280
try:
279281
data = data.astype('float64')
@@ -295,7 +297,7 @@ def _try_convert_data(self, name, data, use_dtypes=True, convert_dates=True):
295297

296298
# coerce ints to 64
297299
if data.dtype == 'int':
298-
300+
299301
# coerce floats to 64
300302
try:
301303
data = data.astype('int64')
@@ -326,7 +328,7 @@ def _try_convert_to_date(self, data):
326328
if issubclass(new_data.dtype.type,np.number):
327329
if not ((new_data == iNaT) | (new_data > 31536000000000000L)).all():
328330
return data, False
329-
331+
330332
try:
331333
new_data = to_datetime(new_data)
332334
except:
@@ -346,7 +348,7 @@ class SeriesParser(Parser):
346348
_default_orient = 'index'
347349

348350
def _parse_no_numpy(self):
349-
351+
350352
json = self.json
351353
orient = self.orient
352354
if orient == "split":

0 commit comments

Comments
 (0)