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 73eb6a15a1b47..d2772b896807d 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -300,7 +300,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 0fa80de812c5f..aa0f32df707d6 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] ... }) @@ -333,14 +333,10 @@ 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='-') @@ -368,8 +364,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,9 +382,9 @@ 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 + ... # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS ht famid birth age 1 1 one 2.8