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

df.apply ignores reduce=True, if function returns list #18901

Closed
Casyfill opened this Issue Dec 21, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@Casyfill
Copy link

commented Dec 21, 2017

def get_candidates_3(closing, sales, settings: dict=_default_) -> list:
        
    S = sales.loc[:closing['future_cap'], :]  # sales were sorted by date beforehand
    mask = (S['building_id'] == closing['building_id'])|(S['unit_bbl'] == closing['bbl'])
    ... 
    if mask.any():
        return S.loc[mask, 'id'].tolist()
    return []

sample.apply(get_candidates_3, reduce=True, axis=1,
             sales=sales_ts,settings=_default_)

( python 3.6, pandas 0.21.0 )

The behavior I want to achieve is to get a single column of lists.
However, despite reduce=True this apply tries to map returned list as a series (?), raising the following:

ValueError: Shape of passed values is (10, 8), indices imply (10, 23)
(here, 10 is the size of the sample, 23 is the number of columns in the sample, 8 is the number of elements in the list that was returned for the first column?

When I change get_candidates_3 to return set instead, I get a full new dataframe of the same shape (10,23), filled with exactly the same sets row-wise, instead.

I am pretty sure I was using the same pattern successfully with a previous version...

@jreback

This comment has been minimized.

Copy link
Contributor

commented Dec 22, 2017

this is related to the other 10 issues duplicated and closed by #18577

@jreback jreback closed this Dec 22, 2017

@jreback jreback added this to the No action milestone Dec 22, 2017

jorisvandenbossche added a commit that referenced this issue Feb 7, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.