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 · Fixed by #18577
Closed

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

Casyfill opened this issue Dec 21, 2017 · 1 comment · Fixed by #18577
Labels
Apply Apply, Aggregate, Transform, Map Duplicate Report Duplicate issue or pull request

Comments

@Casyfill
Copy link

Casyfill 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
Copy link
Contributor

jreback commented Dec 22, 2017

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

@jreback jreback closed this as completed Dec 22, 2017
@jreback jreback added Apply Apply, Aggregate, Transform, Map Duplicate Report Duplicate issue or pull request labels Dec 22, 2017
@jreback jreback added this to the No action milestone Dec 22, 2017
jorisvandenbossche pushed 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
Labels
Apply Apply, Aggregate, Transform, Map Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants