From 5bedd60caeb3ebc4278587db3627b6631690cf47 Mon Sep 17 00:00:00 2001 From: alphaCTzo7G Date: Fri, 6 Jul 2018 09:15:55 -0700 Subject: [PATCH 1/4] Changed import statements in examples in DOCs --- pandas/core/series.py | 2 +- pandas/core/sparse/series.py | 19 ++++++++++--------- pandas/io/pytables.py | 6 +++--- pandas/io/sas/sas_xport.py | 4 ++-- pandas/plotting/_core.py | 6 +++--- pandas/plotting/_misc.py | 12 ++++++------ pandas/tseries/holiday.py | 6 +++--- 7 files changed, 28 insertions(+), 27 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 93c1f866cad17..a04a281666e69 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3048,7 +3048,7 @@ def _gotitem(self, key, ndim, subset=None): Examples -------- - >>> s = Series(np.random.randn(10)) + >>> s = pd.Series(np.random.randn(10)) >>> s.agg('min') -1.3018049988556679 diff --git a/pandas/core/sparse/series.py b/pandas/core/sparse/series.py index 09d958059d355..afc3d40ef2306 100644 --- a/pandas/core/sparse/series.py +++ b/pandas/core/sparse/series.py @@ -736,15 +736,16 @@ def to_coo(self, row_levels=(0, ), column_levels=(1, ), sort_labels=False): Examples -------- - >>> from numpy import nan - >>> s = Series([3.0, nan, 1.0, 3.0, nan, nan]) - >>> s.index = MultiIndex.from_tuples([(1, 2, 'a', 0), - (1, 2, 'a', 1), - (1, 1, 'b', 0), - (1, 1, 'b', 1), - (2, 1, 'b', 0), - (2, 1, 'b', 1)], - names=['A', 'B', 'C', 'D']) + >>> import numpy as np + >>> import pandas as pd + >>> s = pd.Series([3.0, np.nan, 1.0, 3.0, np.nan, np.nan]) + >>> s.index = pd.MultiIndex.from_tuples([(1, 2, 'a', 0), + (1, 2, 'a', 1), + (1, 1, 'b', 0), + (1, 1, 'b', 1), + (2, 1, 'b', 0), + (2, 1, 'b', 1)], + names=['A', 'B', 'C', 'D']) >>> ss = s.to_sparse() >>> A, rows, columns = ss.to_coo(row_levels=['A', 'B'], column_levels=['C', 'D'], diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index f93ad425b2c6a..cfdb5d082aed8 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -454,9 +454,9 @@ class HDFStore(StringMixin): Examples -------- - >>> from pandas import DataFrame - >>> from numpy.random import randn - >>> bar = DataFrame(randn(10, 4)) + >>> import numpy as np + >>> import pandas as pd + >>> bar = pd.DataFrame(np.random.randn(10, 4)) >>> store = HDFStore('test.h5') >>> store['foo'] = bar # write to HDF5 >>> bar = store['foo'] # retrieve diff --git a/pandas/io/sas/sas_xport.py b/pandas/io/sas/sas_xport.py index 7994517b9f303..cb01b7a652157 100644 --- a/pandas/io/sas/sas_xport.py +++ b/pandas/io/sas/sas_xport.py @@ -68,11 +68,11 @@ -------- Read a SAS Xport file: ->>> df = pandas.read_sas('filename.XPT') +>>> df = pd.read_sas('filename.XPT') Read a Xport file in 10,000 line chunks: ->>> itr = pandas.read_sas('filename.XPT', chunksize=10000) +>>> itr = pd.read_sas('filename.XPT', chunksize=10000) >>> for chunk in itr: >>> do_something(chunk) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 0fb1f2b23faac..4b7d42bfb4574 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -2609,14 +2609,14 @@ def boxplot_frame_groupby(grouped, subplots=True, column=None, fontsize=None, Examples -------- - >>> import pandas + >>> import pandas as pd >>> import numpy as np >>> import itertools >>> >>> tuples = [t for t in itertools.product(range(1000), range(4))] - >>> index = pandas.MultiIndex.from_tuples(tuples, names=['lvl0', 'lvl1']) + >>> index = pd.MultiIndex.from_tuples(tuples, names=['lvl0', 'lvl1']) >>> data = np.random.randn(len(index),4) - >>> df = pandas.DataFrame(data, columns=list('ABCD'), index=index) + >>> df = pd.DataFrame(data, columns=list('ABCD'), index=index) >>> >>> grouped = df.groupby(level='lvl1') >>> boxplot_frame_groupby(grouped) diff --git a/pandas/plotting/_misc.py b/pandas/plotting/_misc.py index 150c9274d4e5c..4013d2acadb58 100644 --- a/pandas/plotting/_misc.py +++ b/pandas/plotting/_misc.py @@ -407,6 +407,7 @@ def bootstrap_plot(series, fig=None, size=50, samples=500, **kwds): :context: close-figs >>> import numpy as np + >>> import pandas as pd >>> s = pd.Series(np.random.uniform(size=100)) >>> fig = pd.plotting.bootstrap_plot(s) """ @@ -498,13 +499,12 @@ def parallel_coordinates(frame, class_column, cols=None, ax=None, color=None, Examples -------- - >>> from pandas import read_csv - >>> from pandas.tools.plotting import parallel_coordinates + >>> import pandas as pd >>> from matplotlib import pyplot as plt - >>> df = read_csv('https://raw.github.com/pandas-dev/pandas/master' - '/pandas/tests/data/iris.csv') - >>> parallel_coordinates(df, 'Name', color=('#556270', - '#4ECDC4', '#C7F464')) + >>> df = pd.read_csv('https://raw.github.com/pandas-dev/pandas/master' + '/pandas/tests/data/iris.csv') + >>> pd.plotting.parallel_coordinates(df, 'Name', + color=('#556270', '#4ECDC4', '#C7F464')) >>> plt.show() """ if axvlines_kwds is None: diff --git a/pandas/tseries/holiday.py b/pandas/tseries/holiday.py index 4e874eac9e6c6..633f2a2518962 100644 --- a/pandas/tseries/holiday.py +++ b/pandas/tseries/holiday.py @@ -142,13 +142,13 @@ class from pandas.tseries.offsets Examples -------- + >>> import pandas as pd >>> from pandas.tseries.holiday import Holiday, nearest_workday - >>> from pandas import DateOffset >>> from dateutil.relativedelta import MO >>> USMemorialDay = Holiday('MemorialDay', month=5, day=24, - offset=DateOffset(weekday=MO(1))) + offset=pd.DateOffset(weekday=MO(1))) >>> USLaborDay = Holiday('Labor Day', month=9, day=1, - offset=DateOffset(weekday=MO(1))) + offset=pd.DateOffset(weekday=MO(1))) >>> July3rd = Holiday('July 3rd', month=7, day=3,) >>> NewYears = Holiday('New Years Day', month=1, day=1, observance=nearest_workday), From f3ee814706a71e548ce3ecb4e9db6424c7917bcc Mon Sep 17 00:00:00 2001 From: alphaCTzo7G Date: Sat, 7 Jul 2018 11:16:42 -0700 Subject: [PATCH 2/4] Remove `import numpy as np` and `import pandas as pd` statements --- pandas/core/frame.py | 1 - pandas/core/generic.py | 1 - pandas/core/groupby/groupby.py | 2 -- pandas/core/panel.py | 1 - pandas/core/reshape/melt.py | 3 --- pandas/core/reshape/reshape.py | 2 -- pandas/core/series.py | 6 ------ pandas/core/sparse/series.py | 2 -- pandas/core/tools/numeric.py | 1 - pandas/io/pytables.py | 2 -- pandas/io/stata.py | 4 ---- pandas/plotting/_core.py | 3 --- pandas/plotting/_misc.py | 3 --- pandas/tseries/holiday.py | 1 - 14 files changed, 32 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 7b5f310315485..d192b32b26bdb 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -5643,7 +5643,6 @@ def unstack(self, level=-1, fill_value=None): Examples -------- - >>> import pandas as pd >>> df = pd.DataFrame({'A': {0: 'a', 1: 'b', 2: 'c'}, ... 'B': {0: 1, 1: 3, 2: 5}, ... 'C': {0: 2, 1: 4, 2: 6}}) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 818dd1b408518..251bdcf76355a 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4824,7 +4824,6 @@ def ftypes(self): Examples -------- - >>> import numpy as np >>> arr = np.random.RandomState(0).randn(100, 4) >>> arr[arr < .8] = np.nan >>> pd.DataFrame(arr).ftypes diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index c69d7f43de8ea..e973608507a29 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -3704,7 +3704,6 @@ def filter(self, func, dropna=True, *args, **kwargs): # noqa Examples -------- - >>> import pandas as pd >>> df = pd.DataFrame({'A' : ['foo', 'bar', 'foo', 'bar', ... 'foo', 'bar'], ... 'B' : [1, 2, 3, 4, 5, 6], @@ -4538,7 +4537,6 @@ def filter(self, func, dropna=True, *args, **kwargs): # noqa Examples -------- - >>> import pandas as pd >>> df = pd.DataFrame({'A' : ['foo', 'bar', 'foo', 'bar', ... 'foo', 'bar'], ... 'B' : [1, 2, 3, 4, 5, 6], diff --git a/pandas/core/panel.py b/pandas/core/panel.py index e012819812f6b..9f08fabef8cc7 100644 --- a/pandas/core/panel.py +++ b/pandas/core/panel.py @@ -89,7 +89,6 @@ def panel_index(time, panels, names=None): or - >>> import numpy as np >>> years = np.repeat(range(1960,1963), 3) >>> panels = np.tile(['A', 'B', 'C'], 3) >>> panel_idx = panel_index(years, panels) diff --git a/pandas/core/reshape/melt.py b/pandas/core/reshape/melt.py index b3e3c52f6e363..f4b96c8f1ca49 100644 --- a/pandas/core/reshape/melt.py +++ b/pandas/core/reshape/melt.py @@ -103,7 +103,6 @@ def lreshape(data, groups, dropna=True, label=None): Examples -------- - >>> import pandas as pd >>> data = pd.DataFrame({'hr1': [514, 573], 'hr2': [545, 526], ... 'team': ['Red Sox', 'Yankees'], ... 'year1': [2007, 2007], 'year2': [2008, 2008]}) @@ -217,8 +216,6 @@ def wide_to_long(df, stubnames, i, j, sep="", suffix=r'\d+'): Examples -------- - >>> import pandas as pd - >>> import numpy as np >>> np.random.seed(123) >>> df = pd.DataFrame({"A1970" : {0 : "a", 1 : "b", 2 : "c"}, ... "A1980" : {0 : "d", 1 : "e", 2 : "f"}, diff --git a/pandas/core/reshape/reshape.py b/pandas/core/reshape/reshape.py index 3d9e84954a63b..089634fb8e315 100644 --- a/pandas/core/reshape/reshape.py +++ b/pandas/core/reshape/reshape.py @@ -58,7 +58,6 @@ class _Unstacker(object): Examples -------- - >>> import pandas as pd >>> index = pd.MultiIndex.from_tuples([('one', 'a'), ('one', 'b'), ... ('two', 'a'), ('two', 'b')]) >>> s = pd.Series(np.arange(1, 5, dtype=np.int64), index=index) @@ -771,7 +770,6 @@ def get_dummies(data, prefix=None, prefix_sep='_', dummy_na=False, Examples -------- - >>> import pandas as pd >>> s = pd.Series(list('abca')) >>> pd.get_dummies(s) diff --git a/pandas/core/series.py b/pandas/core/series.py index a04a281666e69..10a08dc5e0cde 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2749,8 +2749,6 @@ def nlargest(self, n=5, keep='first'): Examples -------- - >>> import pandas as pd - >>> import numpy as np >>> s = pd.Series(np.random.randn(10**6)) >>> s.nlargest(10) # only sorts up to the N requested 219921 4.644710 @@ -2796,8 +2794,6 @@ def nsmallest(self, n=5, keep='first'): Examples -------- - >>> import pandas as pd - >>> import numpy as np >>> s = pd.Series(np.random.randn(10**6)) >>> s.nsmallest(10) # only sorts up to the N requested 288532 -4.954580 @@ -3127,8 +3123,6 @@ def apply(self, func, convert_dtype=True, args=(), **kwds): Create a series with typical summer temperatures for each city. - >>> import pandas as pd - >>> import numpy as np >>> series = pd.Series([20, 21, 12], index=['London', ... 'New York','Helsinki']) >>> series diff --git a/pandas/core/sparse/series.py b/pandas/core/sparse/series.py index afc3d40ef2306..f6428568a6383 100644 --- a/pandas/core/sparse/series.py +++ b/pandas/core/sparse/series.py @@ -736,8 +736,6 @@ def to_coo(self, row_levels=(0, ), column_levels=(1, ), sort_labels=False): Examples -------- - >>> import numpy as np - >>> import pandas as pd >>> s = pd.Series([3.0, np.nan, 1.0, 3.0, np.nan, np.nan]) >>> s.index = pd.MultiIndex.from_tuples([(1, 2, 'a', 0), (1, 2, 'a', 1), diff --git a/pandas/core/tools/numeric.py b/pandas/core/tools/numeric.py index ebe135dfb184c..f1d13ccf36cf6 100644 --- a/pandas/core/tools/numeric.py +++ b/pandas/core/tools/numeric.py @@ -58,7 +58,6 @@ def to_numeric(arg, errors='raise', downcast=None): -------- Take separate series and convert to numeric, coercing when told to - >>> import pandas as pd >>> s = pd.Series(['1.0', '2', -3]) >>> pd.to_numeric(s) 0 1.0 diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index cfdb5d082aed8..374114d2b014b 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -454,8 +454,6 @@ class HDFStore(StringMixin): Examples -------- - >>> import numpy as np - >>> import pandas as pd >>> bar = pd.DataFrame(np.random.randn(10, 4)) >>> store = HDFStore('test.h5') >>> store['foo'] = bar # write to HDF5 diff --git a/pandas/io/stata.py b/pandas/io/stata.py index b2a5bec2a4837..c3af5d214317a 100644 --- a/pandas/io/stata.py +++ b/pandas/io/stata.py @@ -102,7 +102,6 @@ -------- Read a Stata dta file: ->>> import pandas as pd >>> df = pd.read_stata('filename.dta') Read a Stata dta file in 10,000 line chunks: @@ -216,7 +215,6 @@ def _stata_elapsed_date_to_datetime_vec(dates, fmt): Examples -------- - >>> import pandas as pd >>> dates = pd.Series([52]) >>> _stata_elapsed_date_to_datetime_vec(dates , "%tw") 0 1961-01-01 @@ -1946,7 +1944,6 @@ class StataWriter(StataParser): Examples -------- - >>> import pandas as pd >>> data = pd.DataFrame([[1.0, 1]], columns=['a', 'b']) >>> writer = StataWriter('./data_file.dta', data) >>> writer.write_file() @@ -2709,7 +2706,6 @@ class StataWriter117(StataWriter): Examples -------- - >>> import pandas as pd >>> from pandas.io.stata import StataWriter117 >>> data = pd.DataFrame([[1.0, 1, 'a']], columns=['a', 'b', 'c']) >>> writer = StataWriter117('./data_file.dta', data) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 4b7d42bfb4574..842da838b4b83 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -2609,10 +2609,7 @@ def boxplot_frame_groupby(grouped, subplots=True, column=None, fontsize=None, Examples -------- - >>> import pandas as pd - >>> import numpy as np >>> import itertools - >>> >>> tuples = [t for t in itertools.product(range(1000), range(4))] >>> index = pd.MultiIndex.from_tuples(tuples, names=['lvl0', 'lvl1']) >>> data = np.random.randn(len(index),4) diff --git a/pandas/plotting/_misc.py b/pandas/plotting/_misc.py index 4013d2acadb58..84e545a3ca2f2 100644 --- a/pandas/plotting/_misc.py +++ b/pandas/plotting/_misc.py @@ -406,8 +406,6 @@ def bootstrap_plot(series, fig=None, size=50, samples=500, **kwds): .. plot:: :context: close-figs - >>> import numpy as np - >>> import pandas as pd >>> s = pd.Series(np.random.uniform(size=100)) >>> fig = pd.plotting.bootstrap_plot(s) """ @@ -499,7 +497,6 @@ def parallel_coordinates(frame, class_column, cols=None, ax=None, color=None, Examples -------- - >>> import pandas as pd >>> from matplotlib import pyplot as plt >>> df = pd.read_csv('https://raw.github.com/pandas-dev/pandas/master' '/pandas/tests/data/iris.csv') diff --git a/pandas/tseries/holiday.py b/pandas/tseries/holiday.py index 633f2a2518962..33dcf6d64b302 100644 --- a/pandas/tseries/holiday.py +++ b/pandas/tseries/holiday.py @@ -142,7 +142,6 @@ class from pandas.tseries.offsets Examples -------- - >>> import pandas as pd >>> from pandas.tseries.holiday import Holiday, nearest_workday >>> from dateutil.relativedelta import MO >>> USMemorialDay = Holiday('MemorialDay', month=5, day=24, From bc25a86396ec027ca4359e1933ad00c2b372df8f Mon Sep 17 00:00:00 2001 From: alphaCTzo7G Date: Sat, 7 Jul 2018 11:33:04 -0700 Subject: [PATCH 3/4] Corrects reference to DataStructures in example code --- pandas/core/algorithms.py | 8 ++++---- pandas/core/arrays/categorical.py | 4 ++-- pandas/core/dtypes/dtypes.py | 2 +- pandas/core/frame.py | 8 +++----- pandas/core/groupby/groupby.py | 8 ++++---- pandas/core/indexes/base.py | 10 +++++----- pandas/core/indexes/category.py | 2 +- pandas/core/indexes/multi.py | 12 ++++++------ pandas/core/indexes/period.py | 4 ++-- pandas/core/resample.py | 5 ++--- pandas/core/series.py | 6 +++--- pandas/core/sparse/series.py | 2 +- pandas/core/strings.py | 10 +++++----- pandas/core/window.py | 4 ++-- pandas/io/pytables.py | 2 +- pandas/plotting/_misc.py | 2 +- 16 files changed, 43 insertions(+), 46 deletions(-) diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index c4e4f5471c4be..7f63481ac61ba 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -306,7 +306,7 @@ def unique(values): >>> pd.unique(pd.Series([2] + [1] * 5)) array([2, 1]) - >>> pd.unique(Series([pd.Timestamp('20160101'), + >>> pd.unique(pd.Series([pd.Timestamp('20160101'), ... pd.Timestamp('20160101')])) array(['2016-01-01T00:00:00.000000000'], dtype='datetime64[ns]') @@ -326,18 +326,18 @@ def unique(values): An unordered Categorical will return categories in the order of appearance. - >>> pd.unique(Series(pd.Categorical(list('baabc')))) + >>> pd.unique(pd.Series(pd.Categorical(list('baabc')))) [b, a, c] Categories (3, object): [b, a, c] - >>> pd.unique(Series(pd.Categorical(list('baabc'), + >>> pd.unique(pd.Series(pd.Categorical(list('baabc'), ... categories=list('abc')))) [b, a, c] Categories (3, object): [b, a, c] An ordered Categorical preserves the category ordering. - >>> pd.unique(Series(pd.Categorical(list('baabc'), + >>> pd.unique(pd.Series(pd.Categorical(list('baabc'), ... categories=list('abc'), ... ordered=True))) [b, a, c] diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 0252b5b52ae94..caaebe352ecac 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -675,7 +675,7 @@ def _set_categories(self, categories, fastpath=False): Examples -------- - >>> c = Categorical(['a', 'b']) + >>> c = pd.Categorical(['a', 'b']) >>> c [a, b] Categories (2, object): [a, b] @@ -950,7 +950,7 @@ def rename_categories(self, new_categories, inplace=False): Examples -------- - >>> c = Categorical(['a', 'a', 'b']) + >>> c = pd.Categorical(['a', 'a', 'b']) >>> c.rename_categories([0, 1]) [0, 0, 1] Categories (2, int64): [0, 1] diff --git a/pandas/core/dtypes/dtypes.py b/pandas/core/dtypes/dtypes.py index de837efc235a0..4f7e9136022a5 100644 --- a/pandas/core/dtypes/dtypes.py +++ b/pandas/core/dtypes/dtypes.py @@ -171,7 +171,7 @@ class CategoricalDtype(PandasExtensionDtype, ExtensionDtype): Examples -------- - >>> t = CategoricalDtype(categories=['b', 'a'], ordered=True) + >>> t = pd.CategoricalDtype(categories=['b', 'a'], ordered=True) >>> pd.Series(['a', 'b', 'a', 'c'], dtype=t) 0 a 1 b diff --git a/pandas/core/frame.py b/pandas/core/frame.py index d192b32b26bdb..bad9cb0084f82 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -2841,9 +2841,7 @@ def query(self, expr, inplace=False, **kwargs): Examples -------- - >>> from numpy.random import randn - >>> from pandas import DataFrame - >>> df = pd.DataFrame(randn(10, 2), columns=list('ab')) + >>> df = pd.DataFrame(np.random.randn(10, 2), columns=list('ab')) >>> df.query('a > b') >>> df[df.a > df.b] # same result as the previous expression """ @@ -4902,8 +4900,8 @@ def combine(self, other, func, fill_value=None, overwrite=True): Examples -------- - >>> df1 = DataFrame({'A': [0, 0], 'B': [4, 4]}) - >>> df2 = DataFrame({'A': [1, 1], 'B': [3, 3]}) + >>> df1 = pd.DataFrame({'A': [0, 0], 'B': [4, 4]}) + >>> df2 = pd.DataFrame({'A': [1, 1], 'B': [3, 3]}) >>> df1.combine(df2, lambda s1, s2: s1 if s1.sum() < s2.sum() else s2) A B 0 0 3 diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index e973608507a29..81b52680f7fd2 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -1824,7 +1824,7 @@ def cumcount(self, ascending=True): Essentially this is equivalent to - >>> self.apply(lambda x: Series(np.arange(len(x)), x.index)) + >>> self.apply(lambda x: pd.Series(np.arange(len(x)), x.index)) Parameters ---------- @@ -2094,7 +2094,7 @@ def head(self, n=5): Examples -------- - >>> df = DataFrame([[1, 2], [1, 4], [5, 6]], + >>> df = pd.DataFrame([[1, 2], [1, 4], [5, 6]], columns=['A', 'B']) >>> df.groupby('A', as_index=False).head(1) A B @@ -2121,7 +2121,7 @@ def tail(self, n=5): Examples -------- - >>> df = DataFrame([['a', 1], ['a', 2], ['b', 1], ['b', 2]], + >>> df = pd.DataFrame([['a', 1], ['a', 2], ['b', 1], ['b', 2]], columns=['A', 'B']) >>> df.groupby('A').tail(1) A B @@ -3430,7 +3430,7 @@ def _selection_name(self): Examples -------- - >>> s = Series([1, 2, 3, 4]) + >>> s = pd.Series([1, 2, 3, 4]) >>> s 0 1 diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index ba60d10099948..a55d4256edfe6 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1272,11 +1272,11 @@ def set_names(self, names, level=None, inplace=False): Examples -------- - >>> Index([1, 2, 3, 4]).set_names('foo') + >>> pd.Index([1, 2, 3, 4]).set_names('foo') Int64Index([1, 2, 3, 4], dtype='int64', name='foo') - >>> Index([1, 2, 3, 4]).set_names(['foo']) + >>> pd.Index([1, 2, 3, 4]).set_names(['foo']) Int64Index([1, 2, 3, 4], dtype='int64', name='foo') - >>> idx = MultiIndex.from_tuples([(1, u'one'), (1, u'two'), + >>> idx = pd.MultiIndex.from_tuples([(1, u'one'), (1, u'two'), (2, u'one'), (2, u'two')], names=['foo', 'bar']) >>> idx.set_names(['baz', 'quz']) @@ -2844,8 +2844,8 @@ def symmetric_difference(self, other, result_name=None): Examples -------- - >>> idx1 = Index([1, 2, 3, 4]) - >>> idx2 = Index([2, 3, 4, 5]) + >>> idx1 = pd.Index([1, 2, 3, 4]) + >>> idx2 = pd.Index([2, 3, 4, 5]) >>> idx1.symmetric_difference(idx2) Int64Index([1, 5], dtype='int64') diff --git a/pandas/core/indexes/category.py b/pandas/core/indexes/category.py index 8472d5fd49bd9..7c63b3c667c01 100644 --- a/pandas/core/indexes/category.py +++ b/pandas/core/indexes/category.py @@ -425,7 +425,7 @@ def get_loc(self, key, method=None): >>> monotonic_index.get_loc('b') slice(1, 3, None) - >>> non_monotonic_index = p.dCategoricalIndex(list('abcb')) + >>> non_monotonic_index = pd.CategoricalIndex(list('abcb')) >>> non_monotonic_index.get_loc('b') array([False, True, False, True], dtype=bool) """ diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index ab1a5783a4045..281af5b57ba2d 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -345,7 +345,7 @@ def set_levels(self, levels, level=None, inplace=False, Examples -------- - >>> idx = MultiIndex.from_tuples([(1, u'one'), (1, u'two'), + >>> idx = pd.MultiIndex.from_tuples([(1, u'one'), (1, u'two'), (2, u'one'), (2, u'two')], names=['foo', 'bar']) >>> idx.set_levels([['a','b'], [1,2]]) @@ -441,7 +441,7 @@ def set_labels(self, labels, level=None, inplace=False, Examples -------- - >>> idx = MultiIndex.from_tuples([(1, u'one'), (1, u'two'), + >>> idx = pd.MultiIndex.from_tuples([(1, u'one'), (1, u'two'), (2, u'one'), (2, u'two')], names=['foo', 'bar']) >>> idx.set_labels([[1,0,1,0], [0,0,1,1]]) @@ -1191,7 +1191,7 @@ def to_hierarchical(self, n_repeat, n_shuffle=1): Examples -------- - >>> idx = MultiIndex.from_tuples([(1, u'one'), (1, u'two'), + >>> idx = pd.MultiIndex.from_tuples([(1, u'one'), (1, u'two'), (2, u'one'), (2, u'two')]) >>> idx.to_hierarchical(3) MultiIndex(levels=[[1, 2], [u'one', u'two']], @@ -1254,7 +1254,7 @@ def from_arrays(cls, arrays, sortorder=None, names=None): Examples -------- >>> arrays = [[1, 1, 2, 2], ['red', 'blue', 'red', 'blue']] - >>> MultiIndex.from_arrays(arrays, names=('number', 'color')) + >>> pd.MultiIndex.from_arrays(arrays, names=('number', 'color')) See Also -------- @@ -1303,7 +1303,7 @@ def from_tuples(cls, tuples, sortorder=None, names=None): -------- >>> tuples = [(1, u'red'), (1, u'blue'), (2, u'red'), (2, u'blue')] - >>> MultiIndex.from_tuples(tuples, names=('number', 'color')) + >>> pd.MultiIndex.from_tuples(tuples, names=('number', 'color')) See Also -------- @@ -1356,7 +1356,7 @@ def from_product(cls, iterables, sortorder=None, names=None): -------- >>> numbers = [0, 1, 2] >>> colors = [u'green', u'purple'] - >>> MultiIndex.from_product([numbers, colors], + >>> pd.MultiIndex.from_product([numbers, colors], names=['number', 'color']) MultiIndex(levels=[[0, 1, 2], [u'green', u'purple']], labels=[[0, 0, 1, 1, 2, 2], [0, 1, 0, 1, 0, 1]], diff --git a/pandas/core/indexes/period.py b/pandas/core/indexes/period.py index 143cb8cd3ff6e..768f1334307b5 100644 --- a/pandas/core/indexes/period.py +++ b/pandas/core/indexes/period.py @@ -190,9 +190,9 @@ class PeriodIndex(PeriodArrayMixin, DatelikeOps, DatetimeIndexOpsMixin, Examples -------- - >>> idx = PeriodIndex(year=year_arr, quarter=q_arr) + >>> idx = pd.PeriodIndex(year=year_arr, quarter=q_arr) - >>> idx2 = PeriodIndex(start='2000', end='2010', freq='A') + >>> idx2 = pd.PeriodIndex(start='2000', end='2010', freq='A') See Also --------- diff --git a/pandas/core/resample.py b/pandas/core/resample.py index 0b0fcacc1bc48..5c3135fe14b51 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -188,9 +188,8 @@ def pipe(self, func, *args, **kwargs): Examples -------- - >>> s = Series([1,2,3,4,5], - index=pd.date_range('20130101', - periods=5,freq='s')) + >>> s = pd.Series([1,2,3,4,5], + index=pd.date_range('20130101', periods=5,freq='s')) 2013-01-01 00:00:00 1 2013-01-01 00:00:01 2 2013-01-01 00:00:02 3 diff --git a/pandas/core/series.py b/pandas/core/series.py index 10a08dc5e0cde..a5c140019bf54 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1868,7 +1868,7 @@ def quantile(self, q=0.5, interpolation='linear'): Examples -------- - >>> s = Series([1, 2, 3, 4]) + >>> s = pd.Series([1, 2, 3, 4]) >>> s.quantile(.5) 2.5 >>> s.quantile([.25, .5, .75]) @@ -2229,8 +2229,8 @@ def combine(self, other, func, fill_value=None): Examples -------- - >>> s1 = Series([1, 2]) - >>> s2 = Series([0, 3]) + >>> s1 = pd.Series([1, 2]) + >>> s2 = pd.Series([0, 3]) >>> s1.combine(s2, lambda x1, x2: x1 if x1 < x2 else x2) 0 0 1 2 diff --git a/pandas/core/sparse/series.py b/pandas/core/sparse/series.py index f6428568a6383..fb337d71fcf8d 100644 --- a/pandas/core/sparse/series.py +++ b/pandas/core/sparse/series.py @@ -795,7 +795,7 @@ def from_coo(cls, A, dense_index=False): matrix([[ 0., 0., 1., 2.], [ 3., 0., 0., 0.], [ 0., 0., 0., 0.]]) - >>> ss = SparseSeries.from_coo(A) + >>> ss = pd.SparseSeries.from_coo(A) >>> ss 0 2 1 3 2 diff --git a/pandas/core/strings.py b/pandas/core/strings.py index b27cfdfe3f1bd..f39bf7bc2eda8 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -875,7 +875,7 @@ def str_extract(arr, pat, flags=0, expand=True): A pattern with two groups will return a DataFrame with two columns. Non-matches will be NaN. - >>> s = Series(['a1', 'b2', 'c3']) + >>> s = pd.Series(['a1', 'b2', 'c3']) >>> s.str.extract(r'([ab])(\d)') 0 1 0 a 1 @@ -959,7 +959,7 @@ def str_extractall(arr, pat, flags=0): A pattern with one group will return a DataFrame with one column. Indices with no matches will not appear in the result. - >>> s = Series(["a1a2", "b1", "c1"], index=["A", "B", "C"]) + >>> s = pd.Series(["a1a2", "b1", "c1"], index=["A", "B", "C"]) >>> s.str.extractall(r"[ab](\d)") 0 match @@ -1051,13 +1051,13 @@ def str_get_dummies(arr, sep='|'): Examples -------- - >>> Series(['a|b', 'a', 'a|c']).str.get_dummies() + >>> pd.Series(['a|b', 'a', 'a|c']).str.get_dummies() a b c 0 1 1 0 1 1 0 0 2 1 0 1 - >>> Series(['a|b', np.nan, 'a|c']).str.get_dummies() + >>> pd.Series(['a|b', np.nan, 'a|c']).str.get_dummies() a b c 0 1 1 0 1 0 0 0 @@ -2362,7 +2362,7 @@ def rsplit(self, pat=None, n=-1, expand=False): Examples -------- - >>> s = Series(['A_B_C', 'D_E_F', 'X']) + >>> s = pd.Series(['A_B_C', 'D_E_F', 'X']) 0 A_B_C 1 D_E_F 2 X diff --git a/pandas/core/window.py b/pandas/core/window.py index f089e402261db..3e337d1196413 100644 --- a/pandas/core/window.py +++ b/pandas/core/window.py @@ -1732,7 +1732,7 @@ class Expanding(_Rolling_and_Expanding): Examples -------- - >>> df = DataFrame({'B': [0, 1, 2, np.nan, 4]}) + >>> df = pd.DataFrame({'B': [0, 1, 2, np.nan, 4]}) B 0 0.0 1 1.0 @@ -2017,7 +2017,7 @@ class EWM(_Rolling): Examples -------- - >>> df = DataFrame({'B': [0, 1, 2, np.nan, 4]}) + >>> df = pd.DataFrame({'B': [0, 1, 2, np.nan, 4]}) B 0 0.0 1 1.0 diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 374114d2b014b..6b5714bcadba1 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -455,7 +455,7 @@ class HDFStore(StringMixin): Examples -------- >>> bar = pd.DataFrame(np.random.randn(10, 4)) - >>> store = HDFStore('test.h5') + >>> store = pd.HDFStore('test.h5') >>> store['foo'] = bar # write to HDF5 >>> bar = store['foo'] # retrieve >>> store.close() diff --git a/pandas/plotting/_misc.py b/pandas/plotting/_misc.py index 84e545a3ca2f2..47858d7651ce0 100644 --- a/pandas/plotting/_misc.py +++ b/pandas/plotting/_misc.py @@ -49,7 +49,7 @@ def scatter_matrix(frame, alpha=0.5, figsize=None, ax=None, grid=False, Examples -------- - >>> df = DataFrame(np.random.randn(1000, 4), columns=['A','B','C','D']) + >>> df = pd.DataFrame(np.random.randn(1000, 4), columns=['A','B','C','D']) >>> scatter_matrix(df, alpha=0.2) """ From c27b5f45ee4be493bb76995d319a073026f6acf5 Mon Sep 17 00:00:00 2001 From: alphaCTzo7G Date: Sat, 7 Jul 2018 11:33:04 -0700 Subject: [PATCH 4/4] DOC: Corrects allignment of code in example code --- pandas/core/algorithms.py | 8 ++++---- pandas/core/groupby/groupby.py | 4 ++-- pandas/core/indexes/base.py | 4 ++-- pandas/core/indexes/multi.py | 12 ++++++------ 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index 7f63481ac61ba..6e49e8044ff25 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -307,7 +307,7 @@ def unique(values): array([2, 1]) >>> pd.unique(pd.Series([pd.Timestamp('20160101'), - ... pd.Timestamp('20160101')])) + ... pd.Timestamp('20160101')])) array(['2016-01-01T00:00:00.000000000'], dtype='datetime64[ns]') >>> pd.unique(pd.Series([pd.Timestamp('20160101', tz='US/Eastern'), @@ -331,15 +331,15 @@ def unique(values): Categories (3, object): [b, a, c] >>> pd.unique(pd.Series(pd.Categorical(list('baabc'), - ... categories=list('abc')))) + ... categories=list('abc')))) [b, a, c] Categories (3, object): [b, a, c] An ordered Categorical preserves the category ordering. >>> pd.unique(pd.Series(pd.Categorical(list('baabc'), - ... categories=list('abc'), - ... ordered=True))) + ... categories=list('abc'), + ... ordered=True))) [b, a, c] Categories (3, object): [a < b < c] diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index ac7c51cec986b..e14a2e0b7a128 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -2095,7 +2095,7 @@ def head(self, n=5): -------- >>> df = pd.DataFrame([[1, 2], [1, 4], [5, 6]], - columns=['A', 'B']) + columns=['A', 'B']) >>> df.groupby('A', as_index=False).head(1) A B 0 1 2 @@ -2122,7 +2122,7 @@ def tail(self, n=5): -------- >>> df = pd.DataFrame([['a', 1], ['a', 2], ['b', 1], ['b', 2]], - columns=['A', 'B']) + columns=['A', 'B']) >>> df.groupby('A').tail(1) A B 1 a 2 diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 3767bc0a1f8ce..5025af9267d91 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1277,8 +1277,8 @@ def set_names(self, names, level=None, inplace=False): >>> pd.Index([1, 2, 3, 4]).set_names(['foo']) Int64Index([1, 2, 3, 4], dtype='int64', name='foo') >>> idx = pd.MultiIndex.from_tuples([(1, u'one'), (1, u'two'), - (2, u'one'), (2, u'two')], - names=['foo', 'bar']) + (2, u'one'), (2, u'two')], + names=['foo', 'bar']) >>> idx.set_names(['baz', 'quz']) MultiIndex(levels=[[1, 2], [u'one', u'two']], labels=[[0, 0, 1, 1], [0, 1, 0, 1]], diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 4bb241a0e61f4..72569bbbab454 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -346,8 +346,8 @@ def set_levels(self, levels, level=None, inplace=False, Examples -------- >>> idx = pd.MultiIndex.from_tuples([(1, u'one'), (1, u'two'), - (2, u'one'), (2, u'two')], - names=['foo', 'bar']) + (2, u'one'), (2, u'two')], + names=['foo', 'bar']) >>> idx.set_levels([['a','b'], [1,2]]) MultiIndex(levels=[[u'a', u'b'], [1, 2]], labels=[[0, 0, 1, 1], [0, 1, 0, 1]], @@ -442,8 +442,8 @@ def set_labels(self, labels, level=None, inplace=False, Examples -------- >>> idx = pd.MultiIndex.from_tuples([(1, u'one'), (1, u'two'), - (2, u'one'), (2, u'two')], - names=['foo', 'bar']) + (2, u'one'), (2, u'two')], + names=['foo', 'bar']) >>> idx.set_labels([[1,0,1,0], [0,0,1,1]]) MultiIndex(levels=[[1, 2], [u'one', u'two']], labels=[[1, 0, 1, 0], [0, 0, 1, 1]], @@ -1192,7 +1192,7 @@ def to_hierarchical(self, n_repeat, n_shuffle=1): Examples -------- >>> idx = pd.MultiIndex.from_tuples([(1, u'one'), (1, u'two'), - (2, u'one'), (2, u'two')]) + (2, u'one'), (2, u'two')]) >>> idx.to_hierarchical(3) MultiIndex(levels=[[1, 2], [u'one', u'two']], labels=[[0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1], @@ -1357,7 +1357,7 @@ def from_product(cls, iterables, sortorder=None, names=None): >>> numbers = [0, 1, 2] >>> colors = [u'green', u'purple'] >>> pd.MultiIndex.from_product([numbers, colors], - names=['number', 'color']) + names=['number', 'color']) MultiIndex(levels=[[0, 1, 2], [u'green', u'purple']], labels=[[0, 0, 1, 1, 2, 2], [0, 1, 0, 1, 0, 1]], names=[u'number', u'color'])