Skip to content

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

Closed
@rhshadrach

Description

@rhshadrach
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.

Metadata

Metadata

Assignees

Labels

API - ConsistencyInternal Consistency of API/BehaviorApplyApply, Aggregate, Transform, MapEnhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions