Skip to content

Commit a1d3ff3

Browse files
MichielStockjorisvandenbossche
authored andcommitted
DOC: resolved mistakes in examples series (pandas-dev#15625)
1 parent 2229c26 commit a1d3ff3

File tree

2 files changed

+56
-26
lines changed

2 files changed

+56
-26
lines changed

pandas/core/generic.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,7 @@ def swaplevel(self, i=-2, j=-1, axis=0):
668668
dtype: int64
669669
>>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
670670
>>> df.rename(2)
671+
Traceback (most recent call last):
671672
...
672673
TypeError: 'int' object is not callable
673674
>>> df.rename(index=str, columns={"A": "a", "B": "c"})
@@ -1115,7 +1116,7 @@ def __setstate__(self, state):
11151116
to the existing workbook. This can be used to save different
11161117
DataFrames to one workbook:
11171118
1118-
>>> writer = ExcelWriter('output.xlsx')
1119+
>>> writer = pd.ExcelWriter('output.xlsx')
11191120
>>> df1.to_excel(writer,'Sheet1')
11201121
>>> df2.to_excel(writer,'Sheet2')
11211122
>>> writer.save()
@@ -2260,7 +2261,7 @@ def sort_index(self, axis=0, level=None, ascending=True, inplace=False,
22602261
... 'response_time': [0.04, 0.02, 0.07, 0.08, 1.0]},
22612262
... index=index)
22622263
>>> df
2263-
http_status response_time
2264+
http_status response_time
22642265
Firefox 200 0.04
22652266
Chrome 200 0.02
22662267
Safari 404 0.07
@@ -2275,11 +2276,11 @@ def sort_index(self, axis=0, level=None, ascending=True, inplace=False,
22752276
... 'Chrome']
22762277
>>> df.reindex(new_index)
22772278
http_status response_time
2278-
Safari 404 0.07
2279+
Safari 404.0 0.07
22792280
Iceweasel NaN NaN
22802281
Comodo Dragon NaN NaN
2281-
IE10 404 0.08
2282-
Chrome 200 0.02
2282+
IE10 404.0 0.08
2283+
Chrome 200.0 0.02
22832284
22842285
We can fill in the missing values by passing a value to
22852286
the keyword ``fill_value``. Because the index is not monotonically

pandas/core/series.py

+50-21
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,10 @@ def values(self):
369369
Timezone aware datetime data is converted to UTC:
370370
371371
>>> pd.Series(pd.date_range('20130101', periods=3,
372-
tz='US/Eastern')).values
373-
array(['2013-01-01T00:00:00.000000000-0500',
374-
'2013-01-02T00:00:00.000000000-0500',
375-
'2013-01-03T00:00:00.000000000-0500'], dtype='datetime64[ns]')
372+
... tz='US/Eastern')).values
373+
array(['2013-01-01T05:00:00.000000000',
374+
'2013-01-02T05:00:00.000000000',
375+
'2013-01-03T05:00:00.000000000'], dtype='datetime64[ns]')
376376
377377
"""
378378
return self._data.external_values()
@@ -1550,6 +1550,8 @@ def append(self, to_append, ignore_index=False, verify_integrity=False):
15501550
With `verify_integrity` set to True:
15511551
15521552
>>> s1.append(s2, verify_integrity=True)
1553+
Traceback (most recent call last):
1554+
...
15531555
ValueError: Indexes have overlapping values: [0, 1, 2]
15541556
15551557
@@ -1919,8 +1921,19 @@ def nlargest(self, n=5, keep='first'):
19191921
--------
19201922
>>> import pandas as pd
19211923
>>> import numpy as np
1922-
>>> s = pd.Series(np.random.randn(1e6))
1924+
>>> s = pd.Series(np.random.randn(10**6))
19231925
>>> s.nlargest(10) # only sorts up to the N requested
1926+
219921 4.644710
1927+
82124 4.608745
1928+
421689 4.564644
1929+
425277 4.447014
1930+
718691 4.414137
1931+
43154 4.403520
1932+
283187 4.313922
1933+
595519 4.273635
1934+
503969 4.250236
1935+
121637 4.240952
1936+
dtype: float64
19241937
"""
19251938
return algorithms.select_n_series(self, n=n, keep=keep,
19261939
method='nlargest')
@@ -1958,8 +1971,19 @@ def nsmallest(self, n=5, keep='first'):
19581971
--------
19591972
>>> import pandas as pd
19601973
>>> import numpy as np
1961-
>>> s = pd.Series(np.random.randn(1e6))
1974+
>>> s = pd.Series(np.random.randn(10**6))
19621975
>>> s.nsmallest(10) # only sorts up to the N requested
1976+
288532 -4.954580
1977+
732345 -4.835960
1978+
64803 -4.812550
1979+
446457 -4.609998
1980+
501225 -4.483945
1981+
669476 -4.472935
1982+
973615 -4.401699
1983+
621279 -4.355126
1984+
773916 -4.347355
1985+
359919 -4.331927
1986+
dtype: float64
19631987
"""
19641988
return algorithms.select_n_series(self, n=n, keep=keep,
19651989
method='nsmallest')
@@ -2052,21 +2076,24 @@ def unstack(self, level=-1, fill_value=None):
20522076
20532077
Examples
20542078
--------
2079+
>>> s = pd.Series([1, 2, 3, 4],
2080+
... index=pd.MultiIndex.from_product([['one', 'two'], ['a', 'b']]))
20552081
>>> s
2056-
one a 1.
2057-
one b 2.
2058-
two a 3.
2059-
two b 4.
2082+
one a 1
2083+
b 2
2084+
two a 3
2085+
b 4
2086+
dtype: int64
20602087
20612088
>>> s.unstack(level=-1)
2062-
a b
2063-
one 1. 2.
2064-
two 3. 4.
2089+
a b
2090+
one 1 2
2091+
two 3 4
20652092
20662093
>>> s.unstack(level=0)
20672094
one two
2068-
a 1. 2.
2069-
b 3. 4.
2095+
a 1 3
2096+
b 2 4
20702097
20712098
Returns
20722099
-------
@@ -2102,15 +2129,16 @@ def map(self, arg, na_action=None):
21022129
21032130
>>> x = pd.Series([1,2,3], index=['one', 'two', 'three'])
21042131
>>> x
2105-
one 1
2106-
two 2
2107-
three 3
2132+
one 1
2133+
two 2
2134+
three 3
2135+
dtype: int64
21082136
21092137
>>> y = pd.Series(['foo', 'bar', 'baz'], index=[1,2,3])
21102138
>>> y
2111-
1 foo
2112-
2 bar
2113-
3 baz
2139+
1 foo
2140+
2 bar
2141+
3 baz
21142142
21152143
>>> x.map(y)
21162144
one foo
@@ -2215,6 +2243,7 @@ def apply(self, func, convert_dtype=True, args=(), **kwds):
22152243
>>> import numpy as np
22162244
>>> series = pd.Series([20, 21, 12], index=['London',
22172245
... 'New York','Helsinki'])
2246+
>>> series
22182247
London 20
22192248
New York 21
22202249
Helsinki 12

0 commit comments

Comments
 (0)