Skip to content

Commit 535336a

Browse files
committed
DOC: updated documentation for date_unit="D" (#16492)
1 parent 3e323d9 commit 535336a

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

doc/source/user_guide/io.rst

+10-3
Original file line numberDiff line numberDiff line change
@@ -1864,7 +1864,7 @@ with optional parameters:
18641864
* ``date_format`` : string, type of date conversion, 'epoch' for timestamp, 'iso' for ISO8601.
18651865
* ``double_precision`` : The number of decimal places to use when encoding floating point values, default 10.
18661866
* ``force_ascii`` : force encoded string to be ASCII, default True.
1867-
* ``date_unit`` : The time unit to encode to, governs timestamp and ISO8601 precision. One of 's', 'ms', 'us' or 'ns' for seconds, milliseconds, microseconds and nanoseconds respectively. Default 'ms'.
1867+
* ``date_unit`` : The time unit to encode to, governs timestamp and ISO8601 precision. One of 'D', 's', 'ms', 'us' or 'ns' for days, seconds, milliseconds, microseconds and nanoseconds respectively. Default 'ms'.
18681868
* ``default_handler`` : The handler to call if an object cannot otherwise be converted to a suitable format for JSON. Takes a single argument, which is the object to convert, and returns a serializable object.
18691869
* ``lines`` : If ``records`` orient, then will write each record per line as json.
18701870
* ``mode`` : string, writer mode when writing to path. 'w' for write, 'a' for append. Default 'w'
@@ -1964,6 +1964,13 @@ Writing in ISO date format, with microseconds:
19641964
json = dfd.to_json(date_format="iso", date_unit="us")
19651965
json
19661966
1967+
Writing in ISO date format, with just dates:
1968+
1969+
.. ipython:: python
1970+
1971+
json = dfd.to_json(date_format="iso", date_unit="D")
1972+
json
1973+
19671974
Epoch timestamps, in seconds:
19681975

19691976
.. ipython:: python
@@ -2064,8 +2071,8 @@ is ``None``. To explicitly force ``Series`` parsing, pass ``typ=series``
20642071
* ``precise_float`` : boolean, default ``False``. Set to enable usage of higher precision (strtod) function when decoding string to double values. Default (``False``) is to use fast but less precise builtin functionality.
20652072
* ``date_unit`` : string, the timestamp unit to detect if converting dates. Default
20662073
None. By default the timestamp precision will be detected, if this is not desired
2067-
then pass one of 's', 'ms', 'us' or 'ns' to force timestamp precision to
2068-
seconds, milliseconds, microseconds or nanoseconds respectively.
2074+
then pass one of 'D', 's', 'ms', 'us' or 'ns' to force timestamp precision to
2075+
days, seconds, milliseconds, microseconds or nanoseconds respectively.
20692076
* ``lines`` : reads file as one json object per line.
20702077
* ``encoding`` : The encoding to use to decode py3 bytes.
20712078
* ``chunksize`` : when used in combination with ``lines=True``, return a JsonReader which reads in ``chunksize`` lines per iteration.

pandas/core/generic.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2349,8 +2349,8 @@ def to_json(
23492349
Force encoded string to be ASCII.
23502350
date_unit : str, default 'ms' (milliseconds)
23512351
The time unit to encode to, governs timestamp and ISO8601
2352-
precision. One of 's', 'ms', 'us', 'ns' for second, millisecond,
2353-
microsecond, and nanosecond respectively.
2352+
precision. One of 'D', 's', 'ms', 'us', 'ns' for days,
2353+
second, millisecond, microsecond, and nanosecond respectively.
23542354
default_handler : callable, default None
23552355
Handler to call if object cannot otherwise be converted to a
23562356
suitable format for JSON. Should receive a single argument which is

pandas/io/json/_json.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,10 @@ def read_json(
596596
date_unit : str, default None
597597
The timestamp unit to detect if converting dates. The default behaviour
598598
is to try and detect the correct precision, but if this is not desired
599-
then pass one of 's', 'ms', 'us' or 'ns' to force parsing only seconds,
600-
milliseconds, microseconds or nanoseconds respectively.
599+
then pass one of 'D', 's', 'ms', 'us' or 'ns' to force parsing only days,
600+
seconds, milliseconds, microseconds or nanoseconds respectively.
601+
Time unit (from 's' to 'ns') are automatically inferred from the input,
602+
while the 'D' unit is not inferred and must be specified explicitly.
601603
602604
encoding : str, default is 'utf-8'
603605
The encoding to use to decode py3 bytes.

0 commit comments

Comments
 (0)