Skip to content

ENH: apply_where accept kwargs? #612

@mdhaber

Description

@mdhaber

apply_where is one of a relatively small subset of functions1 that accept a callable f and args and does something useful to the elements of args before passing them to f . If the user's callable f accepts keyword-only arguments, say kwargs, it is still possible to pass kwargs.values() as the args argument of apply_where, then as the callable(s) f1 (and f2, if applicable) something like lambda *args: f(dict(zip(kwargs.keys(), args))). This is somewhat cumbersome and hard to read, so I'd suggest that apply_where accept kwargs natively.

Footnotes

  1. I call this out to distinguish apply_where from the many functions in the scientific Python ecosystem (or at least in SciPy) that accept a callable f also accept args - only to pass them unmodified to f. IMO, this sort of "convenience" behavior bloats API, since it leads users to expect that all functions that accept callables should also accept args. Then, the natural extension of that expectation is for all these functions to also accept kwargs. This is all unnecessary, since the user could have simply passed lambda x: f(x, *args, **kwargs) (or f wrapped with functools.partial) as the callable instead of f, which is approximately as concise and readable. (It would be considered even more readable if it were the only option and universal practice.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions