-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
errors='ignore' does not work on df.replace({col : type}) if col not found #30324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I believe that I fixed this issue, and agree that it does not appear to be intended behavior. |
What's the status of this issue? I'm still getting it as of pandas.version == '1.0.3' |
Still an issue on 1.2 Output of pd.show_versions()INSTALLED VERSIONScommit : 3b1d4f1 pandas : 1.2.0.dev0+10.g3b1d4f1ee |
This is still an issue in pandas 2.0.1. import numpy as np
import pandas as pd
df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
print(df.astype({"foo": str}, errors="ignore").dtypes) results in error:
|
@zerothi pandas is all volunteer and there is a large back log. the core team is happy to review any PRs submitted by the community to fix issue that are still open. |
yeah, sorry about the blurp... guidance for solving this issue would be ideal, especially to those unfamiliar with the internals... |
Why raise at all if column is not in the data frame? Shouldn't the For example, I think the best thing to do would be to introduce a parameter, in all functions that accept a dictionary to make conversions, that controls this behaviour (either raise or ignore, if the dictionary contains a mapping that does not exist in the data frame) Btw, the title is wrong. It should have been "... does not work on df.astype()". |
Someone may want to have it raise an error if the column is not found, because code assuming the column exist could have a bug. In my case, want to ensure that in case a certain column is contained, it must have no other type than specified in There are two design considerations:
Workaround: |
This may be considered a feature request
Code Sample, a copy-pastable example if possible
Problem description
A KeyError is still raised if the column name is not found. I'd think
errors='ignore'
should suppress this error, which would make it consistent with other methods, such asdf.rename(errors='ignore')
.Expected Output
Unchanged dataframe.
Output of
pd.show_versions()
[paste the output of
pd.show_versions()
here below this line]INSTALLED VERSIONS
commit : None
python : 3.7.3.final.0
python-bits : 64
OS : Darwin
OS-release : 17.7.0
machine : x86_64
processor : i386
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 0.25.2
numpy : 1.17.2
pytz : 2019.3
dateutil : 2.8.0
pip : 19.3.1
setuptools : 41.4.0
Cython : 0.29.13
pytest : 5.2.1
hypothesis : None
sphinx : 2.2.0
blosc : None
feather : None
xlsxwriter : 1.2.2
lxml.etree : 4.4.1
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.10.3
IPython : 7.8.0
pandas_datareader: None
bs4 : 4.8.1
bottleneck : 1.2.1
fastparquet : None
gcsfs : None
lxml.etree : 4.4.1
matplotlib : 3.1.1
numexpr : 2.7.0
odfpy : None
openpyxl : 3.0.0
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : 1.3.1
sqlalchemy : 1.3.10
tables : 3.5.2
xarray : None
xlrd : 1.2.0
xlwt : 1.3.0
xlsxwriter : 1.2.2
The text was updated successfully, but these errors were encountered: