Skip to content

Commit ec07ea8

Browse files
alphaCTzo7Gjorisvandenbossche
authored andcommitted
DOC: remove imports and use pd in docstrings (#21797)
1 parent 9e1f6fd commit ec07ea8

File tree

16 files changed

+53
-55
lines changed

16 files changed

+53
-55
lines changed

pandas/core/algorithms.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ def unique(values):
306306
>>> pd.unique(pd.Series([2] + [1] * 5))
307307
array([2, 1])
308308
309-
>>> pd.unique(Series([pd.Timestamp('20160101'),
310-
... pd.Timestamp('20160101')]))
309+
>>> pd.unique(pd.Series([pd.Timestamp('20160101'),
310+
... pd.Timestamp('20160101')]))
311311
array(['2016-01-01T00:00:00.000000000'], dtype='datetime64[ns]')
312312
313313
>>> pd.unique(pd.Series([pd.Timestamp('20160101', tz='US/Eastern'),
@@ -326,20 +326,20 @@ def unique(values):
326326
An unordered Categorical will return categories in the
327327
order of appearance.
328328
329-
>>> pd.unique(Series(pd.Categorical(list('baabc'))))
329+
>>> pd.unique(pd.Series(pd.Categorical(list('baabc'))))
330330
[b, a, c]
331331
Categories (3, object): [b, a, c]
332332
333-
>>> pd.unique(Series(pd.Categorical(list('baabc'),
334-
... categories=list('abc'))))
333+
>>> pd.unique(pd.Series(pd.Categorical(list('baabc'),
334+
... categories=list('abc'))))
335335
[b, a, c]
336336
Categories (3, object): [b, a, c]
337337
338338
An ordered Categorical preserves the category ordering.
339339
340-
>>> pd.unique(Series(pd.Categorical(list('baabc'),
341-
... categories=list('abc'),
342-
... ordered=True)))
340+
>>> pd.unique(pd.Series(pd.Categorical(list('baabc'),
341+
... categories=list('abc'),
342+
... ordered=True)))
343343
[b, a, c]
344344
Categories (3, object): [a < b < c]
345345

pandas/core/arrays/categorical.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ def _set_categories(self, categories, fastpath=False):
675675
676676
Examples
677677
--------
678-
>>> c = Categorical(['a', 'b'])
678+
>>> c = pd.Categorical(['a', 'b'])
679679
>>> c
680680
[a, b]
681681
Categories (2, object): [a, b]
@@ -883,7 +883,7 @@ def rename_categories(self, new_categories, inplace=False):
883883
884884
Examples
885885
--------
886-
>>> c = Categorical(['a', 'a', 'b'])
886+
>>> c = pd.Categorical(['a', 'a', 'b'])
887887
>>> c.rename_categories([0, 1])
888888
[0, 0, 1]
889889
Categories (2, int64): [0, 1]

pandas/core/dtypes/dtypes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class CategoricalDtype(PandasExtensionDtype, ExtensionDtype):
171171
172172
Examples
173173
--------
174-
>>> t = CategoricalDtype(categories=['b', 'a'], ordered=True)
174+
>>> t = pd.CategoricalDtype(categories=['b', 'a'], ordered=True)
175175
>>> pd.Series(['a', 'b', 'a', 'c'], dtype=t)
176176
0 a
177177
1 b

pandas/core/frame.py

-2
Original file line numberDiff line numberDiff line change
@@ -2864,8 +2864,6 @@ def query(self, expr, inplace=False, **kwargs):
28642864
28652865
Examples
28662866
--------
2867-
>>> import numpy as np
2868-
>>> import pandas as pd
28692867
>>> df = pd.DataFrame(np.random.randn(10, 2), columns=list('ab'))
28702868
>>> df.query('a > b')
28712869
>>> df[df.a > df.b] # same result as the previous expression

pandas/core/groupby/groupby.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1863,7 +1863,7 @@ def cumcount(self, ascending=True):
18631863
18641864
Essentially this is equivalent to
18651865
1866-
>>> self.apply(lambda x: Series(np.arange(len(x)), x.index))
1866+
>>> self.apply(lambda x: pd.Series(np.arange(len(x)), x.index))
18671867
18681868
Parameters
18691869
----------
@@ -2133,8 +2133,8 @@ def head(self, n=5):
21332133
Examples
21342134
--------
21352135
2136-
>>> df = DataFrame([[1, 2], [1, 4], [5, 6]],
2137-
columns=['A', 'B'])
2136+
>>> df = pd.DataFrame([[1, 2], [1, 4], [5, 6]],
2137+
columns=['A', 'B'])
21382138
>>> df.groupby('A', as_index=False).head(1)
21392139
A B
21402140
0 1 2
@@ -2160,8 +2160,8 @@ def tail(self, n=5):
21602160
Examples
21612161
--------
21622162
2163-
>>> df = DataFrame([['a', 1], ['a', 2], ['b', 1], ['b', 2]],
2164-
columns=['A', 'B'])
2163+
>>> df = pd.DataFrame([['a', 1], ['a', 2], ['b', 1], ['b', 2]],
2164+
columns=['A', 'B'])
21652165
>>> df.groupby('A').tail(1)
21662166
A B
21672167
1 a 2
@@ -3461,7 +3461,7 @@ def _selection_name(self):
34613461
Examples
34623462
--------
34633463
3464-
>>> s = Series([1, 2, 3, 4])
3464+
>>> s = pd.Series([1, 2, 3, 4])
34653465
34663466
>>> s
34673467
0 1

pandas/core/indexes/base.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1272,13 +1272,13 @@ def set_names(self, names, level=None, inplace=False):
12721272
12731273
Examples
12741274
--------
1275-
>>> Index([1, 2, 3, 4]).set_names('foo')
1275+
>>> pd.Index([1, 2, 3, 4]).set_names('foo')
12761276
Int64Index([1, 2, 3, 4], dtype='int64', name='foo')
1277-
>>> Index([1, 2, 3, 4]).set_names(['foo'])
1277+
>>> pd.Index([1, 2, 3, 4]).set_names(['foo'])
12781278
Int64Index([1, 2, 3, 4], dtype='int64', name='foo')
1279-
>>> idx = MultiIndex.from_tuples([(1, u'one'), (1, u'two'),
1280-
(2, u'one'), (2, u'two')],
1281-
names=['foo', 'bar'])
1279+
>>> idx = pd.MultiIndex.from_tuples([(1, u'one'), (1, u'two'),
1280+
(2, u'one'), (2, u'two')],
1281+
names=['foo', 'bar'])
12821282
>>> idx.set_names(['baz', 'quz'])
12831283
MultiIndex(levels=[[1, 2], [u'one', u'two']],
12841284
labels=[[0, 0, 1, 1], [0, 1, 0, 1]],
@@ -2891,8 +2891,8 @@ def symmetric_difference(self, other, result_name=None):
28912891
28922892
Examples
28932893
--------
2894-
>>> idx1 = Index([1, 2, 3, 4])
2895-
>>> idx2 = Index([2, 3, 4, 5])
2894+
>>> idx1 = pd.Index([1, 2, 3, 4])
2895+
>>> idx2 = pd.Index([2, 3, 4, 5])
28962896
>>> idx1.symmetric_difference(idx2)
28972897
Int64Index([1, 5], dtype='int64')
28982898

pandas/core/indexes/category.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ def get_loc(self, key, method=None):
425425
>>> monotonic_index.get_loc('b')
426426
slice(1, 3, None)
427427
428-
>>> non_monotonic_index = p.dCategoricalIndex(list('abcb'))
428+
>>> non_monotonic_index = pd.CategoricalIndex(list('abcb'))
429429
>>> non_monotonic_index.get_loc('b')
430430
array([False, True, False, True], dtype=bool)
431431
"""

pandas/core/indexes/multi.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,9 @@ def set_levels(self, levels, level=None, inplace=False,
346346
347347
Examples
348348
--------
349-
>>> idx = MultiIndex.from_tuples([(1, u'one'), (1, u'two'),
350-
(2, u'one'), (2, u'two')],
351-
names=['foo', 'bar'])
349+
>>> idx = pd.MultiIndex.from_tuples([(1, u'one'), (1, u'two'),
350+
(2, u'one'), (2, u'two')],
351+
names=['foo', 'bar'])
352352
>>> idx.set_levels([['a','b'], [1,2]])
353353
MultiIndex(levels=[[u'a', u'b'], [1, 2]],
354354
labels=[[0, 0, 1, 1], [0, 1, 0, 1]],
@@ -442,9 +442,9 @@ def set_labels(self, labels, level=None, inplace=False,
442442
443443
Examples
444444
--------
445-
>>> idx = MultiIndex.from_tuples([(1, u'one'), (1, u'two'),
446-
(2, u'one'), (2, u'two')],
447-
names=['foo', 'bar'])
445+
>>> idx = pd.MultiIndex.from_tuples([(1, u'one'), (1, u'two'),
446+
(2, u'one'), (2, u'two')],
447+
names=['foo', 'bar'])
448448
>>> idx.set_labels([[1,0,1,0], [0,0,1,1]])
449449
MultiIndex(levels=[[1, 2], [u'one', u'two']],
450450
labels=[[1, 0, 1, 0], [0, 0, 1, 1]],
@@ -1192,8 +1192,8 @@ def to_hierarchical(self, n_repeat, n_shuffle=1):
11921192
11931193
Examples
11941194
--------
1195-
>>> idx = MultiIndex.from_tuples([(1, u'one'), (1, u'two'),
1196-
(2, u'one'), (2, u'two')])
1195+
>>> idx = pd.MultiIndex.from_tuples([(1, u'one'), (1, u'two'),
1196+
(2, u'one'), (2, u'two')])
11971197
>>> idx.to_hierarchical(3)
11981198
MultiIndex(levels=[[1, 2], [u'one', u'two']],
11991199
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):
12551255
Examples
12561256
--------
12571257
>>> arrays = [[1, 1, 2, 2], ['red', 'blue', 'red', 'blue']]
1258-
>>> MultiIndex.from_arrays(arrays, names=('number', 'color'))
1258+
>>> pd.MultiIndex.from_arrays(arrays, names=('number', 'color'))
12591259
12601260
See Also
12611261
--------
@@ -1304,7 +1304,7 @@ def from_tuples(cls, tuples, sortorder=None, names=None):
13041304
--------
13051305
>>> tuples = [(1, u'red'), (1, u'blue'),
13061306
(2, u'red'), (2, u'blue')]
1307-
>>> MultiIndex.from_tuples(tuples, names=('number', 'color'))
1307+
>>> pd.MultiIndex.from_tuples(tuples, names=('number', 'color'))
13081308
13091309
See Also
13101310
--------
@@ -1357,8 +1357,8 @@ def from_product(cls, iterables, sortorder=None, names=None):
13571357
--------
13581358
>>> numbers = [0, 1, 2]
13591359
>>> colors = [u'green', u'purple']
1360-
>>> MultiIndex.from_product([numbers, colors],
1361-
names=['number', 'color'])
1360+
>>> pd.MultiIndex.from_product([numbers, colors],
1361+
names=['number', 'color'])
13621362
MultiIndex(levels=[[0, 1, 2], [u'green', u'purple']],
13631363
labels=[[0, 0, 1, 1, 2, 2], [0, 1, 0, 1, 0, 1]],
13641364
names=[u'number', u'color'])

pandas/core/indexes/period.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ class PeriodIndex(PeriodArrayMixin, DatelikeOps, DatetimeIndexOpsMixin,
147147
148148
Examples
149149
--------
150-
>>> idx = PeriodIndex(year=year_arr, quarter=q_arr)
150+
>>> idx = pd.PeriodIndex(year=year_arr, quarter=q_arr)
151151
152-
>>> idx2 = PeriodIndex(start='2000', end='2010', freq='A')
152+
>>> idx2 = pd.PeriodIndex(start='2000', end='2010', freq='A')
153153
154154
See Also
155155
---------

pandas/core/resample.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,8 @@ def pipe(self, func, *args, **kwargs):
188188
189189
Examples
190190
--------
191-
>>> s = Series([1,2,3,4,5],
192-
index=pd.date_range('20130101',
193-
periods=5,freq='s'))
191+
>>> s = pd.Series([1,2,3,4,5],
192+
index=pd.date_range('20130101', periods=5,freq='s'))
194193
2013-01-01 00:00:00 1
195194
2013-01-01 00:00:01 2
196195
2013-01-01 00:00:02 3

pandas/core/series.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1868,7 +1868,7 @@ def quantile(self, q=0.5, interpolation='linear'):
18681868
18691869
Examples
18701870
--------
1871-
>>> s = Series([1, 2, 3, 4])
1871+
>>> s = pd.Series([1, 2, 3, 4])
18721872
>>> s.quantile(.5)
18731873
2.5
18741874
>>> s.quantile([.25, .5, .75])
@@ -2229,8 +2229,8 @@ def combine(self, other, func, fill_value=None):
22292229
22302230
Examples
22312231
--------
2232-
>>> s1 = Series([1, 2])
2233-
>>> s2 = Series([0, 3])
2232+
>>> s1 = pd.Series([1, 2])
2233+
>>> s2 = pd.Series([0, 3])
22342234
>>> s1.combine(s2, lambda x1, x2: x1 if x1 < x2 else x2)
22352235
0 0
22362236
1 2

pandas/core/sparse/series.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ def from_coo(cls, A, dense_index=False):
795795
matrix([[ 0., 0., 1., 2.],
796796
[ 3., 0., 0., 0.],
797797
[ 0., 0., 0., 0.]])
798-
>>> ss = SparseSeries.from_coo(A)
798+
>>> ss = pd.SparseSeries.from_coo(A)
799799
>>> ss
800800
0 2 1
801801
3 2

pandas/core/strings.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ def str_extractall(arr, pat, flags=0):
961961
A pattern with one group will return a DataFrame with one column.
962962
Indices with no matches will not appear in the result.
963963
964-
>>> s = Series(["a1a2", "b1", "c1"], index=["A", "B", "C"])
964+
>>> s = pd.Series(["a1a2", "b1", "c1"], index=["A", "B", "C"])
965965
>>> s.str.extractall(r"[ab](\d)")
966966
0
967967
match
@@ -1053,13 +1053,13 @@ def str_get_dummies(arr, sep='|'):
10531053
10541054
Examples
10551055
--------
1056-
>>> Series(['a|b', 'a', 'a|c']).str.get_dummies()
1056+
>>> pd.Series(['a|b', 'a', 'a|c']).str.get_dummies()
10571057
a b c
10581058
0 1 1 0
10591059
1 1 0 0
10601060
2 1 0 1
10611061
1062-
>>> Series(['a|b', np.nan, 'a|c']).str.get_dummies()
1062+
>>> pd.Series(['a|b', np.nan, 'a|c']).str.get_dummies()
10631063
a b c
10641064
0 1 1 0
10651065
1 0 0 0
@@ -2368,6 +2368,7 @@ def rsplit(self, pat=None, n=-1, expand=False):
23682368
Examples
23692369
--------
23702370
2371+
23712372
>>> s = pd.Series(['Linda van der Berg', 'George Pitt-Rivers'])
23722373
>>> s
23732374
0 Linda van der Berg

pandas/core/window.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1825,7 +1825,7 @@ class Expanding(_Rolling_and_Expanding):
18251825
Examples
18261826
--------
18271827
1828-
>>> df = DataFrame({'B': [0, 1, 2, np.nan, 4]})
1828+
>>> df = pd.DataFrame({'B': [0, 1, 2, np.nan, 4]})
18291829
B
18301830
0 0.0
18311831
1 1.0
@@ -2109,7 +2109,7 @@ class EWM(_Rolling):
21092109
Examples
21102110
--------
21112111
2112-
>>> df = DataFrame({'B': [0, 1, 2, np.nan, 4]})
2112+
>>> df = pd.DataFrame({'B': [0, 1, 2, np.nan, 4]})
21132113
B
21142114
0 0.0
21152115
1 1.0

pandas/io/pytables.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ class HDFStore(StringMixin):
455455
Examples
456456
--------
457457
>>> bar = pd.DataFrame(np.random.randn(10, 4))
458-
>>> store = HDFStore('test.h5')
458+
>>> store = pd.HDFStore('test.h5')
459459
>>> store['foo'] = bar # write to HDF5
460460
>>> bar = store['foo'] # retrieve
461461
>>> store.close()

pandas/plotting/_misc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def scatter_matrix(frame, alpha=0.5, figsize=None, ax=None, grid=False,
4949
5050
Examples
5151
--------
52-
>>> df = DataFrame(np.random.randn(1000, 4), columns=['A','B','C','D'])
52+
>>> df = pd.DataFrame(np.random.randn(1000, 4), columns=['A','B','C','D'])
5353
>>> scatter_matrix(df, alpha=0.2)
5454
"""
5555

0 commit comments

Comments
 (0)