Skip to content

ENH: Allow apply/agg to accept list-like and dict-like #39140

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
rhshadrach opened this issue Jan 13, 2021 · 1 comment · Fixed by #39141
Closed

ENH: Allow apply/agg to accept list-like and dict-like #39140

rhshadrach opened this issue Jan 13, 2021 · 1 comment · Fixed by #39141
Assignees
Labels
API - Consistency Internal Consistency of API/Behavior Apply Apply, Aggregate, Transform, Map Enhancement
Milestone

Comments

@rhshadrach
Copy link
Member

s = pd.Series([1, 2])
df = pd.DataFrame([1, 2])

# Reducers: list-like
ops = np.array([np.sum, np.mean])
print(df.agg(ops))
print(s.agg(ops))
print(df.apply(ops))
print(s.apply(ops))  # Raises

# Reducers: dict-like
ops = pd.Series({0: np.mean})
print(df.agg(ops))  # Raises
print(s.agg(ops))  # Raises
print(df.apply(ops))  # Raises
print(s.apply(ops))  # Raises

# Transforms - list-like
ops = np.array([np.abs, np.sqrt])
print(df.transform(ops))
print(df.apply(ops))
print(s.transform(ops))
print(s.apply(ops))  # Raises

# Transforms - dict-like
ops = pd.Series({0: np.abs})
print(df.transform(ops))
print(s.transform(ops))
print(s.apply(ops))  # Raises
print(df.apply(ops))  # Raises

All lines that don't raise give the expected output.

@rhshadrach rhshadrach added Enhancement Apply Apply, Aggregate, Transform, Map API - Consistency Internal Consistency of API/Behavior labels Jan 13, 2021
@rhshadrach rhshadrach self-assigned this Jan 13, 2021
@rhshadrach
Copy link
Member Author

For DataFrame.apply, dict-likes that aren't dictionaries work; only using a Series as a dict-like does not because the code uses arg.values() and values is a property of Series.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API - Consistency Internal Consistency of API/Behavior Apply Apply, Aggregate, Transform, Map Enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants