Skip to content

fix: DataFrame.assign None #1238

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

Merged
merged 1 commit into from
Jun 3, 2025

Conversation

cmp0xff
Copy link
Contributor

@cmp0xff cmp0xff commented Jun 3, 2025

- [ ] Closes #xxxx (Replace xxxx with the Github issue number)

  • Tests added: Please use assert_type() to assert the type of any return value

Describe the bug

Assigning a None column using DataFrame.assign causes a typing error.

To Reproduce

Provide a minimal runnable pandas example that is not properly checked by the stubs.

import pandas as pd

pd.DataFrame({"a": [1]}).assign(c=None)

Indicate which type checker you are using (mypy or pyright).

mypy

Show the error message received from that type checker while checking your example.

assign.py:3:35: error: Argument "c" to "assign" of "DataFrame" has incompatible type "None"; expected "ExtensionArray | ndarray[Any, Any] | Index[Any] | Series[Any] | str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any] | Callable[[DataFrame], ExtensionArray | ndarray[Any, Any] | Index[Any] | Series[Any] | str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]]"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

Please complete the following information

OS

Windows

OS Version

10

python version

3.13.2

version of type checker

1.16.0

version of installed pandas-stubs

2.2.3.250527

Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @cmp0xff

@Dr-Irv Dr-Irv merged commit 4bf9af2 into pandas-dev:main Jun 3, 2025
13 checks passed
@cmp0xff cmp0xff deleted the hotfix/cmp0xff/assign-none branch June 3, 2025 21:27
cmp0xff added a commit to cmp0xff/pandas-stubs that referenced this pull request Jun 4, 2025
cmp0xff added a commit to cmp0xff/pandas-stubs that referenced this pull request Jun 4, 2025
Dr-Irv pushed a commit that referenced this pull request Jun 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants