Skip to content

ENH: ipython_directive to warning on exceptions when building docs #635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/source/dsintro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ objects. To get started, import numpy and load pandas into your namespace:
import numpy as np
from pandas import *
randn = np.random.randn
np.set_printoptions(precision=4, suppress=True, max_columns=8)
np.set_printoptions(precision=4, suppress=True)
set_printoptions(precision=4, max_columns=8)

.. ipython:: python

Expand Down
1 change: 1 addition & 0 deletions doc/source/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ performance HDF5 format using the excellent `PyTables

.. ipython:: python
:suppress:
:okexcept:

os.remove('store.h5')

Expand Down
4 changes: 2 additions & 2 deletions doc/source/merging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ along ``axis=0``, namely the index:
.. ipython:: python

s = Series(randn(10), index=np.arange(10))
s1 = s[:5]
s2 = s[-5:]
s1 = s[:5] # note we're slicing with labels here, so 5 is included
s2 = s[6:]
s1.append(s2)

In the case of DataFrame, the indexes must be disjoint but the columns do not
Expand Down
1 change: 1 addition & 0 deletions doc/source/missing_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ an ndarray (e.g. selecting values based on some criteria). If a boolean vector
contains NAs, an exception will be generated:

.. ipython:: python
:okexcept:

reindexed = s.reindex(range(8)).fillna(0)
reindexed[crit]
Expand Down
4 changes: 2 additions & 2 deletions doc/source/visualization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ groupings. For instance,
df = DataFrame(np.random.rand(10,2), columns=['Col1', 'Col2'] )
df['X'] = Series(['A','A','A','A','A','B','B','B','B','B'])

plot.figure();
plt.figure();

@savefig box_plot_ex2.png width=4.5in
df.boxplot(by='X')
Expand All @@ -184,7 +184,7 @@ columns:
df['X'] = Series(['A','A','A','A','A','B','B','B','B','B'])
df['Y'] = Series(['A','B','A','B','A','B','A','B','A','B'])

plot.figure();
plt.figure();

@savefig box_plot_ex3.png width=4.5in
df.boxplot(column=['Col1','Col2'], by=['X','Y'])
15 changes: 11 additions & 4 deletions doc/sphinxext/ipython_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
# Globals
#-----------------------------------------------------------------------------
# for tokenizing blocks
COMMENT, INPUT, OUTPUT = range(3)
COMMENT, INPUT, OUTPUT = range(3)

#-----------------------------------------------------------------------------
# Functions and class declarations
Expand Down Expand Up @@ -196,7 +196,6 @@ def __init__(self):

self.cout = cStringIO.StringIO()


# Create config object for IPython
config = Config()
config.Global.display_banner = False
Expand All @@ -215,6 +214,7 @@ def __init__(self):

# Create and initialize ipython, but don't start its mainloop
IP = InteractiveShell.instance(config=config, profile_dir=profile)

# io.stdout redirect must be done *after* instantiating InteractiveShell
io.stdout = self.cout
io.stderr = self.cout
Expand Down Expand Up @@ -299,13 +299,15 @@ def process_input(self, data, input_prompt, lineno):
is_verbatim = decorator=='@verbatim' or self.is_verbatim
is_doctest = decorator=='@doctest' or self.is_doctest
is_suppress = decorator=='@suppress' or self.is_suppress
is_okexcept = decorator=='@okexcept' or self.is_okexcept
is_savefig = decorator is not None and \
decorator.startswith('@savefig')

input_lines = input.split('\n')

self.datacontent = data

continuation = ' %s:'%''.join(['.']*(len(str(lineno))+2))
Nc = len(continuation)

if is_savefig:
image_file, image_directive = self.process_image(decorator)
Expand Down Expand Up @@ -352,6 +354,9 @@ def process_input(self, data, input_prompt, lineno):
if not is_suppress and not is_semicolon:
ret.append(output)

if not is_okexcept and "Traceback" in output:
sys.stdout.write(output)

self.cout.truncate(0)
return (ret, input_lines, output, is_doctest, image_file,
image_directive)
Expand Down Expand Up @@ -597,6 +602,7 @@ class IpythonDirective(Directive):
'suppress' : directives.flag,
'verbatim' : directives.flag,
'doctest' : directives.flag,
'okexcept' : directives.flag,
}

shell = EmbeddedSphinxShell()
Expand Down Expand Up @@ -662,7 +668,8 @@ def run(self):
self.shell.is_suppress = 'suppress' in options
self.shell.is_doctest = 'doctest' in options
self.shell.is_verbatim = 'verbatim' in options

self.shell.is_okexcept = 'okexcept' in options
self.shell.current_content = self.content

# handle pure python code
if 'python' in self.arguments:
Expand Down
3 changes: 3 additions & 0 deletions pandas/core/daterange.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ def __getitem__(self, key):
new_index.name = self.name
return new_index
else:
if result.ndim > 1:
return result

return Index(result, name=self.name)

def summary(self):
Expand Down
22 changes: 11 additions & 11 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3546,17 +3546,17 @@ def plot(self, subplots=False, sharex=True, sharey=False, use_index=True,
empty = self[col].count() == 0
y = self[col].values if not empty else np.zeros(x.shape)

try:
if subplots:
ax = axes[i]
ax.plot(x, y, 'k', label=str(col), **kwds)
ax.legend(loc='best')
else:
ax.plot(x, y, label=str(col), **kwds)
except Exception, e:
msg = ('Unable to plot data %s vs index %s,\n'
'error was: %s' % (str(y), str(x), str(e)))
raise Exception(msg)
#try:
if subplots:
ax = axes[i]
ax.plot(x, y, 'k', label=str(col), **kwds)
ax.legend(loc='best')
else:
ax.plot(x, y, label=str(col), **kwds)
#except Exception, e:
# msg = ('Unable to plot data %s vs index %s,\n'
# 'error was: %s' % (str(y), str(x), str(e)))
# raise Exception(msg)

ax.grid(grid)

Expand Down