Skip to content

BUG: astype ignore errors not working for categorical/StringArray #35471

Closed
@traubms

Description

@traubms
  • 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.


Problem description

It seems to be ignoring errors='ignore' kwarg. The behavior in 0.25.3 is expected.

Code Sample, a copy-pastable example

import pandas as pd
pd.__version__
# '1.0.5'

pd.Series(pd.Categorical(['A', 'B'])).astype(float, errors='ignore')
# ---------------------------------------------------------------------------
# ValueError                                Traceback (most recent call last)
# <ipython-input-4-3d39cd9c1cdd> in <module>
# ----> 1 pd.Series(pd.Categorical(['A', 'B'])).astype(float, errors='ignore')
#
# ...
# ValueError: could not convert string to float: 'A'

Expected Output

import pandas as pd
pd.__version__
# '0.25.3'

pd.Series(pd.Categorical(['A', 'B'])).astype(float, errors='ignore')
# 0    A
# 1    B
# dtype: category
# Categories (2, object): [A, B]

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.7.7.final.0
python-bits : 64
OS : Linux
OS-release : 3.10.0-1062.4.1.el7.x86_64
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.0.5
numpy : 1.18.5
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 49.2.0.post20200714
Cython : None
pytest : 6.0.0
hypothesis : None
sphinx : 3.1.2
blosc : None
feather : None
xlsxwriter : 1.2.9
lxml.etree : 4.5.2
html5lib : None
pymysql : None
psycopg2 : 2.8.5 (dt dec pq3 ext lo64)
jinja2 : 2.11.2
IPython : 7.16.1
pandas_datareader: None
bs4 : None
bottleneck : 1.3.2
fastparquet : 0.3.2
gcsfs : None
lxml.etree : 4.5.2
matplotlib : 3.2.2
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.4
pandas_gbq : None
pyarrow : 0.15.1
pytables : None
pytest : 6.0.0
pyxlsb : None
s3fs : None
scipy : 1.3.1
sqlalchemy : 1.3.18
tables : None
tabulate : 0.8.7
xarray : None
xlrd : None
xlwt : None
xlsxwriter : 1.2.9
numba : 0.50.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDtype ConversionsUnexpected or buggy dtype conversionsExtensionArrayExtending pandas with custom dtypes or arrays.RegressionFunctionality that used to work in a prior pandas version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions