Skip to content

BUG: replacement works for object but not string dtype #35977

Closed
@yunkypunky

Description

@yunkypunky
  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Code Sample

import pandas as pd
import numpy as np

a = pd.DataFrame({'a': ['a', 'b', 'c'], 'b': ['d', '', '']}, dtype='object')
b = pd.DataFrame({'a': ['a', 'b', 'c'], 'b': ['d', '', '']}, dtype='string')

print(a)
a.replace(r'^\s*$', pd.NA, regex=True, inplace=True)
print(a)

print(b)
b.replace(r'^\s*$', pd.NA, regex=True, inplace=True)
print(b)

Problem description

replace(r'^\s*$', pd.NA, regex=True, inplace=True) works on object dtype, but not on stringdtype

Expected Output

Same on both replacement

Output of pd.show_versions()

[paste the output of pd.show_versions() here leaving a blank line after the details tag]

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNA - MaskedArraysRelated to pd.NA and nullable extension arraysStringsString extension data type and string datareplacereplace method

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions