Skip to content

Commit 2a15e47

Browse files
committed
correct examples in whatsnew
1 parent c6cbda3 commit 2a15e47

File tree

2 files changed

+67
-18
lines changed

2 files changed

+67
-18
lines changed

doc/source/whatsnew/v0.18.0.rst

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,15 +322,28 @@ Tz-aware are rounded, floored and ceiled in local times
322322
323323
Timedeltas
324324

325-
.. ipython:: python
325+
.. code-block:: ipython
326+
327+
In [37]: t = pd.timedelta_range('1 days 2 hr 13 min 45 us', periods=3, freq='d')
326328
327-
t = pd.timedelta_range('1 days 2 hr 13 min 45 us', periods=3, freq='d')
328-
t
329-
t.round('10min')
329+
In [38]: t
330+
Out[38]:
331+
TimedeltaIndex(['1 days 02:13:00.000045', '2 days 02:13:00.000045',
332+
'3 days 02:13:00.000045'],
333+
dtype='timedelta64[ns]', freq='D')
334+
335+
In [39]: t.round('10min')
336+
Out[39]:
337+
TimedeltaIndex(['1 days 02:10:00', '2 days 02:10:00',
338+
'3 days 02:10:00'],
339+
dtype='timedelta64[ns]', freq=None)
330340
331341
# Timedelta scalar
332-
t[0]
333-
t[0].round('2h')
342+
In [40]: t[0]
343+
Out[40]: Timedelta('1 days 02:13:00.000045')
344+
345+
In [41]: t[0].round('2h')
346+
Out[41]: Timedelta('1 days 02:00:00')
334347
335348
336349
In addition, ``.round()``, ``.floor()`` and ``.ceil()`` will be available through the ``.dt`` accessor of ``Series``.

doc/source/whatsnew/v0.23.0.rst

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,55 @@ JSON read/write round-trippable with ``orient='table'``
5050

5151
A ``DataFrame`` can now be written to and subsequently read back via JSON while preserving metadata through usage of the ``orient='table'`` argument (see :issue:`18912` and :issue:`9146`). Previously, none of the available ``orient`` values guaranteed the preservation of dtypes and index names, amongst other metadata.
5252

53-
.. ipython:: python
53+
.. code-block:: ipython
5454
55-
df = pd.DataFrame({'foo': [1, 2, 3, 4],
56-
'bar': ['a', 'b', 'c', 'd'],
57-
'baz': pd.date_range('2018-01-01', freq='d', periods=4),
58-
'qux': pd.Categorical(['a', 'b', 'c', 'c'])},
59-
index=pd.Index(range(4), name='idx'))
60-
df
61-
df.dtypes
62-
df.to_json('test.json', orient='table')
63-
new_df = pd.read_json('test.json', orient='table')
64-
new_df
65-
new_df.dtypes
55+
In [1]: df = pd.DataFrame({'foo': [1, 2, 3, 4],
56+
...: 'bar': ['a', 'b', 'c', 'd'],
57+
...: 'baz': pd.date_range('2018-01-01', freq='d', periods=4),
58+
...: 'qux': pd.Categorical(['a', 'b', 'c', 'c'])},
59+
...: index=pd.Index(range(4), name='idx'))
60+
61+
In [2]: df
62+
Out[2]:
63+
foo bar baz qux
64+
idx
65+
0 1 a 2018-01-01 a
66+
1 2 b 2018-01-02 b
67+
2 3 c 2018-01-03 c
68+
3 4 d 2018-01-04 c
69+
70+
[4 rows x 4 columns]
71+
72+
In [3]: df.dtypes
73+
Out[3]:
74+
foo int64
75+
bar object
76+
baz datetime64[ns]
77+
qux category
78+
Length: 4, dtype: object
79+
80+
In [4]: df.to_json('test.json', orient='table')
81+
82+
In [5]: new_df = pd.read_json('test.json', orient='table')
83+
84+
In [6]: new_df
85+
Out[6]:
86+
foo bar baz qux
87+
idx
88+
0 1 a 2018-01-01 a
89+
1 2 b 2018-01-02 b
90+
2 3 c 2018-01-03 c
91+
3 4 d 2018-01-04 c
92+
93+
[4 rows x 4 columns]
94+
95+
In [7]: new_df.dtypes
96+
Out[7]:
97+
foo int64
98+
bar object
99+
baz datetime64[ns]
100+
qux category
101+
Length: 4, dtype: object
66102
67103
Please note that the string ``index`` is not supported with the round trip format, as it is used by default in ``write_json`` to indicate a missing index name.
68104

0 commit comments

Comments
 (0)