Skip to content

BUG: pd.DataFrame.replace(to_replace: list, method: str) raises TypeError: No matching signature found #37899

Closed
@oguzhanogreden

Description

@oguzhanogreden
  • I have checked that this issue has not already been reported: search query

  • 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: Tested with '1.2.0.dev0+1137.g50b34a4a8')


Code Sample, a copy-pastable example

import pandas as pd

df = pd.DataFrame({
    'x': pd.Categorical([1, 2, 3], [1, 2, 3])
})

df.replace([1, 2], method='bfill')

# > Traceback excerpt: 635 def backfill_inplace(algos_t[:] values, const uint8_t[:] mask, limit=None):
# > TypeError: No matching signature found

Problem description

This should work fine, within bounds of considerations like #18250.

Expected Output

Should be equivalent to pd.Categorical([3, 3, 3], [1,2,3]) (or pd.Categorical([3, 3, 3], [3]) depending on the what's done with unused categories elsewhere.)

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 50b34a4
python : 3.8.3.final.0
python-bits : 64
OS : Darwin
OS-release : 19.4.0
Version : Darwin Kernel Version 19.4.0: Wed Mar 4 22:28:40 PST 2020; root:xnu-6153.101.6~15/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8

pandas : 1.2.0.dev0+1137.g50b34a4a8
numpy : 1.18.5
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 47.3.1.post20200616
Cython : 0.29.21
pytest : 5.4.3
hypothesis : 5.16.2
sphinx : 3.1.1
blosc : None
feather : None
xlsxwriter : 1.2.9
lxml.etree : 4.5.1
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.15.0
pandas_datareader: None
bs4 : 4.9.1
bottleneck : 1.3.2
fsspec : 0.7.4
fastparquet : 0.4.0
gcsfs : None
matplotlib : 3.2.1
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.3
pandas_gbq : None
pyarrow : 0.17.1
pyxlsb : None
s3fs : 0.4.2
scipy : 1.4.1
sqlalchemy : 1.3.17
tables : 3.6.1
tabulate : 0.8.7
xarray : 0.15.1
xlrd : 1.2.0
xlwt : 1.3.0
numba : 0.48.0

Noticed while working on #32542

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions