question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`DataFrame.apply` stub doesn't reflect default value of `axis` parameter

See original GitHub issue

Describe the bug If you call DataFrame.apply and pass parameters beyond f but not including axis, you’ll get the following error from Pyright:

No overloads for "apply" match the provided arguments

To Reproduce

import pandas as pd

def gethead(s, y):
    return s.head(y)

df = pd.DataFrame({"A": [1, 2, 3, 4, 5, 6], "B": [11, 12, 13, 14, 15, 16]})

df2 = df.apply(gethead, args=tuple([4]))  # error

Pylance gives the following error on the apply call:

No overloads for "apply" match the provided arguments
  Argument types: ((s: Unknown, y: Unknown) -> Unknown, tuple[int, ...])Pylance[reportGeneralTypeIssues](https://github.com/microsoft/pylance-release/blob/main/DIAGNOSTIC_SEVERITY_RULES.md#diagnostic-severity-rules)

Please complete the following information:

  • OS: Windows
  • OS Version: 10.0.25197 Build 25197
  • python version: 3.10.0
  • version of type checker: Pylance 2022.10.21
  • version of installed pandas-stubs: 1.5.0.220926

Additional context Originally reported by @jonmooser at https://github.com/microsoft/pylance-release/issues/3491

I was originally thinking that the fix was to indicate in the stubs that axis has a default value (axis: AxisType = ...), but then the two overloads of apply overlap with each other. It was looking like the correct fix would require more knowledge of the innards of apply and Pandas in general than I have.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
Dr-Irvcommented, Oct 27, 2022

fixed in #401

0reactions
Dr-Irvcommented, Oct 19, 2022

But I think the underlying problem here may be a bit different. None of the overloads allows for an args param with no axis param.

We need to have a new overload, where the return type is based on whether the function f is Callable[..., ScalarT] or Callable[..., list-like], where list-like is appropriately defined.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dataframe apply doesn't accept axis argument - Stack Overflow
So far I am trying to perform an apply function that will return me this structure, but the dataframe apply is not accepting...
Read more >
Why isn't my Pandas .apply working? Try axis=1 - Medium
What's going on here? The default for .apply is axis=0. axis=0, pass the df index to the function; axis=1, pass the ...
Read more >
What's New — pandas 0.23.0 documentation - PyData |
DataFrame.apply() was inconsistent when applying an arbitrary user-defined-function that returned a list-like with axis=1 . Several bugs and inconsistencies ...
Read more >
Pandas DataFrame apply() Examples - DigitalOcean
axis : axis along which the function is applied. The possible values are {0 or 'index', 1 or 'columns'}, default 0. args: The...
Read more >
SWAT USER GROUP
changed land use and soil maps and tested all changes in parameters ... instance, my initial N-S for winter flow was 0.64 with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found