Skip to content

Commit 14c811f

Browse files
authored
DOC: Fix some doctest errors (#50494)
1 parent bf731cc commit 14c811f

File tree

4 files changed

+59
-50
lines changed

4 files changed

+59
-50
lines changed

pandas/core/frame.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3477,7 +3477,7 @@ def transpose(self, *args, copy: bool = False) -> DataFrame:
34773477
0 1 3
34783478
1 2 4
34793479
3480-
>>> df1_transposed = df1.T # or df1.transpose()
3480+
>>> df1_transposed = df1.T # or df1.transpose()
34813481
>>> df1_transposed
34823482
0 1
34833483
col1 1 2
@@ -3507,7 +3507,7 @@ def transpose(self, *args, copy: bool = False) -> DataFrame:
35073507
0 Alice 9.5 False 0
35083508
1 Bob 8.0 True 0
35093509
3510-
>>> df2_transposed = df2.T # or df2.transpose()
3510+
>>> df2_transposed = df2.T # or df2.transpose()
35113511
>>> df2_transposed
35123512
0 1
35133513
name Alice Bob
@@ -4744,7 +4744,7 @@ def assign(self, **kwargs) -> DataFrame:
47444744
of the columns depends on another one defined within the same assign:
47454745
47464746
>>> df.assign(temp_f=lambda x: x['temp_c'] * 9 / 5 + 32,
4747-
... temp_k=lambda x: (x['temp_f'] + 459.67) * 5 / 9)
4747+
... temp_k=lambda x: (x['temp_f'] + 459.67) * 5 / 9)
47484748
temp_c temp_f temp_k
47494749
Portland 17.0 62.6 290.15
47504750
Berkeley 25.0 77.0 298.15
@@ -5983,8 +5983,8 @@ class max_speed
59835983
>>> columns = pd.MultiIndex.from_tuples([('speed', 'max'),
59845984
... ('species', 'type')])
59855985
>>> df = pd.DataFrame([(389.0, 'fly'),
5986-
... ( 24.0, 'fly'),
5987-
... ( 80.5, 'run'),
5986+
... (24.0, 'fly'),
5987+
... (80.5, 'run'),
59885988
... (np.nan, 'jump')],
59895989
... index=index,
59905990
... columns=columns)
@@ -8262,14 +8262,14 @@ def groupby(
82628262
4 2 1 1 5 4
82638263
5 2 2 2 6 5
82648264
8265-
>>> df.pivot(index="lev1", columns=["lev2", "lev3"],values="values")
8265+
>>> df.pivot(index="lev1", columns=["lev2", "lev3"], values="values")
82668266
lev2 1 2
82678267
lev3 1 2 1 2
82688268
lev1
82698269
1 0.0 1.0 2.0 NaN
82708270
2 4.0 3.0 NaN 5.0
82718271
8272-
>>> df.pivot(index=["lev1", "lev2"], columns=["lev3"],values="values")
8272+
>>> df.pivot(index=["lev1", "lev2"], columns=["lev3"], values="values")
82738273
lev3 1 2
82748274
lev1 lev2
82758275
1 1 0.0 1.0
@@ -8317,7 +8317,8 @@ def pivot(
83178317
83188318
Parameters
83198319
----------%s
8320-
values : column to aggregate, optional
8320+
values : list-like or scalar, optional
8321+
Column or columns to aggregate.
83218322
index : column, Grouper, array, or list of the previous
83228323
If an array is passed, it must be the same length as the data. The
83238324
list can contain any of the other types (except list).
@@ -8403,7 +8404,7 @@ def pivot(
84038404
This first example aggregates values by taking the sum.
84048405
84058406
>>> table = pd.pivot_table(df, values='D', index=['A', 'B'],
8406-
... columns=['C'], aggfunc=np.sum)
8407+
... columns=['C'], aggfunc=np.sum)
84078408
>>> table
84088409
C large small
84098410
A B
@@ -8415,7 +8416,7 @@ def pivot(
84158416
We can also fill missing values using the `fill_value` parameter.
84168417
84178418
>>> table = pd.pivot_table(df, values='D', index=['A', 'B'],
8418-
... columns=['C'], aggfunc=np.sum, fill_value=0)
8419+
... columns=['C'], aggfunc=np.sum, fill_value=0)
84198420
>>> table
84208421
C large small
84218422
A B
@@ -8427,8 +8428,7 @@ def pivot(
84278428
The next example aggregates by taking the mean across multiple columns.
84288429
84298430
>>> table = pd.pivot_table(df, values=['D', 'E'], index=['A', 'C'],
8430-
... aggfunc={'D': np.mean,
8431-
... 'E': np.mean})
8431+
... aggfunc={'D': np.mean, 'E': np.mean})
84328432
>>> table
84338433
D E
84348434
A C
@@ -8441,8 +8441,8 @@ def pivot(
84418441
value column.
84428442
84438443
>>> table = pd.pivot_table(df, values=['D', 'E'], index=['A', 'C'],
8444-
... aggfunc={'D': np.mean,
8445-
... 'E': [min, max, np.mean]})
8444+
... aggfunc={'D': np.mean,
8445+
... 'E': [min, max, np.mean]})
84468446
>>> table
84478447
D E
84488448
mean max mean min
@@ -10926,7 +10926,8 @@ def to_timestamp(
1092610926
1092710927
Returns
1092810928
-------
10929-
DataFrame with DatetimeIndex
10929+
DataFrame
10930+
The DataFrame has a DatetimeIndex.
1093010931
"""
1093110932
new_obj = self.copy(deep=copy)
1093210933

@@ -10960,7 +10961,8 @@ def to_period(
1096010961
1096110962
Returns
1096210963
-------
10963-
DataFrame with PeriodIndex
10964+
DataFrame:
10965+
The DataFrame has a PeriodIndex.
1096410966
1096510967
Examples
1096610968
--------

pandas/core/generic.py

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4855,8 +4855,8 @@ def sort_values(
48554855
4 96hr 50
48564856
>>> from natsort import index_natsorted
48574857
>>> df.sort_values(
4858-
... by="time",
4859-
... key=lambda x: np.argsort(index_natsorted(df["time"]))
4858+
... by="time",
4859+
... key=lambda x: np.argsort(index_natsorted(df["time"]))
48604860
... )
48614861
time value
48624862
0 0hr 10
@@ -7703,10 +7703,10 @@ def isna(self: NDFrameT) -> NDFrameT:
77037703
Show which entries in a DataFrame are NA.
77047704
77057705
>>> df = pd.DataFrame(dict(age=[5, 6, np.NaN],
7706-
... born=[pd.NaT, pd.Timestamp('1939-05-27'),
7707-
... pd.Timestamp('1940-04-25')],
7708-
... name=['Alfred', 'Batman', ''],
7709-
... toy=[None, 'Batmobile', 'Joker']))
7706+
... born=[pd.NaT, pd.Timestamp('1939-05-27'),
7707+
... pd.Timestamp('1940-04-25')],
7708+
... name=['Alfred', 'Batman', ''],
7709+
... toy=[None, 'Batmobile', 'Joker']))
77107710
>>> df
77117711
age born name toy
77127712
0 5.0 NaT Alfred None
@@ -7770,10 +7770,10 @@ def notna(self: NDFrameT) -> NDFrameT:
77707770
Show which entries in a DataFrame are not NA.
77717771
77727772
>>> df = pd.DataFrame(dict(age=[5, 6, np.NaN],
7773-
... born=[pd.NaT, pd.Timestamp('1939-05-27'),
7774-
... pd.Timestamp('1940-04-25')],
7775-
... name=['Alfred', 'Batman', ''],
7776-
... toy=[None, 'Batmobile', 'Joker']))
7773+
... born=[pd.NaT, pd.Timestamp('1939-05-27'),
7774+
... pd.Timestamp('1940-04-25')],
7775+
... name=['Alfred', 'Batman', ''],
7776+
... toy=[None, 'Batmobile', 'Joker']))
77777777
>>> df
77787778
age born name toy
77797779
0 5.0 NaT Alfred None
@@ -8162,6 +8162,7 @@ def at_time(
81628162
Parameters
81638163
----------
81648164
time : datetime.time or str
8165+
The values to select.
81658166
axis : {0 or 'index', 1 or 'columns'}, default 0
81668167
For `Series` this parameter is unused and defaults to 0.
81678168
@@ -10118,7 +10119,8 @@ def tz_convert(
1011810119
tz : str or tzinfo object or None
1011910120
Target time zone. Passing ``None`` will convert to
1012010121
UTC and remove the timezone information.
10121-
axis : the axis to convert
10122+
axis : {{0 or 'index', 1 or 'columns'}}, default 0
10123+
The axis to convert
1012210124
level : int, str, default None
1012310125
If axis is a MultiIndex, convert a specific level. Otherwise
1012410126
must be None.
@@ -10139,8 +10141,10 @@ def tz_convert(
1013910141
--------
1014010142
Change to another time zone:
1014110143
10142-
>>> s = pd.Series([1],
10143-
... index=pd.DatetimeIndex(['2018-09-15 01:30:00+02:00']))
10144+
>>> s = pd.Series(
10145+
... [1],
10146+
... index=pd.DatetimeIndex(['2018-09-15 01:30:00+02:00']),
10147+
... )
1014410148
>>> s.tz_convert('Asia/Shanghai')
1014510149
2018-09-15 07:30:00+08:00 1
1014610150
dtype: int64
@@ -10205,7 +10209,8 @@ def tz_localize(
1020510209
tz : str or tzinfo or None
1020610210
Time zone to localize. Passing ``None`` will remove the
1020710211
time zone information and preserve local time.
10208-
axis : the axis to localize
10212+
axis : {{0 or 'index', 1 or 'columns'}}, default 0
10213+
The axis to localize
1020910214
level : int, str, default None
1021010215
If axis ia a MultiIndex, localize a specific level. Otherwise
1021110216
must be None.
@@ -10254,8 +10259,10 @@ def tz_localize(
1025410259
--------
1025510260
Localize local times:
1025610261
10257-
>>> s = pd.Series([1],
10258-
... index=pd.DatetimeIndex(['2018-09-15 01:30:00']))
10262+
>>> s = pd.Series(
10263+
... [1],
10264+
... index=pd.DatetimeIndex(['2018-09-15 01:30:00']),
10265+
... )
1025910266
>>> s.tz_localize('CET')
1026010267
2018-09-15 01:30:00+02:00 1
1026110268
dtype: int64
@@ -10489,9 +10496,9 @@ def describe(
1048910496
Describing a timestamp ``Series``.
1049010497
1049110498
>>> s = pd.Series([
10492-
... np.datetime64("2000-01-01"),
10493-
... np.datetime64("2010-01-01"),
10494-
... np.datetime64("2010-01-01")
10499+
... np.datetime64("2000-01-01"),
10500+
... np.datetime64("2010-01-01"),
10501+
... np.datetime64("2010-01-01")
1049510502
... ])
1049610503
>>> s.describe()
1049710504
count 3
@@ -11749,9 +11756,9 @@ def _doc_params(cls):
1174911756
Examples
1175011757
--------
1175111758
>>> df = pd.DataFrame({'person_id': [0, 1, 2, 3],
11752-
... 'age': [21, 25, 62, 43],
11753-
... 'height': [1.61, 1.87, 1.49, 2.01]}
11754-
... ).set_index('person_id')
11759+
... 'age': [21, 25, 62, 43],
11760+
... 'height': [1.61, 1.87, 1.49, 2.01]}
11761+
... ).set_index('person_id')
1175511762
>>> df
1175611763
age height
1175711764
person_id
@@ -11969,7 +11976,7 @@ def _doc_params(cls):
1196911976
>>> df = pd.DataFrame([[2.0, 1.0],
1197011977
... [3.0, np.nan],
1197111978
... [1.0, 0.0]],
11972-
... columns=list('AB'))
11979+
... columns=list('AB'))
1197311980
>>> df
1197411981
A B
1197511982
0 2.0 1.0
@@ -12034,7 +12041,7 @@ def _doc_params(cls):
1203412041
>>> df = pd.DataFrame([[2.0, 1.0],
1203512042
... [3.0, np.nan],
1203612043
... [1.0, 0.0]],
12037-
... columns=list('AB'))
12044+
... columns=list('AB'))
1203812045
>>> df
1203912046
A B
1204012047
0 2.0 1.0
@@ -12099,7 +12106,7 @@ def _doc_params(cls):
1209912106
>>> df = pd.DataFrame([[2.0, 1.0],
1210012107
... [3.0, np.nan],
1210112108
... [1.0, 0.0]],
12102-
... columns=list('AB'))
12109+
... columns=list('AB'))
1210312110
>>> df
1210412111
A B
1210512112
0 2.0 1.0
@@ -12164,7 +12171,7 @@ def _doc_params(cls):
1216412171
>>> df = pd.DataFrame([[2.0, 1.0],
1216512172
... [3.0, np.nan],
1216612173
... [1.0, 0.0]],
12167-
... columns=list('AB'))
12174+
... columns=list('AB'))
1216812175
>>> df
1216912176
A B
1217012177
0 2.0 1.0

pandas/core/shared_docs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -798,8 +798,8 @@
798798
Consider a dataset containing food consumption in Argentina.
799799
800800
>>> df = pd.DataFrame({{'consumption': [10.51, 103.11, 55.48],
801-
... 'co2_emissions': [37.2, 19.66, 1712]}},
802-
... index=['Pork', 'Wheat Products', 'Beef'])
801+
... 'co2_emissions': [37.2, 19.66, 1712]}},
802+
... index=['Pork', 'Wheat Products', 'Beef'])
803803
804804
>>> df
805805
consumption co2_emissions
@@ -865,8 +865,8 @@
865865
Consider a dataset containing food consumption in Argentina.
866866
867867
>>> df = pd.DataFrame({{'consumption': [10.51, 103.11, 55.48],
868-
... 'co2_emissions': [37.2, 19.66, 1712]}},
869-
... index=['Pork', 'Wheat Products', 'Beef'])
868+
... 'co2_emissions': [37.2, 19.66, 1712]}},
869+
... index=['Pork', 'Wheat Products', 'Beef'])
870870
871871
>>> df
872872
consumption co2_emissions

pandas/core/window/doc.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ def create_section_header(header: str) -> str:
2424

2525
template_see_also = dedent(
2626
"""
27-
pandas.Series.{window_method} : Calling {window_method} with Series data.
28-
pandas.DataFrame.{window_method} : Calling {window_method} with DataFrames.
29-
pandas.Series.{agg_method} : Aggregating {agg_method} for Series.
30-
pandas.DataFrame.{agg_method} : Aggregating {agg_method} for DataFrame.\n
27+
Series.{window_method} : Calling {window_method} with Series data.
28+
DataFrame.{window_method} : Calling {window_method} with DataFrames.
29+
Series.{agg_method} : Aggregating {agg_method} for Series.
30+
DataFrame.{agg_method} : Aggregating {agg_method} for DataFrame.\n
3131
"""
3232
).replace("\n", "", 1)
3333

0 commit comments

Comments
 (0)