Skip to content

DataFrameGroupBy.ffill with Duplicate Column Labels ValueError #25610

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

Closed
datatravelgit opened this issue Mar 8, 2019 · 3 comments · Fixed by #36326
Closed

DataFrameGroupBy.ffill with Duplicate Column Labels ValueError #25610

datatravelgit opened this issue Mar 8, 2019 · 3 comments · Fixed by #36326
Labels
Groupby Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Needs Tests Unit test(s) needed to prevent regressions
Milestone

Comments

@datatravelgit
Copy link

datatravelgit commented Mar 8, 2019

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

@WillAyd
Copy link
Member

WillAyd commented Mar 9, 2019

OK thanks. This looks like it is a result of having duplicate column labels.

Investigation and PRs would certainly be welcome

@WillAyd WillAyd added Bug Groupby Regression Functionality that used to work in a prior pandas version labels Mar 9, 2019
@WillAyd WillAyd added this to the Contributions Welcome milestone Mar 9, 2019
@WillAyd WillAyd changed the title DataFrameGroupBy.ffill - ValueError: Buffer has wrong number of dimensions (expected 1, got 2) DataFrameGroupBy.ffill with Duplicate Column Labels ValueError Mar 9, 2019
@Itay4
Copy link

Itay4 commented Mar 10, 2019

@WillAyd How would expect this to be handled? Not allow duplicate column labels?

@WillAyd
Copy link
Member

WillAyd commented Mar 10, 2019

@Itay4 I think fine to allow. Probably something in the code base that can be switched to accessing by position instead of labels

@phofl phofl added Needs Tests Unit test(s) needed to prevent regressions and removed Bug Regression Functionality that used to work in a prior pandas version labels Sep 13, 2020
@jreback jreback added the Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate label Sep 13, 2020
@jreback jreback modified the milestones: Contributions Welcome, 1.2 Sep 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Groupby Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Needs Tests Unit test(s) needed to prevent regressions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants