Skip to content

Crash when using align between a Series and a DataFrame and ffill (or bfill) method #31785

Closed
@m-lal

Description

@m-lal

Code Sample, a copy-pastable example if possible

# Your code here
import pandas as pd

x = pd.Series(range(10), index=range(10))
y = pd.DataFrame(0.0, index=range(20), columns=range(12))

# works fine (no fill method)
x.align(y)

# crash
x.align(y, method='ffill')

# works fine if x is converted to a DataFrame
x.to_frame().align(y, method='ffill')

Problem description

This problem only occurs on pandas version >= 1.0.0
Pretty simple bug to reproduce... Quite a serious issue! It should probably shows elsewhere also.

**When using align between a Series and a DataFrame with a fill method the code hits this

assert isinstance(obj, type(self)), type(obj)
AssertionError: <class 'pandas.core.frame.DataFrame'>**

My guess is that isinstance(obj, type(self)) try to assert that a Series is a DataFrame which is not the case.

Expected Output

Similar to x.align(y), with forward filled values.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.7.4.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 85 Stepping 4, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None
pandas : 1.0.1
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 19.0.3
setuptools : 40.8.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.8.4 (dt dec pq3 ext lo64)
jinja2 : None
IPython : 7.12.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.1.3
numexpr : 2.7.1
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : 3.6.1
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : 0.48.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    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