-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: replace fails with IndexError when regex parameter is passed a dictionary with multiple items #39338
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
@phofl I'd like to contribute here. This will be my first time with |
Hey, this is a tricky bug. The actual replace is done on object Blocks (this is an internal structure). At the beginning we have an object block representing both columns. After replacing the empty string with nan, the object block is split into two Object blocks, this causes the indexing error. I thinkt the split should not happen, but I am not an expert here either. |
Interesting, I'll have a look at the source code and see if I can solve this. |
@phofl I saw that there is a split of |
Haven't looked deeply enough, but this seemed odd to me. When you create a DataFrame with nans in object columns this is stored as one object block, for example
has one object block. You can see this with
Ths casts the second column to float, hence there is a split necessary. |
working in 1.1.5, labelling as regression
|
starting failing with first bad commit: [4f2251c] REF: implement Block._replace_list (#36020) cc @jbrockmendel but at this point the traceback was
|
moving to 1.2.3 |
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, a copy-pastable example
Problem description
In the dataframe columns specified by the non_string_column variable, the above code should be replacing all the blanks with np.nan and removing all the commas.
If I change the replace to look like the following, the dataframe is correct.
Expected Output
I expected the dataframe to look like the following:
I get this error whether I am using Python 3.8.3 or 3.9.1. Also, the numpy version under Python 3.9.1 is 1.19.5.
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : 9d598a5
python : 3.8.3.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.17763
machine : AMD64
processor : Intel64 Family 6 Model 58 Stepping 0, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : English_United States.1252
pandas : 1.2.1
numpy : 1.18.2
pytz : 2020.1
dateutil : 2.8.1
pip : 20.3.3
setuptools : 41.2.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.18.1
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 1.3.15
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
None
The text was updated successfully, but these errors were encountered: