Skip to content

Commit af5089e

Browse files
committed
Merge pull request #10916 from jreback/de
Revert "Merge pull request #10727 from jorisvandenbossche/sphinx-traceback
2 parents f44c490 + 9f20c66 commit af5089e

File tree

7 files changed

+49
-41
lines changed

7 files changed

+49
-41
lines changed

doc/source/advanced.rst

+20-14
Original file line numberDiff line numberDiff line change
@@ -661,14 +661,18 @@ 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-
.. ipython:: python
665-
:okexcept:
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')
666673
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]
674+
In [12]: pd.concat([df2, df3]
675+
TypeError: categories must match existing categories when appending
672676
673677
.. _indexing.float64index:
674678
@@ -734,18 +738,20 @@ In float indexes, slicing using floats is allowed
734738
735739
In non-float indexes, slicing using floats will raise a ``TypeError``
736740
737-
.. ipython:: python
738-
:okexcept:
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)
739745
740-
pd.Series(range(5))[3.5]
741-
pd.Series(range(5))[3.5:4.5]
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)
742748
743749
Using a scalar float indexer will be deprecated in a future version, but is allowed for now.
744750
745-
.. ipython:: python
746-
:okwarning:
751+
.. code-block:: python
747752
748-
pd.Series(range(5))[3.0]
753+
In [3]: pd.Series(range(5))[3.0]
754+
Out[3]: 3
749755
750756
Here is a typical use-case for using this type of indexing. Imagine that you have a somewhat
751757
irregular timedelta-like indexing scheme, but the data is recorded as floats. This could for

doc/source/basics.rst

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

355-
.. ipython:: python
356-
:okexcept:
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
357359
358-
pd.Series(['foo', 'bar', 'baz']) == pd.Series(['foo', 'bar'])
359-
pd.Series(['foo', 'bar', 'baz']) == pd.Series(['foo'])
360+
In [56]: pd.Series(['foo', 'bar', 'baz']) == pd.Series(['foo'])
361+
ValueError: Series lengths must match to compare
360362
361363
Note that this is different from the numpy behavior where a comparison can
362364
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-
.. ipython:: python
147-
:okexcept:
146+
.. code-block:: python
148147
149-
s['f']
148+
>>> s['f']
149+
KeyError: 'f'
150150
151151
Using the ``get`` method, a missing label will return None or specified default:
152152

doc/source/indexing.rst

+7-5
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-
.. ipython:: python
297-
:okexcept:
296+
.. code-block:: python
298297
299-
dfl.loc[2:3]
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'>
300300
301301
String likes in slicing *can* be convertible to the type of the index and lead to natural slicing.
302302

@@ -475,11 +475,13 @@ 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-
.. ipython:: python
479-
:okexcept:
478+
.. code-block:: python
480479
481480
dfl.iloc[[4,5,6]]
481+
IndexError: positional indexers are out-of-bounds
482+
482483
dfl.iloc[:,4]
484+
IndexError: single positional indexer is out-of-bounds
483485
484486
.. _indexing.basics.partial_setting:
485487

doc/source/options.rst

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

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:
208209
209210
# 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:
17051706
17061707
rng_hourly = DatetimeIndex(['11/06/2011 00:00', '11/06/2011 01:00',
17071708
'11/06/2011 01:00', '11/06/2011 02:00',
17081709
'11/06/2011 03:00'])
17091710
17101711
# 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()

doc/sphinxext/ipython_sphinxext/ipython_directive.py

+4-10
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,10 @@ def process_input(self, data, input_prompt, lineno):
465465

466466
self.cout.seek(0)
467467
output = self.cout.read()
468+
if not is_suppress and not is_semicolon:
469+
ret.append(output)
470+
elif is_semicolon: # get spacing right
471+
ret.append('')
468472

469473
# context information
470474
filename = self.state.document.current_source
@@ -494,16 +498,6 @@ def process_input(self, data, input_prompt, lineno):
494498
sys.stdout.write(s)
495499
sys.stdout.write('<<<' + ('-' * 73) + '\n')
496500

497-
# if :okexcept: has been specified, display shorter traceback
498-
if is_okexcept and "Traceback" in output:
499-
traceback = output.split('\n\n')
500-
output = traceback[-1]
501-
502-
if not is_suppress and not is_semicolon:
503-
ret.append(output)
504-
elif is_semicolon: # get spacing right
505-
ret.append('')
506-
507501
self.cout.truncate(0)
508502
return (ret, input_lines, output, is_doctest, decorator, image_file,
509503
image_directive)

0 commit comments

Comments
 (0)