diff --git a/doc/source/dsintro.rst b/doc/source/dsintro.rst index a87ebce8e3d7c..9cf616a4670d7 100644 --- a/doc/source/dsintro.rst +++ b/doc/source/dsintro.rst @@ -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 diff --git a/doc/source/io.rst b/doc/source/io.rst index c83ef06bfca2f..6c7a60d2fb223 100644 --- a/doc/source/io.rst +++ b/doc/source/io.rst @@ -343,6 +343,7 @@ performance HDF5 format using the excellent `PyTables .. ipython:: python :suppress: + :okexcept: os.remove('store.h5') diff --git a/doc/source/merging.rst b/doc/source/merging.rst index 9b3c145d4f96a..874bdcf58ab33 100644 --- a/doc/source/merging.rst +++ b/doc/source/merging.rst @@ -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 diff --git a/doc/source/missing_data.rst b/doc/source/missing_data.rst index 06c9eead9be16..493492121bab2 100644 --- a/doc/source/missing_data.rst +++ b/doc/source/missing_data.rst @@ -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] diff --git a/doc/source/visualization.rst b/doc/source/visualization.rst index b4f1657fa6758..371057d82fdf1 100644 --- a/doc/source/visualization.rst +++ b/doc/source/visualization.rst @@ -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') @@ -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']) diff --git a/doc/sphinxext/ipython_directive.py b/doc/sphinxext/ipython_directive.py index 2f60b173339e4..bbc8578c2b9b1 100644 --- a/doc/sphinxext/ipython_directive.py +++ b/doc/sphinxext/ipython_directive.py @@ -90,7 +90,7 @@ # Globals #----------------------------------------------------------------------------- # for tokenizing blocks -COMMENT, INPUT, OUTPUT = range(3) +COMMENT, INPUT, OUTPUT = range(3) #----------------------------------------------------------------------------- # Functions and class declarations @@ -196,7 +196,6 @@ def __init__(self): self.cout = cStringIO.StringIO() - # Create config object for IPython config = Config() config.Global.display_banner = False @@ -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 @@ -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) @@ -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) @@ -597,6 +602,7 @@ class IpythonDirective(Directive): 'suppress' : directives.flag, 'verbatim' : directives.flag, 'doctest' : directives.flag, + 'okexcept' : directives.flag, } shell = EmbeddedSphinxShell() @@ -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: diff --git a/pandas/core/daterange.py b/pandas/core/daterange.py index bb2270697e839..408ec43c102fb 100644 --- a/pandas/core/daterange.py +++ b/pandas/core/daterange.py @@ -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): diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 046bcac674a28..0d9b0911871ea 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -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)