Skip to content

Commit aad7739

Browse files
DOC: fix errors/warnings in running code blocks (pandas-dev#26076)
1 parent d86553b commit aad7739

File tree

10 files changed

+171
-85
lines changed

10 files changed

+171
-85
lines changed

doc/source/user_guide/io.rst

-7
Original file line numberDiff line numberDiff line change
@@ -3565,13 +3565,6 @@ HDFStore will by default not drop rows that are all missing. This behavior can b
35653565
os.remove('file.h5')
35663566
35673567
3568-
.. ipython:: python
3569-
:suppress:
3570-
3571-
os.remove('file.h5')
3572-
3573-
3574-
35753568
.. _io.hdf5-fixed:
35763569

35773570
Fixed Format

doc/source/user_guide/timedeltas.rst

+3-4
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,12 @@ Operands can also appear in a reversed order (a singular object operated with a
191191
df.min().idxmax()
192192
df.min(axis=1).idxmin()
193193
194-
You can fillna on timedeltas. Integers will be interpreted as seconds. You can
195-
pass a timedelta to get a particular value.
194+
You can fillna on timedeltas, passing a timedelta to get a particular value.
196195

197196
.. ipython:: python
198197
199-
y.fillna(0)
200-
y.fillna(10)
198+
y.fillna(pd.Timedelta(0))
199+
y.fillna(pd.Timedelta(10, unit='s'))
201200
y.fillna(pd.Timedelta('-1 days, 00:00:05'))
202201
203202
You can also negate, multiply and use ``abs`` on ``Timedeltas``:

doc/source/user_guide/timeseries.rst

+7-4
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,16 @@ which can be specified. These are computed from the starting point specified by
322322
1349720105400, 1349720105500], unit='ms')
323323
324324
Constructing a :class:`Timestamp` or :class:`DatetimeIndex` with an epoch timestamp
325-
with the ``tz`` argument specified will localize the epoch timestamps to UTC
326-
first then convert the result to the specified time zone.
325+
with the ``tz`` argument specified will currently localize the epoch timestamps to UTC
326+
first then convert the result to the specified time zone. However, this behavior
327+
is :ref:`deprecated <whatsnew_0240.deprecations.integer_tz>`, and if you have
328+
epochs in wall time in another timezone, it is recommended to read the epochs
329+
as timezone-naive timestamps and then localize to the appropriate timezone:
327330

328331
.. ipython:: python
329332
330-
pd.Timestamp(1262347200000000000, tz='US/Pacific')
331-
pd.DatetimeIndex([1262347200000000000], tz='US/Pacific')
333+
pd.Timestamp(1262347200000000000).tz_localize('US/Pacific')
334+
pd.DatetimeIndex([1262347200000000000]).tz_localize('US/Pacific')
332335
333336
.. note::
334337

doc/source/whatsnew/v0.10.0.rst

+141-56
Original file line numberDiff line numberDiff line change
@@ -295,79 +295,171 @@ Updated PyTables Support
295295

296296
:ref:`Docs <io.hdf5>` for PyTables ``Table`` format & several enhancements to the api. Here is a taste of what to expect.
297297

298-
.. ipython:: python
299-
:suppress:
300-
:okexcept:
298+
.. code-block:: ipython
301299
302-
import os
300+
In [41]: store = pd.HDFStore('store.h5')
303301
304-
os.remove('store.h5')
302+
In [42]: df = pd.DataFrame(np.random.randn(8, 3),
303+
....: index=pd.date_range('1/1/2000', periods=8),
304+
....: columns=['A', 'B', 'C'])
305305
306-
.. ipython:: python
306+
In [43]: df
307+
Out[43]:
308+
A B C
309+
2000-01-01 -2.036047 0.000830 -0.955697
310+
2000-01-02 -0.898872 -0.725411 0.059904
311+
2000-01-03 -0.449644 1.082900 -1.221265
312+
2000-01-04 0.361078 1.330704 0.855932
313+
2000-01-05 -1.216718 1.488887 0.018993
314+
2000-01-06 -0.877046 0.045976 0.437274
315+
2000-01-07 -0.567182 -0.888657 -0.556383
316+
2000-01-08 0.655457 1.117949 -2.782376
307317
308-
store = pd.HDFStore('store.h5')
309-
df = pd.DataFrame(np.random.randn(8, 3),
310-
index=pd.date_range('1/1/2000', periods=8),
311-
columns=['A', 'B', 'C'])
312-
df
318+
[8 rows x 3 columns]
313319
314-
# appending data frames
315-
df1 = df[0:4]
316-
df2 = df[4:]
317-
store.append('df', df1)
318-
store.append('df', df2)
319-
store
320+
# appending data frames
321+
In [44]: df1 = df[0:4]
320322
321-
# selecting the entire store
322-
store.select('df')
323+
In [45]: df2 = df[4:]
323324
324-
.. ipython:: python
325-
:okwarning:
325+
In [46]: store.append('df', df1)
326326
327-
wp = pd.Panel(np.random.randn(2, 5, 4), items=['Item1', 'Item2'],
328-
major_axis=pd.date_range('1/1/2000', periods=5),
329-
minor_axis=['A', 'B', 'C', 'D'])
330-
wp
327+
In [47]: store.append('df', df2)
331328
332-
# storing a panel
333-
store.append('wp', wp)
329+
In [48]: store
330+
Out[48]:
331+
<class 'pandas.io.pytables.HDFStore'>
332+
File path: store.h5
333+
/df frame_table (typ->appendable,nrows->8,ncols->3,indexers->[index])
334334
335-
# selecting via A QUERY
336-
store.select('wp', "major_axis>20000102 and minor_axis=['A','B']")
335+
# selecting the entire store
336+
In [49]: store.select('df')
337+
Out[49]:
338+
A B C
339+
2000-01-01 -2.036047 0.000830 -0.955697
340+
2000-01-02 -0.898872 -0.725411 0.059904
341+
2000-01-03 -0.449644 1.082900 -1.221265
342+
2000-01-04 0.361078 1.330704 0.855932
343+
2000-01-05 -1.216718 1.488887 0.018993
344+
2000-01-06 -0.877046 0.045976 0.437274
345+
2000-01-07 -0.567182 -0.888657 -0.556383
346+
2000-01-08 0.655457 1.117949 -2.782376
337347
338-
# removing data from tables
339-
store.remove('wp', "major_axis>20000103")
340-
store.select('wp')
348+
[8 rows x 3 columns]
349+
350+
.. code-block:: ipython
351+
352+
In [50]: wp = pd.Panel(np.random.randn(2, 5, 4), items=['Item1', 'Item2'],
353+
....: major_axis=pd.date_range('1/1/2000', periods=5),
354+
....: minor_axis=['A', 'B', 'C', 'D'])
355+
356+
In [51]: wp
357+
Out[51]:
358+
<class 'pandas.core.panel.Panel'>
359+
Dimensions: 2 (items) x 5 (major_axis) x 4 (minor_axis)
360+
Items axis: Item1 to Item2
361+
Major_axis axis: 2000-01-01 00:00:00 to 2000-01-05 00:00:00
362+
Minor_axis axis: A to D
363+
364+
# storing a panel
365+
In [52]: store.append('wp', wp)
366+
367+
# selecting via A QUERY
368+
In [53]: store.select('wp', [pd.Term('major_axis>20000102'),
369+
....: pd.Term('minor_axis', '=', ['A', 'B'])])
370+
....:
371+
Out[53]:
372+
<class 'pandas.core.panel.Panel'>
373+
Dimensions: 2 (items) x 3 (major_axis) x 2 (minor_axis)
374+
Items axis: Item1 to Item2
375+
Major_axis axis: 2000-01-03 00:00:00 to 2000-01-05 00:00:00
376+
Minor_axis axis: A to B
377+
378+
# removing data from tables
379+
In [54]: store.remove('wp', pd.Term('major_axis>20000103'))
380+
Out[54]: 8
381+
382+
In [55]: store.select('wp')
383+
Out[55]:
384+
<class 'pandas.core.panel.Panel'>
385+
Dimensions: 2 (items) x 3 (major_axis) x 4 (minor_axis)
386+
Items axis: Item1 to Item2
387+
Major_axis axis: 2000-01-01 00:00:00 to 2000-01-03 00:00:00
388+
Minor_axis axis: A to D
389+
390+
# deleting a store
391+
In [56]: del store['df']
392+
393+
In [57]: store
394+
Out[57]:
395+
<class 'pandas.io.pytables.HDFStore'>
396+
File path: store.h5
397+
/wp wide_table (typ->appendable,nrows->12,ncols->2,indexers->[major_axis,minor_axis])
341398
342-
# deleting a store
343-
del store['df']
344-
store
345399
346400
**Enhancements**
347401

348402
- added ability to hierarchical keys
349403

350-
.. ipython:: python
404+
.. code-block:: ipython
405+
406+
In [58]: store.put('foo/bar/bah', df)
407+
408+
In [59]: store.append('food/orange', df)
351409
352-
store.put('foo/bar/bah', df)
353-
store.append('food/orange', df)
354-
store.append('food/apple', df)
355-
store
410+
In [60]: store.append('food/apple', df)
356411
357-
# remove all nodes under this level
358-
store.remove('food')
359-
store
412+
In [61]: store
413+
Out[61]:
414+
<class 'pandas.io.pytables.HDFStore'>
415+
File path: store.h5
416+
/foo/bar/bah frame (shape->[8,3])
417+
/food/apple frame_table (typ->appendable,nrows->8,ncols->3,indexers->[index])
418+
/food/orange frame_table (typ->appendable,nrows->8,ncols->3,indexers->[index])
419+
/wp wide_table (typ->appendable,nrows->12,ncols->2,indexers->[major_axis,minor_axis])
420+
421+
# remove all nodes under this level
422+
In [62]: store.remove('food')
423+
424+
In [63]: store
425+
Out[63]:
426+
<class 'pandas.io.pytables.HDFStore'>
427+
File path: store.h5
428+
/foo/bar/bah frame (shape->[8,3])
429+
/wp wide_table (typ->appendable,nrows->12,ncols->2,indexers->[major_axis,minor_axis])
360430
361431
- added mixed-dtype support!
362432

363433
.. ipython:: python
364434
365-
df['string'] = 'string'
366-
df['int'] = 1
367-
store.append('df', df)
368-
df1 = store.select('df')
369-
df1
370-
df1.get_dtype_counts()
435+
In [64]: df['string'] = 'string'
436+
437+
In [65]: df['int'] = 1
438+
439+
In [66]: store.append('df', df)
440+
441+
In [67]: df1 = store.select('df')
442+
443+
In [68]: df1
444+
Out[68]:
445+
A B C string int
446+
2000-01-01 -2.036047 0.000830 -0.955697 string 1
447+
2000-01-02 -0.898872 -0.725411 0.059904 string 1
448+
2000-01-03 -0.449644 1.082900 -1.221265 string 1
449+
2000-01-04 0.361078 1.330704 0.855932 string 1
450+
2000-01-05 -1.216718 1.488887 0.018993 string 1
451+
2000-01-06 -0.877046 0.045976 0.437274 string 1
452+
2000-01-07 -0.567182 -0.888657 -0.556383 string 1
453+
2000-01-08 0.655457 1.117949 -2.782376 string 1
454+
455+
[8 rows x 5 columns]
456+
457+
In [69]: df1.get_dtype_counts()
458+
Out[69]:
459+
float64 3
460+
int64 1
461+
object 1
462+
dtype: int64
371463
372464
- performance improvements on table writing
373465
- support for arbitrarily indexed dimensions
@@ -392,13 +484,6 @@ Updated PyTables Support
392484
- minor change to select and remove: require a table ONLY if where is also
393485
provided (and not None)
394486

395-
.. ipython:: python
396-
:suppress:
397-
398-
store.close()
399-
import os
400-
os.remove('store.h5')
401-
402487
**Compatibility**
403488

404489
0.10 of ``HDFStore`` is backwards compatible for reading tables created in a prior version of pandas,

doc/source/whatsnew/v0.11.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ Enhancements
278278
- ``Squeeze`` to possibly remove length 1 dimensions from an object.
279279

280280
.. ipython:: python
281+
:okwarning:
281282
282283
p = pd.Panel(np.random.randn(3, 4, 4), items=['ItemA', 'ItemB', 'ItemC'],
283284
major_axis=pd.date_range('20010102', periods=4),

doc/source/whatsnew/v0.12.0.rst

+14-12
Original file line numberDiff line numberDiff line change
@@ -317,22 +317,24 @@ Other Enhancements
317317

318318
- ``pd.set_option()`` now allows N option, value pairs (:issue:`3667`).
319319

320-
Let's say that we had an option ``'a.b'`` and another option ``'b.c'``.
321-
We can set them at the same time:
320+
Let's say that we had an option ``'a.b'`` and another option ``'b.c'``.
321+
We can set them at the same time:
322322

323-
.. ipython:: python
324-
:suppress:
323+
.. ipython:: python
325324
326-
pd.core.config.register_option('a.b', 2, 'ay dot bee')
327-
pd.core.config.register_option('b.c', 3, 'bee dot cee')
325+
In [31]: pd.get_option('a.b')
326+
Out[31]: 2
328327
329-
.. ipython:: python
328+
In [32]: pd.get_option('b.c')
329+
Out[32]: 3
330+
331+
In [33]: pd.set_option('a.b', 1, 'b.c', 4)
332+
333+
In [34]: pd.get_option('a.b')
334+
Out[34]: 1
330335
331-
pd.get_option('a.b')
332-
pd.get_option('b.c')
333-
pd.set_option('a.b', 1, 'b.c', 4)
334-
pd.get_option('a.b')
335-
pd.get_option('b.c')
336+
In [35]: pd.get_option('b.c')
337+
Out[35]: 4
336338
337339
- The ``filter`` method for group objects returns a subset of the original
338340
object. Suppose we want to take only elements that belong to groups with a

doc/source/whatsnew/v0.13.0.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ This is like an ``append`` operation.
272272
A Panel setting operation on an arbitrary axis aligns the input to the Panel
273273

274274
.. ipython:: python
275+
:okwarning:
275276
276277
p = pd.Panel(np.arange(16).reshape(2, 4, 2),
277278
items=['Item1', 'Item2'],
@@ -543,7 +544,7 @@ Enhancements
543544

544545
.. ipython:: python
545546
546-
td.fillna(0)
547+
td.fillna(pd.Timedelta(0))
547548
td.fillna(datetime.timedelta(days=1, seconds=5))
548549
549550
You can do numeric reduction operations on timedeltas.

doc/source/whatsnew/v0.15.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ Other notable API changes:
702702
This can also be seen in multi-axis indexing with a ``Panel``.
703703

704704
.. ipython:: python
705+
:okwarning:
705706
706707
p = pd.Panel(np.arange(2 * 3 * 4).reshape(2, 3, 4),
707708
items=['ItemA', 'ItemB'],

doc/source/whatsnew/v0.15.2.rst

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ Other enhancements:
161161
- ``Panel`` now supports the ``all`` and ``any`` aggregation functions. (:issue:`8302`):
162162

163163
.. ipython:: python
164+
:okwarning:
164165
165166
p = pd.Panel(np.random.rand(2, 5, 4) > 0.1)
166167
p.all()

doc/source/whatsnew/v0.24.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ missing indicator, ``np.nan``. (:issue:`20377`)
567567
.. ipython:: python
568568
:suppress:
569569
570-
from pandas.io import StringIO
570+
from io import StringIO
571571
572572
*Previous Behavior*:
573573

0 commit comments

Comments
 (0)