-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
REGR: AssertionError when subtracting Timestamp-valued DataFrames with non-indentical column index #31623
Comments
Thanks for the report. The NaNs are introduced in pandas/pandas/core/ops/__init__.py Line 725 in a2721fd
I wonder, should this be changed? In [6]: df.align(df2)[1]
Out[6]:
bar foo
0 NaN 2019-01-01
1 NaN 2020-01-01 to have |
cc @jbrockmendel. |
ill look at this today |
So this is pretty ugly, but one option that tentatively works is to patch ops._arith_method_FRAME so that we only operate on shared columns, then reindex the result. |
might actually improve perf for cases where we have very few shared columns |
That seems reasonable. The alternative is to ensure that the correct Is that likely to cause issues with methods like |
yah, it would also depend on op, which would become a nightmare. I'll put up a proof of concept in a bit |
@DomKennedy in the meantime, here's a workaround In [14]: import operator
In [15]: operator.sub(*df.align(df2, fill_value=pd.NaT))
Out[15]:
bar foo
0 NaT 0 days
1 NaT 0 days There are lots of issues with that (if you have other columns that don't align, NaT won't be the right fill value) but hopefully not too bad for now. We'll try to get this fixed properly for 1.0.2. |
Problem description
The above snippet raises the following exception:
This is a 1.0.0 regression; in 0.25.3, the operation succeeds and the unmatched
bar
column is filled withNaN
in the output.The same error occurs with:
subtract
method instead of using the subtraction operatorTimestamp
s as well as timezone-naiveIt does not seem to occur with:
pd.Series
objects with mismatched indexes (e.g. calling the above on the first row of each dataframe works fine)bool
,float
, andint
seem to work fine. Similarly, if the dataframes are explicitly cast to dtypeobject
, the operation succeeds.Expected Output
Output of
pd.show_versions()
pandas : 1.0.0
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 19.3.1
setuptools : 41.6.0
Cython : None
pytest : 5.3.5
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : 5.3.5
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None
The text was updated successfully, but these errors were encountered: