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

Fix incorrect example in wide_to_long docstring #25736

wants to merge 8 commits into from

Conversation

bharatr21
Copy link
Contributor

@bharatr21 bharatr21 commented Mar 14, 2019

@codecov
Copy link

codecov bot commented Mar 14, 2019

Codecov Report

Merging #25736 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #25736   +/-   ##
=======================================
  Coverage   91.25%   91.25%           
=======================================
  Files         172      172           
  Lines       52973    52973           
=======================================
  Hits        48338    48338           
  Misses       4635     4635
Flag Coverage Δ
#multiple 89.82% <ø> (ø) ⬆️
#single 41.74% <ø> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/reshape/melt.py 97.5% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9eec9b8...5bda59c. Read the comment docs.

@codecov
Copy link

codecov bot commented Mar 14, 2019

Codecov Report

Merging #25736 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #25736   +/-   ##
=======================================
  Coverage   91.26%   91.26%           
=======================================
  Files         173      173           
  Lines       52982    52982           
=======================================
  Hits        48356    48356           
  Misses       4626     4626
Flag Coverage Δ
#multiple 89.83% <ø> (ø) ⬆️
#single 41.75% <ø> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/reshape/melt.py 97.5% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4663951...b182905. Read the comment docs.

Copy link
Contributor

@TomAugspurger TomAugspurger left a comment

Choose a reason for hiding this comment

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

Can you post the output of python scripts/validate_docstrings.py pandas.wide_to_long

And, it's not necessary, but it would be good to run all these in CI. Can you add

diff --git a/ci/code_checks.sh b/ci/code_checks.sh
index 51df77934..5ab33e7e2 100755
--- a/ci/code_checks.sh
+++ b/ci/code_checks.sh
@@ -223,6 +223,7 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
     MSG='Doctests top-level reshaping functions' ; echo $MSG
     pytest -q --doctest-modules \
         pandas/core/reshape/concat.py \
+        pandas/core/reshape/melt.py \
         pandas/core/reshape/pivot.py \
         pandas/core/reshape/reshape.py \
         pandas/core/reshape/tile.py \

and ensure that things pass with pytest --doctest-modules pandas/core/reshape/melt.py. May need to change a couple more things.

@@ -386,7 +386,7 @@ def wide_to_long(df, stubnames, i, j, sep="", suffix=r'\d+'):
8 3 3 2.1 2.9

>>> l = pd.wide_to_long(df, stubnames='ht', i=['famid', 'birth'], j='age',
sep='_', suffix='\w')
sep='_', suffix='\w+')
Copy link
Contributor

Choose a reason for hiding this comment

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

Need ... under the >>>.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Errors:

################################### Doctests ###################################
################################################################################

**********************************************************************
Line 94, in pandas.wide_to_long
Failed example:
    df
Expected:
       birth  famid  ht1  ht2
    0      1      1  2.8  3.4
    1      2      1  2.9  3.8
    2      3      1  2.2  2.9
    3      1      2  2.0  3.2
    4      2      2  1.8  2.8
    5      3      2  1.9  2.4
    6      1      3  2.2  3.3
    7      2      3  2.3  3.4
    8      3      3  2.1  2.9
Got:
       famid  birth  ht1  ht2
    0      1      1  2.8  3.4
    1      1      2  2.9  3.8
    2      1      3  2.2  2.9
    3      2      1  2.0  3.2
    4      2      2  1.8  2.8
    5      2      3  1.9  2.4
    6      3      1  2.2  3.3
    7      3      2  2.3  3.4
    8      3      3  2.1  2.9
**********************************************************************
Line 154, in pandas.wide_to_long
Failed example:
    df # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
Expected:
       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
Got:
       A(quarterly)-2010  A(quarterly)-2011  B(quarterly)-2010  B(quarterly)-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
    2           0.602763           0.645894           0.963663           0.528895  1   2
**********************************************************************
Line 195, in pandas.wide_to_long
Failed example:
    df
Expected:
       birth  famid  ht_one  ht_two
    0      1      1     2.8     3.4
    1      2      1     2.9     3.8
    2      3      1     2.2     2.9
    3      1      2     2.0     3.2
    4      2      2     1.8     2.8
    5      3      2     1.9     2.4
    6      1      3     2.2     3.3
    7      2      3     2.3     3.4
    8      3      3     2.1     2.9
Got:
       famid  birth  ht_one  ht_two
    0      1      1     2.8     3.4
    1      1      2     2.9     3.8
    2      1      3     2.2     2.9
    3      2      1     2.0     3.2
    4      2      2     1.8     2.8
    5      2      3     1.9     2.4
    6      3      1     2.2     3.3
    7      3      2     2.3     3.4
    8      3      3     2.1     2.9

and after my attempted fix,

################################################################################
################################### Doctests ###################################
################################################################################

**********************************************************************
Line 154, in pandas.wide_to_long
Failed example:
    df # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
Expected:
       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
Got:
       A(quarterly)-2010  A(quarterly)-2011  B(quarterly)-2010  B(quarterly)-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
    2           0.602763           0.645894           0.963663           0.528895  1   2

The ELLIPSIS is not being considered or ignored by doctest as it ought to be. Perhaps another PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The doctest, and hence the entire pipeline is failing only due to this ELLIPSIS error @TomAugspurger any suggestions on what to do? (If I put all columns, pylint and flake8 fails because it exceeds 79 chars)

Copy link
Contributor

Choose a reason for hiding this comment

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

@jreback jreback added the Docs label Mar 14, 2019
@jreback jreback added this to the 0.25.0 milestone Mar 14, 2019
@TomAugspurger
Copy link
Contributor

How does pytest --doctest-modules pandas/core/reshape/melt.py look now?

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.

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.

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

pls merge master

@WillAyd
Copy link
Member

WillAyd commented Apr 10, 2019

Closing as stale and superseded by #26010

@WillAyd WillAyd closed this Apr 10, 2019
@TomAugspurger
Copy link
Contributor

TomAugspurger commented Apr 10, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect example in wide_to_long docstring
4 participants