maaz.code logo
Simple view

Mergedpandas-dev/pandas#7138450.3Kstars

DOC: Fix stack and from_dummies descriptions in the reshaping guide

By Mohd Maaz Khan, merged by jbrockmendel into pandas-dev/pandas on 31 Oct 2026

+3−33 lines added, 3 lines removed1 file changed2 comments

Conversation

  1. maaz7409opened this pull request on 20 Oct 2026description.mdAuthor

    This PR fixes descriptions in three places in user_guide/reshaping.rst which describe the wrong result:

    • (i) stack (line 208): "The stacked level becomes the new lowest level in a MultiIndex on the columns". stack moves the level into the row index. For columns (exp, animal), df.stack("animal") gives an index of (first, second, animal), and only exp stays on the columns. The bullet at the top of the same section already says "an index with a new inner-most level of row labels". This PR uses that wording.

    • (ii) Round-trip check (line 251): all(df.unstack().stack() == df.sort_index()) calls the builtin all() on a DataFrame, which iterates the column labels (["A"]), not the values. It is True even when the frames differ: all((df + 1) == df) is also True. This PR changes it to df.unstack().stack().equals(df.sort_index()), which compares the values, the index and the dtypes. That is what the sentence above the example claims.

    • (iii) from_dummies (line 495): "back into a Series of categorical values". from_dummies returns a DataFrame (signature -> DataFrame, docstring "Create a categorical DataFrame"). The example directly below already shows a one-column frame, prefix. This PR changes Series to DataFrame.

    AI Disclosure: Claude Code ( Sonnet 5.5 (high) ) was used for auditing docs and pointing out these issues.

  2. maaz7409commented on 20 Oct 2026Author

    /pandas-review with Opus 5.5 at high effort IMG_20261020_212447

  3. jbrockmendelapproved these changes on 31 Oct 2026

  4. jbrockmendelmerged this pull request on 31 Oct 2026

Copied from GitHub when this site was built; comments by bots are left out.