perf: Avoid redefining lambda in *Namespace.all#2102
Conversation
Mentioned in (#2058 (comment)) Originally in - (028098e) - c597ba7
|
thanks - could you clarify how this helps please? i don't understand the difference, and there aren't any arguments to bind in this function? |
Sure thing @MarcoGorelli Right now, every time def _(df):
return df.columns
...
columns = _(df)By equivalent - I mean if you call def _1(df):
return df.columns
...
columns = _1(df)
def _2(df):
return df.columns
...
columns = _2(df)
def _3(df):
return df.columns
...
columns = _3(df)This change skips defining function each time, so those 3 calls would all be: columns = get_column_names(df)
columns = get_column_names(df)
columns = get_column_names(df)The difference is we didn't need to create a new inline function each time.
What I mean is the scope created by That would be a use-case I'd understand for a narwhals/narwhals/_pandas_like/namespace.py Lines 125 to 132 in 8888e2c Also some links: |
MarcoGorelli
left a comment
There was a problem hiding this comment.
sure, thanks @dangotbanned

What type of PR is this? (check all applicable)
Related issues
kwargsfromselectorfunction #2058 (comment))Checklist
If you have comments or can explain your changes, please do so below
Previously, a new function was created in each of these locations - but it didn't bind any arguments - so there was no benefit to using a
lambda