Description
Code Sample, a copy-pastable example if possible
import pandas as pd
import numpy as np
df1 = pd.DataFrame({'field1': [1, 2, 3, 4],
'field2': [1, 2, 3, 4],
'field3': [1, 2, 3, 4]
})
df2 = pd.DataFrame({'field1': [1, 2, np.nan, 4],
})
same_col = pd.concat([df1, df2], axis=1)
print(same_col)
# field1 field2 field3 field1
# 0 1 1 1 1.0
# 1 2 2 2 2.0
# 2 3 3 3 NaN
# 3 4 4 4 4.0
print(same_col.ffill())
# field1 field2 field3 field1
# 0 1 1 1 1.0
# 1 2 2 2 2.0
# 2 3 3 3 2.0
# 3 4 4 4 4.0
for k, v in same_col.groupby(by=['field2']):
print(v.ffill())
# field1 field2 field3 field1
# 0 1 1 1 1.0
# field1 field2 field3 field1
# 1 2 2 2 2.0
# field1 field2 field3 field1
# 2 3 3 3 NaN
# field1 field2 field3 field1
# 3 4 4 4 4.0
same_col.groupby(by=['field2']).ffill()
ValueError: Buffer has wrong number of dimensions (expected 1, got 2)
Problem description
A DataFrameGroupBy.ffill with 2 or more column with the same name produce an error:
ValueError: Buffer has wrong number of dimensions (expected 1, got 2)
Pandas 0.22.0 did not have this bud. It seems that it was introduced recently. Or if this is an expected behaviour, it must be consistent with the behaviour of a DataFrame.ffill with 2 or more column with the same name and have a meaningful error.
Expected Output
# field1 field2 field3 field1
# 0 1 1 1 1.0
# 1 2 2 2 2.0
# 2 3 3 3 NaN
# 3 4 4 4 4.0
Output of pd.show_versions()
[paste the output of pd.show_versions()
here below this line]
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.7.1.final.0
python-bits: 64
OS: Darwin
OS-release: 18.2.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: None
LOCALE: en_GB.UTF-8
pandas: 0.24.1
pytest: None
pip: 10.0.1
setuptools: 39.1.0
Cython: None
numpy: 1.16.2
scipy: None
pyarrow: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.8.0
pytz: 2018.9
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml.etree: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None