Skip to content

Fix incorrect example in wide_to_long docstring #25736

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

Closed
wants to merge 8 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions pandas/core/reshape/melt.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,11 @@ def wide_to_long(df, stubnames, i, j, sep="", suffix=r'\d+'):
... 'X' : np.random.randint(3, size=3)})
>>> df['id'] = df.index
>>> df # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
A(quarterly)-2010 A(quarterly)-2011 B(quarterly)-2010 ...
0 0.548814 0.544883 0.437587 ...
1 0.715189 0.423655 0.891773 ...
2 0.602763 0.645894 0.963663 ...
X id
0 0 0
1 1 1
2 1 2
A(quarterly)-2010 A(quarterly)-2011 B(quarterly)-2010 ... X id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the output too wide to include all the columns without any ellipses?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes @TomAugspurger the line is too wide to include all columns, so deleted only "B(quarterly)-2011" column (88 > 79 chars on pycodestyle and flake8)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrm, that's a little unfortunate as all the columns are important :/

Well, for now, let's use ellipses. FYI, your spacing is just slightly off, so it failed again :)

diff --git a/pandas/core/reshape/melt.py b/pandas/core/reshape/melt.py
index cec4c609c..df144db50 100644
--- a/pandas/core/reshape/melt.py
+++ b/pandas/core/reshape/melt.py
@@ -334,9 +334,9 @@ def wide_to_long(df, stubnames, i, j, sep="", suffix=r'\d+'):
     >>> df['id'] = df.index
     >>> df # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
        A(quarterly)-2010  A(quarterly)-2011  B(quarterly)-2010  ...  X  id
-    0           0.548814           0.544883           0.437587  ...  0  0
-    1           0.715189           0.423655           0.891773  ...  1  1
-    2           0.602763           0.645894           0.963663  ...  2  2
+    0           0.548814           0.544883           0.437587  ...  0   0
+    1           0.715189           0.423655           0.891773  ...  1   1
+    2           0.602763           0.645894           0.963663  ...  1   2
 
     >>> pd.wide_to_long(df, ['A(quarterly)', 'B(quarterly)'], i='id',
     ...                 j='year', sep='-')

I think you need an extra space so that the values in id are under the d.

0 0.548814 0.544883 0.437587 ... 0 0
1 0.715189 0.423655 0.891773 ... 1 1
2 0.602763 0.645894 0.963663 ... 2 2

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can delete this line I think.


>>> pd.wide_to_long(df, ['A(quarterly)', 'B(quarterly)'], i='id',
... j='year', sep='-')
Expand Down