Skip to content

BUG: Series.str.get_dummies adds "NaN" / "" column for categorical / Arrow-backed strings #71887

Open

Description

@rhshadrach

Ref: #70812

s = pd.Series(["a|b", "a", None, ""], dtype=object)
print(s.str.get_dummies("|"))
#    a  b
# 0  1  1
# 1  1  0
# 2  0  0
# 3  0  0

print(s.astype("category").str.get_dummies("|"))
#    NaN  a  b
# 0    0  1  1
# 1    0  1  0
# 2    1  0  0
# 3    0  0  0

print(pd.Series(["a|b", "a", None, ""], dtype="str").str.get_dummies("|"))
#       a  b
# 0  0  1  1
# 1  0  1  0
# 2  0  0  0
# 3  1  0  0

Every dtype should give the same result as object dtype: NA values and empty strings get a row of zeros, with no "NaN" or "" column:

   a  b
0  1  1
1  1  0
2  0  0
3  0  0

Activity

  1. added
    ReshapingConcat, Merge/Join, Stack/Unstack, Explode
    Missing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
    on Nov 3, 2026
  2. AntsiferovBogdan commented on Nov 4, 2026

    @AntsiferovBogdan

    /take

  3. changed the title [-]BBUG: Series.str.get_dummies adds "NaN" / "" column for categorical / Arrow-backed strings[/-] [+]BUG: Series.str.get_dummies adds "NaN" / "" column for categorical / Arrow-backed strings[/+] on Nov 4, 2026
  4. added this to the 3.1.1 milestone on Nov 4, 2026
  5. jorisvandenbossche commented on Nov 4, 2026

    @jorisvandenbossche
    Member

    This is a regression from 2.x for strings (due to implicit object -> str dtype change), so marking for 3.1.x

  6. jorisvandenbossche commented on Nov 4, 2026

    @jorisvandenbossche
    Member

    Although for category it is long standing behaviour, so there we should maybe not fix it in a patch release

  7. AntsiferovBogdan commented on Nov 4, 2026

    @AntsiferovBogdan

    Thanks for clarifying the release scope. I can split this into two PRs: an Arrow-backed string fix suitable for backporting to 3.1.x, and a separate categorical fix.

    The Arrow PR would exclude the empty-string dummy column and preserve the row count when no labels remain, without changing categorical behavior.

    Would that split work for you? I would use Refs #71887 for the Arrow PR so that the issue remains open for the categorical part.

  8. modified the milestones: 3.1.1, 3.1.2 on Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolateReshapingConcat, Merge/Join, Stack/Unstack, Explode

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions