From d472c174d48f51d3778ec55efc5ffc852f7d6e2f Mon Sep 17 00:00:00 2001 From: Bharat123Rox Date: Fri, 15 Mar 2019 00:32:54 +0530 Subject: [PATCH 1/6] Fix incorrect example in wide_to_long docstring --- doc/source/whatsnew/v0.25.0.rst | 2 +- pandas/core/reshape/melt.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 124ec8f4ab92c..84b16f5c5a359 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -241,7 +241,7 @@ Reshaping - Bug in :func:`pandas.merge` adds a string of ``None`` if ``None`` is assigned in suffixes instead of remain the column name as-is (:issue:`24782`). - Bug in :func:`merge` when merging by index name would sometimes result in an incorrectly numbered index (:issue:`24212`) - :func:`to_records` now accepts dtypes to its `column_dtypes` parameter (:issue:`24895`) - +- Bug in last example in docstring of :func:`wide_to_long` has been fixed (:issue:`25733`) Sparse ^^^^^^ diff --git a/pandas/core/reshape/melt.py b/pandas/core/reshape/melt.py index 0fa80de812c5f..789cf4e298c03 100644 --- a/pandas/core/reshape/melt.py +++ b/pandas/core/reshape/melt.py @@ -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+') >>> l ... # doctest: +NORMALIZE_WHITESPACE ht From 26a28d51f1754fdc219d7ab22458412b70852f86 Mon Sep 17 00:00:00 2001 From: Bharat123Rox Date: Fri, 15 Mar 2019 08:55:36 +0530 Subject: [PATCH 2/6] More changes to docstring, added CI, removed whatsnew courtesy @TomAugspurger and @jreback --- ci/code_checks.sh | 1 + doc/source/whatsnew/v0.25.0.rst | 2 +- pandas/core/reshape/melt.py | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 51df779341ed5..2be8940478082 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -224,6 +224,7 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then pytest -q --doctest-modules \ pandas/core/reshape/concat.py \ pandas/core/reshape/pivot.py \ + pandas/core/reshape/melt.py \ pandas/core/reshape/reshape.py \ pandas/core/reshape/tile.py \ -k"-crosstab -pivot_table -cut" diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index fe13348d05d81..d5e6fa57b14ca 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -245,7 +245,7 @@ Reshaping - Bug in :func:`merge` when merging by index name would sometimes result in an incorrectly numbered index (:issue:`24212`) - :func:`to_records` now accepts dtypes to its `column_dtypes` parameter (:issue:`24895`) - Bug in :func:`concat` where order of ``OrderedDict`` (and ``dict`` in Python 3.6+) is not respected, when passed in as ``objs`` argument (:issue:`21510`) -- Bug in last example in docstring of :func:`wide_to_long` has been fixed (:issue:`25733`) +- Sparse ^^^^^^ diff --git a/pandas/core/reshape/melt.py b/pandas/core/reshape/melt.py index 789cf4e298c03..ee25a252525c9 100644 --- a/pandas/core/reshape/melt.py +++ b/pandas/core/reshape/melt.py @@ -267,8 +267,8 @@ def wide_to_long(df, stubnames, i, j, sep="", suffix=r'\d+'): With multiple id columns >>> df = pd.DataFrame({ - ... 'famid': [1, 1, 1, 2, 2, 2, 3, 3, 3], ... 'birth': [1, 2, 3, 1, 2, 3, 1, 2, 3], + ... 'famid': [1, 1, 1, 2, 2, 2, 3, 3, 3], ... 'ht1': [2.8, 2.9, 2.2, 2, 1.8, 1.9, 2.2, 2.3, 2.1], ... 'ht2': [3.4, 3.8, 2.9, 3.2, 2.8, 2.4, 3.3, 3.4, 2.9] ... }) @@ -368,8 +368,8 @@ def wide_to_long(df, stubnames, i, j, sep="", suffix=r'\d+'): have non-integers as suffixes. >>> df = pd.DataFrame({ - ... 'famid': [1, 1, 1, 2, 2, 2, 3, 3, 3], ... 'birth': [1, 2, 3, 1, 2, 3, 1, 2, 3], + ... 'famid': [1, 1, 1, 2, 2, 2, 3, 3, 3], ... 'ht_one': [2.8, 2.9, 2.2, 2, 1.8, 1.9, 2.2, 2.3, 2.1], ... 'ht_two': [3.4, 3.8, 2.9, 3.2, 2.8, 2.4, 3.3, 3.4, 2.9] ... }) @@ -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+') >>> l ... # doctest: +NORMALIZE_WHITESPACE ht From cda32f0ac02acbb934ac26bd4401450ca5918119 Mon Sep 17 00:00:00 2001 From: Bharat123Rox Date: Fri, 15 Mar 2019 16:58:47 +0530 Subject: [PATCH 3/6] Fixed ellipsis, added back whatsnew --- doc/source/whatsnew/v0.25.0.rst | 2 +- pandas/core/reshape/melt.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index d5e6fa57b14ca..fe13348d05d81 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -245,7 +245,7 @@ Reshaping - Bug in :func:`merge` when merging by index name would sometimes result in an incorrectly numbered index (:issue:`24212`) - :func:`to_records` now accepts dtypes to its `column_dtypes` parameter (:issue:`24895`) - Bug in :func:`concat` where order of ``OrderedDict`` (and ``dict`` in Python 3.6+) is not respected, when passed in as ``objs`` argument (:issue:`21510`) -- +- Bug in last example in docstring of :func:`wide_to_long` has been fixed (:issue:`25733`) Sparse ^^^^^^ diff --git a/pandas/core/reshape/melt.py b/pandas/core/reshape/melt.py index ee25a252525c9..bb39d87c74c34 100644 --- a/pandas/core/reshape/melt.py +++ b/pandas/core/reshape/melt.py @@ -388,7 +388,7 @@ def wide_to_long(df, stubnames, i, j, sep="", suffix=r'\d+'): >>> l = pd.wide_to_long(df, stubnames='ht', i=['famid', 'birth'], j='age', ... sep='_', suffix='\w+') >>> l - ... # doctest: +NORMALIZE_WHITESPACE + ... # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS ht famid birth age 1 1 one 2.8 From aebff331005d9b1128b6e2b9d6d2b7acf8c92dbd Mon Sep 17 00:00:00 2001 From: Bharat123Rox Date: Fri, 15 Mar 2019 19:56:36 +0530 Subject: [PATCH 4/6] Final doctest fix --- pandas/core/reshape/melt.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pandas/core/reshape/melt.py b/pandas/core/reshape/melt.py index bb39d87c74c34..0bdcaccfda732 100644 --- a/pandas/core/reshape/melt.py +++ b/pandas/core/reshape/melt.py @@ -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 + 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 + >>> pd.wide_to_long(df, ['A(quarterly)', 'B(quarterly)'], i='id', ... j='year', sep='-') From 87a0867c23d49e17914144f3ac4c856f1e5f3636 Mon Sep 17 00:00:00 2001 From: Bharat123Rox Date: Fri, 15 Mar 2019 23:47:20 +0530 Subject: [PATCH 5/6] Final doctest fix --- pandas/core/reshape/melt.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/reshape/melt.py b/pandas/core/reshape/melt.py index 0bdcaccfda732..cec4c609c38ed 100644 --- a/pandas/core/reshape/melt.py +++ b/pandas/core/reshape/melt.py @@ -338,7 +338,6 @@ def wide_to_long(df, stubnames, i, j, sep="", suffix=r'\d+'): 1 0.715189 0.423655 0.891773 ... 1 1 2 0.602763 0.645894 0.963663 ... 2 2 - >>> pd.wide_to_long(df, ['A(quarterly)', 'B(quarterly)'], i='id', ... j='year', sep='-') ... # doctest: +NORMALIZE_WHITESPACE From e7b1679a243a3510c97f36f156018911bf6292da Mon Sep 17 00:00:00 2001 From: Bharat123Rox Date: Fri, 15 Mar 2019 23:47:20 +0530 Subject: [PATCH 6/6] Final doctest fix --- pandas/core/reshape/melt.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/reshape/melt.py b/pandas/core/reshape/melt.py index cec4c609c38ed..aa0f32df707d6 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 ... 2 2 >>> pd.wide_to_long(df, ['A(quarterly)', 'B(quarterly)'], i='id', ... j='year', sep='-')