Skip to content

Commit 469df2d

Browse files
DOC: change code-blocks to ipython blocks with okexcept (GH10715)
1 parent f9f97eb commit 469df2d

File tree

6 files changed

+31
-45
lines changed

6 files changed

+31
-45
lines changed

doc/source/advanced.rst

+14-20
Original file line numberDiff line numberDiff line change
@@ -661,18 +661,14 @@ values NOT in the categories, similarly to how you can reindex ANY pandas index.
661661
Reshaping and Comparision operations on a ``CategoricalIndex`` must have the same categories
662662
or a ``TypeError`` will be raised.
663663

664-
.. code-block:: python
665-
666-
In [9]: df3 = pd.DataFrame({'A' : np.arange(6),
667-
'B' : pd.Series(list('aabbca')).astype('category')})
668-
669-
In [11]: df3 = df3.set_index('B')
670-
671-
In [11]: df3.index
672-
Out[11]: CategoricalIndex([u'a', u'a', u'b', u'b', u'c', u'a'], categories=[u'a', u'b', u'c'], ordered=False, name=u'B', dtype='category')
664+
.. ipython:: python
665+
:okexcept:
673666
674-
In [12]: pd.concat([df2, df3]
675-
TypeError: categories must match existing categories when appending
667+
df3 = pd.DataFrame({'A' : np.arange(6),
668+
'B' : pd.Series(list('aabbca')).astype('category')})
669+
df3 = df3.set_index('B')
670+
df3.index
671+
pd.concat([df2, df3]
676672
677673
.. _indexing.float64index:
678674
@@ -738,20 +734,18 @@ In float indexes, slicing using floats is allowed
738734
739735
In non-float indexes, slicing using floats will raise a ``TypeError``
740736
741-
.. code-block:: python
742-
743-
In [1]: pd.Series(range(5))[3.5]
744-
TypeError: the label [3.5] is not a proper indexer for this index type (Int64Index)
737+
.. ipython:: python
738+
:okexcept:
745739
746-
In [1]: pd.Series(range(5))[3.5:4.5]
747-
TypeError: the slice start [3.5] is not a proper indexer for this index type (Int64Index)
740+
pd.Series(range(5))[3.5]
741+
pd.Series(range(5))[3.5:4.5]
748742
749743
Using a scalar float indexer will be deprecated in a future version, but is allowed for now.
750744
751-
.. code-block:: python
745+
.. ipython:: python
746+
:okwarning:
752747
753-
In [3]: pd.Series(range(5))[3.0]
754-
Out[3]: 3
748+
pd.Series(range(5))[3.0]
755749
756750
Here is a typical use-case for using this type of indexing. Imagine that you have a somewhat
757751
irregular timedelta-like indexing scheme, but the data is recorded as floats. This could for

doc/source/basics.rst

+4-6
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,11 @@ objects of the same length:
352352
Trying to compare ``Index`` or ``Series`` objects of different lengths will
353353
raise a ValueError:
354354

355-
.. code-block:: python
356-
357-
In [55]: pd.Series(['foo', 'bar', 'baz']) == pd.Series(['foo', 'bar'])
358-
ValueError: Series lengths must match to compare
355+
.. ipython:: python
356+
:okexcept:
359357
360-
In [56]: pd.Series(['foo', 'bar', 'baz']) == pd.Series(['foo'])
361-
ValueError: Series lengths must match to compare
358+
pd.Series(['foo', 'bar', 'baz']) == pd.Series(['foo', 'bar'])
359+
pd.Series(['foo', 'bar', 'baz']) == pd.Series(['foo'])
362360
363361
Note that this is different from the numpy behavior where a comparison can
364362
be broadcast:

doc/source/dsintro.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ label:
143143
144144
If a label is not contained, an exception is raised:
145145

146-
.. code-block:: python
146+
.. ipython:: python
147+
:okexcept:
147148
148-
>>> s['f']
149-
KeyError: 'f'
149+
s['f']
150150
151151
Using the ``get`` method, a missing label will return None or specified default:
152152

doc/source/indexing.rst

+5-7
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,10 @@ Selection By Label
293293
dfl = pd.DataFrame(np.random.randn(5,4), columns=list('ABCD'), index=pd.date_range('20130101',periods=5))
294294
dfl
295295
296-
.. code-block:: python
296+
.. ipython:: python
297+
:okexcept:
297298
298-
In [4]: dfl.loc[2:3]
299-
TypeError: cannot do slice indexing on <class 'pandas.tseries.index.DatetimeIndex'> with these indexers [2] of <type 'int'>
299+
dfl.loc[2:3]
300300
301301
String likes in slicing *can* be convertible to the type of the index and lead to natural slicing.
302302

@@ -475,13 +475,11 @@ A single indexer that is out of bounds will raise an ``IndexError``.
475475
A list of indexers where any element is out of bounds will raise an
476476
``IndexError``
477477

478-
.. code-block:: python
478+
.. ipython:: python
479+
:okexcept:
479480
480481
dfl.iloc[[4,5,6]]
481-
IndexError: positional indexers are out-of-bounds
482-
483482
dfl.iloc[:,4]
484-
IndexError: single positional indexer is out-of-bounds
485483
486484
.. _indexing.basics.partial_setting:
487485

doc/source/options.rst

+1-5
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,7 @@ The following will **not work** because it matches multiple option names, e.g.
5757
.. ipython:: python
5858
:okexcept:
5959
60-
try:
61-
pd.get_option("column")
62-
except KeyError as e:
63-
print(e)
64-
60+
pd.get_option("column")
6561
6662
**Note:** Using this form of shorthand may cause your code to break if new options with similar names are added in future versions.
6763

doc/source/timeseries.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ Invalid Data
205205
Pass ``errors='coerce'`` to convert invalid data to ``NaT`` (not a time):
206206

207207
.. ipython:: python
208-
:okexcept:
209208
210209
# this is the default, raise when unparseable
210+
@okexcept
211211
to_datetime(['2009/07/31', 'asd'], errors='raise')
212212
213213
# return the original input when unparseable
@@ -656,7 +656,7 @@ apply the offset to each element.
656656
rng + DateOffset(months=2)
657657
s + DateOffset(months=2)
658658
s - DateOffset(months=2)
659-
659+
660660
If the offset class maps directly to a ``Timedelta`` (``Day``, ``Hour``,
661661
``Minute``, ``Second``, ``Micro``, ``Milli``, ``Nano``) it can be
662662
used exactly like a ``Timedelta`` - see the
@@ -670,7 +670,7 @@ used exactly like a ``Timedelta`` - see the
670670
td + Minute(15)
671671
672672
Note that some offsets (such as ``BQuarterEnd``) do not have a
673-
vectorized implementation. They can still be used but may
673+
vectorized implementation. They can still be used but may
674674
calculate signficantly slower and will raise a ``PerformanceWarning``
675675

676676
.. ipython:: python
@@ -1702,13 +1702,13 @@ the top example will fail as it contains ambiguous times and the bottom will
17021702
infer the right offset.
17031703

17041704
.. ipython:: python
1705-
:okexcept:
17061705
17071706
rng_hourly = DatetimeIndex(['11/06/2011 00:00', '11/06/2011 01:00',
17081707
'11/06/2011 01:00', '11/06/2011 02:00',
17091708
'11/06/2011 03:00'])
17101709
17111710
# This will fail as there are ambiguous times
1711+
@okexcept
17121712
rng_hourly.tz_localize('US/Eastern')
17131713
rng_hourly_eastern = rng_hourly.tz_localize('US/Eastern', ambiguous='infer')
17141714
rng_hourly_eastern.tolist()

0 commit comments

Comments
 (0)