From ca1951e1738ae0cfb7e6dfb0edb9ed44c464f21e Mon Sep 17 00:00:00 2001 From: Jordan Murphy <35613487+jordan-d-murphy@users.noreply.github.com> Date: Sun, 14 Jan 2024 23:37:48 -0700 Subject: [PATCH] DOC: fix EX03 errors in docstrings - pandas.core.resample.Resampler.interpolate, pandas.pivot, pandas.merge_asof, pandas.wide_to_long (#56868) --- ci/code_checks.sh | 4 --- pandas/core/reshape/melt.py | 20 +++++++-------- pandas/core/reshape/merge.py | 48 ++++++++++++++++++------------------ 3 files changed, 34 insertions(+), 38 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index afb76c29133f9..50310a3af9661 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -89,11 +89,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.read_parquet \ pandas.DataFrame.to_sql \ pandas.read_stata \ - pandas.core.resample.Resampler.interpolate \ pandas.plotting.scatter_matrix \ - pandas.pivot \ - pandas.merge_asof \ - pandas.wide_to_long \ pandas.Index.rename \ pandas.Index.droplevel \ pandas.Index.isin \ diff --git a/pandas/core/reshape/melt.py b/pandas/core/reshape/melt.py index bb1cd0d738dac..1ae7000f56bc9 100644 --- a/pandas/core/reshape/melt.py +++ b/pandas/core/reshape/melt.py @@ -295,7 +295,7 @@ def wide_to_long( ... "B1970" : {0 : 2.5, 1 : 1.2, 2 : .7}, ... "B1980" : {0 : 3.2, 1 : 1.3, 2 : .1}, ... "X" : dict(zip(range(3), np.random.randn(3))) - ... }) + ... }) >>> df["id"] = df.index >>> df A1970 A1980 B1970 B1980 X id @@ -332,8 +332,8 @@ def wide_to_long( 6 3 1 2.2 3.3 7 3 2 2.3 3.4 8 3 3 2.1 2.9 - >>> l = pd.wide_to_long(df, stubnames='ht', i=['famid', 'birth'], j='age') - >>> l + >>> long_format = pd.wide_to_long(df, stubnames='ht', i=['famid', 'birth'], j='age') + >>> long_format ... # doctest: +NORMALIZE_WHITESPACE ht famid birth age @@ -358,9 +358,9 @@ def wide_to_long( Going from long back to wide just takes some creative use of `unstack` - >>> w = l.unstack() - >>> w.columns = w.columns.map('{0[0]}{0[1]}'.format) - >>> w.reset_index() + >>> wide_format = long_format.unstack() + >>> wide_format.columns = wide_format.columns.map('{0[0]}{0[1]}'.format) + >>> wide_format.reset_index() famid birth ht1 ht2 0 1 1 2.8 3.4 1 1 2 2.9 3.8 @@ -381,7 +381,7 @@ def wide_to_long( ... 'B(weekly)-2011': np.random.rand(3), ... 'X' : np.random.randint(3, size=3)}) >>> df['id'] = df.index - >>> df # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS + >>> df # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS A(weekly)-2010 A(weekly)-2011 B(weekly)-2010 B(weekly)-2011 X id 0 0.548814 0.544883 0.437587 0.383442 0 0 1 0.715189 0.423655 0.891773 0.791725 1 1 @@ -430,9 +430,9 @@ def wide_to_long( 7 3 2 2.3 3.4 8 3 3 2.1 2.9 - >>> l = pd.wide_to_long(df, stubnames='ht', i=['famid', 'birth'], j='age', - ... sep='_', suffix=r'\w+') - >>> l + >>> long_format = pd.wide_to_long(df, stubnames='ht', i=['famid', 'birth'], j='age', + ... sep='_', suffix=r'\w+') + >>> long_format ... # doctest: +NORMALIZE_WHITESPACE ht famid birth age diff --git a/pandas/core/reshape/merge.py b/pandas/core/reshape/merge.py index 804144931bcfd..6ca403bdb439a 100644 --- a/pandas/core/reshape/merge.py +++ b/pandas/core/reshape/merge.py @@ -601,17 +601,17 @@ def merge_asof( ... pd.Timestamp("2016-05-25 13:30:00.075") ... ], ... "ticker": [ - ... "GOOG", - ... "MSFT", - ... "MSFT", - ... "MSFT", - ... "GOOG", - ... "AAPL", - ... "GOOG", - ... "MSFT" - ... ], - ... "bid": [720.50, 51.95, 51.97, 51.99, 720.50, 97.99, 720.50, 52.01], - ... "ask": [720.93, 51.96, 51.98, 52.00, 720.93, 98.01, 720.88, 52.03] + ... "GOOG", + ... "MSFT", + ... "MSFT", + ... "MSFT", + ... "GOOG", + ... "AAPL", + ... "GOOG", + ... "MSFT" + ... ], + ... "bid": [720.50, 51.95, 51.97, 51.99, 720.50, 97.99, 720.50, 52.01], + ... "ask": [720.93, 51.96, 51.98, 52.00, 720.93, 98.01, 720.88, 52.03] ... } ... ) >>> quotes @@ -626,19 +626,19 @@ def merge_asof( 7 2016-05-25 13:30:00.075 MSFT 52.01 52.03 >>> trades = pd.DataFrame( - ... { - ... "time": [ - ... pd.Timestamp("2016-05-25 13:30:00.023"), - ... pd.Timestamp("2016-05-25 13:30:00.038"), - ... pd.Timestamp("2016-05-25 13:30:00.048"), - ... pd.Timestamp("2016-05-25 13:30:00.048"), - ... pd.Timestamp("2016-05-25 13:30:00.048") - ... ], - ... "ticker": ["MSFT", "MSFT", "GOOG", "GOOG", "AAPL"], - ... "price": [51.95, 51.95, 720.77, 720.92, 98.0], - ... "quantity": [75, 155, 100, 100, 100] - ... } - ... ) + ... { + ... "time": [ + ... pd.Timestamp("2016-05-25 13:30:00.023"), + ... pd.Timestamp("2016-05-25 13:30:00.038"), + ... pd.Timestamp("2016-05-25 13:30:00.048"), + ... pd.Timestamp("2016-05-25 13:30:00.048"), + ... pd.Timestamp("2016-05-25 13:30:00.048") + ... ], + ... "ticker": ["MSFT", "MSFT", "GOOG", "GOOG", "AAPL"], + ... "price": [51.95, 51.95, 720.77, 720.92, 98.0], + ... "quantity": [75, 155, 100, 100, 100] + ... } + ... ) >>> trades time ticker price quantity 0 2016-05-25 13:30:00.023 MSFT 51.95 75