Skip to content
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

Reading single index DataFrame with pandas > 0.20 causes MultiIndex issue #786

Closed
sdementen opened this issue Dec 14, 2017 · 8 comments
Closed
Milestone

Comments

@sdementen
Copy link
Contributor

During a training session this morning, a call on the laptop of a colleague of the function

@xlwings.func
@xlwings.arg('df', pandas.DataFrame, expand='vertical')
@xlwings.ret(expand="table", index=True)
def my_func(df):
    df.info()
    print(df.columns)

called with a range pointing to the first row of

month_start month
1/01/2018 Jan-18
1/02/2018 Feb-18
1/03/2018 Mar-18
1/04/2018 Apr-18
1/05/2018 May-18
1/06/2018 Jun-18
1/07/2018 Jul-18
1/08/2018 Aug-18
1/09/2018 Sep-18
1/10/2018 Oct-18
1/11/2018 Nov-18
1/12/2018 Dec-18
1/01/2019 Jan-19

prints the following

<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 13 entries, 2018-01-01 to 2019-01-01
Data columns (total 1 columns):
(month,) 13 non-null object
dtypes: object(1)
memory usage: 208.0+ bytes
MultiIndex(levels=[['month', 'month_start']],
           labels=[[0]])

The MultiIndex part is weird as on my laptop I get

<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 13 entries, 2018-01-01 to 2019-01-01
Data columns (total 1 columns):
month    13 non-null object
dtypes: object(1)
memory usage: 208.0+ bytes
Index(['month'], dtype='object')

We were both using xlwings=0.11.4 on a windows 7.0 laptop with Excel 2010.
Any hint of what could give this different behaviours ?

@fzumstein
Copy link
Member

different version of pandas?

@sdementen
Copy link
Contributor Author

it fails on my colleague machine with pandas 0.21.0.
it works on mine with pandas 0.20.3

@sdementen
Copy link
Contributor Author

indeed, downgrading pandas to 0.20.3 fixes the issues
do I close the issue ?

@fzumstein
Copy link
Member

fzumstein commented Dec 21, 2017 via email

pauliacomi added a commit to pauliacomi/xlwings that referenced this issue Dec 27, 2017
@pauliacomi
Copy link
Contributor

I had the same problem. Looking at the pandas 0.21.0 changelog, the issue seems to be related to
this particular change in how a single level MultiIndex is treated.

I put an extra check in the pandas_conv.py module and it now works for me. I could submit a PR if you want.

@fzumstein
Copy link
Member

sure, PR is always helpful!

@pauliacomi
Copy link
Contributor

Opened #789. Ran tests on both pandas 0.20 and 0.21 and works on both.

@andymcarter
Copy link

Hi, ran across this problem a week or so ago and got very confused. Was unknowingly building single level multi-index columns (which look identical to standard indices), then df['col_name'] was returning a dataframe!

Glad to see a fix is on the way for this.

@fzumstein fzumstein added this to the v0.11.5 milestone Jan 7, 2018
@fzumstein fzumstein changed the title UDF parameters with xlwings.args(..., pandas.DataFrame, expand='table') returns multiindex columns Reading single index DataFrame with pandas > 0.20 causes MultiIndex issue Jan 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants