Skip to content
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

TYP: remove mypy ignore[assignment] from pandas/core/internals/construction.py #53135

Merged
merged 3 commits into from
May 12, 2023

Conversation

natmokval
Copy link
Contributor

Related to #37715
mypy ignore[assignment] was removed from pandas/core/internals/construction.py

@natmokval natmokval changed the title TYP: mypy ignore[assignment] was removed from pandas/core/internals/construction.py TYP: remove mypy ignore[assignment] from pandas/core/internals/construction.py May 8, 2023
@natmokval natmokval marked this pull request as ready for review May 8, 2023 11:30
@natmokval
Copy link
Contributor Author

Hi @MarcoGorelli, could you please take a look at this pr?

@mroeschke mroeschke added the Typing type annotations, mypy/pyright type checking label May 8, 2023
Comment on lines 690 to 693
# Incompatible types in assignment (expression has type
# "List[Union[ExtensionArray, ndarray[Any, Any], None]]", variable
# has type "List[Union[ExtensionArray, ndarray[Any, Any]]]")
arrays = new_arrays # type: ignore[assignment]
arrays = cast(list[ArrayLike], new_arrays)
Copy link
Member

@MarcoGorelli MarcoGorelli May 11, 2023

Choose a reason for hiding this comment

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

is it possible to refactor instead of casting? it might be possible to be more precise here

something like

            new_arrays: list[ArrayLike] = []
            indexer = arr_columns.get_indexer(columns)
            for i, k in enumerate(indexer):
                if k == -1:
                    # by convention default is all-NaN object dtype
                    arr = np.empty(length, dtype=object)
                    arr.fill(np.nan)
                else:
                    arr = arrays[k]
                new_arrays.append(arr)

then the cast might not be necessary? haven't tried running this (currently on a train 🚋), but hoping this might work

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, I did as you suggested. It works very well.

@MarcoGorelli MarcoGorelli added this to the 2.1 milestone May 11, 2023
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

should be good, lgtm on green, thanks @natmokval!

@MarcoGorelli
Copy link
Member

let's ship it

if you're interested in typing, I'd highly suggest you take a look at https://github.com/pandas-dev/pandas-stubs - that affects the type hints which users get, there's plenty of really useful issues to work on there (and feel free to reach out to Irv if you're not sure where to start)

@MarcoGorelli MarcoGorelli merged commit 779a0ff into pandas-dev:main May 12, 2023
Rylie-W pushed a commit to Rylie-W/pandas that referenced this pull request May 19, 2023
…uction.py (pandas-dev#53135)

* remove mypy ignore[assignment]

* replace casting with refactoring
Daquisu pushed a commit to Daquisu/pandas that referenced this pull request Jul 8, 2023
…uction.py (pandas-dev#53135)

* remove mypy ignore[assignment]

* replace casting with refactoring
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants