Skip to content

DOC: remove imports and use pd in docstrings #21797

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

Merged
merged 7 commits into from
Jul 8, 2018
16 changes: 8 additions & 8 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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]

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
Expand Down Expand Up @@ -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')

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
"""
Expand Down
24 changes: 12 additions & 12 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
Expand Down Expand Up @@ -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]],
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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
--------
Expand Down Expand Up @@ -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
--------
Expand Down Expand Up @@ -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'])
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------
Expand Down
5 changes: 2 additions & 3 deletions pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/sparse/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions pandas/core/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion pandas/plotting/_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
"""

Expand Down