diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index c4e4f5471c4be..6e49e8044ff25 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -306,8 +306,8 @@ def unique(values): >>> pd.unique(pd.Series([2] + [1] * 5)) array([2, 1]) - >>> pd.unique(Series([pd.Timestamp('20160101'), - ... pd.Timestamp('20160101')])) + >>> pd.unique(pd.Series([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'), @@ -326,20 +326,20 @@ 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'), - ... categories=list('abc')))) + >>> 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'), - ... categories=list('abc'), - ... ordered=True))) + >>> pd.unique(pd.Series(pd.Categorical(list('baabc'), + ... categories=list('abc'), + ... ordered=True))) [b, a, c] Categories (3, object): [a < b < c] diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 375db28a4ee5a..83fd0ab499283 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] @@ -883,7 +883,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 fa720bb38213f..1c8b1ccd0fe8d 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -2864,8 +2864,6 @@ def query(self, expr, inplace=False, **kwargs): Examples -------- - >>> import numpy as np - >>> import pandas as pd >>> 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 diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index aa4c7452bcea9..5dc1d518d1c2d 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -1863,7 +1863,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 ---------- @@ -2133,8 +2133,8 @@ def head(self, n=5): Examples -------- - >>> df = DataFrame([[1, 2], [1, 4], [5, 6]], - columns=['A', 'B']) + >>> df = pd.DataFrame([[1, 2], [1, 4], [5, 6]], + columns=['A', 'B']) >>> df.groupby('A', as_index=False).head(1) A B 0 1 2 @@ -2160,8 +2160,8 @@ def tail(self, n=5): Examples -------- - >>> df = DataFrame([['a', 1], ['a', 2], ['b', 1], ['b', 2]], - columns=['A', 'B']) + >>> df = pd.DataFrame([['a', 1], ['a', 2], ['b', 1], ['b', 2]], + columns=['A', 'B']) >>> df.groupby('A').tail(1) A B 1 a 2 @@ -3461,7 +3461,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 904aa3d4bcb03..9458f9667b551 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1272,13 +1272,13 @@ 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'), - (2, u'one'), (2, u'two')], - names=['foo', 'bar']) + >>> 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']) MultiIndex(levels=[[1, 2], [u'one', u'two']], labels=[[0, 0, 1, 1], [0, 1, 0, 1]], @@ -2891,8 +2891,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 b3bf7abe97279..a791ce1d87264 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -346,9 +346,9 @@ def set_levels(self, levels, level=None, inplace=False, Examples -------- - >>> idx = MultiIndex.from_tuples([(1, u'one'), (1, u'two'), - (2, u'one'), (2, u'two')], - names=['foo', 'bar']) + >>> 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]]) MultiIndex(levels=[[u'a', u'b'], [1, 2]], labels=[[0, 0, 1, 1], [0, 1, 0, 1]], @@ -442,9 +442,9 @@ def set_labels(self, labels, level=None, inplace=False, Examples -------- - >>> idx = MultiIndex.from_tuples([(1, u'one'), (1, u'two'), - (2, u'one'), (2, u'two')], - names=['foo', 'bar']) + >>> 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]]) MultiIndex(levels=[[1, 2], [u'one', u'two']], labels=[[1, 0, 1, 0], [0, 0, 1, 1]], @@ -1192,8 +1192,8 @@ def to_hierarchical(self, n_repeat, n_shuffle=1): Examples -------- - >>> idx = MultiIndex.from_tuples([(1, u'one'), (1, u'two'), - (2, u'one'), (2, 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']], labels=[[0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1], @@ -1255,7 +1255,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 -------- @@ -1304,7 +1304,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 -------- @@ -1357,8 +1357,8 @@ def from_product(cls, iterables, sortorder=None, names=None): -------- >>> numbers = [0, 1, 2] >>> colors = [u'green', u'purple'] - >>> MultiIndex.from_product([numbers, colors], - names=['number', 'color']) + >>> 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]], names=[u'number', u'color']) diff --git a/pandas/core/indexes/period.py b/pandas/core/indexes/period.py index 3fa525b8617c5..a0b9b25874623 100644 --- a/pandas/core/indexes/period.py +++ b/pandas/core/indexes/period.py @@ -147,9 +147,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 db3d02ad7b3d5..96f9f6c87f969 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 ecc8c266b136d..e4765c00f80fd 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -961,7 +961,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 @@ -1053,13 +1053,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 @@ -2368,6 +2368,7 @@ def rsplit(self, pat=None, n=-1, expand=False): Examples -------- + >>> s = pd.Series(['Linda van der Berg', 'George Pitt-Rivers']) >>> s 0 Linda van der Berg diff --git a/pandas/core/window.py b/pandas/core/window.py index 1029b96c58475..5e7330ed6001c 100644 --- a/pandas/core/window.py +++ b/pandas/core/window.py @@ -1825,7 +1825,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 @@ -2109,7 +2109,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 a8ae9b7edd628..be6ff898ec2b7 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) """