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 from pandas/core/construction.py #53112

Merged
merged 5 commits into from
May 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions pandas/core/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,7 @@ def sanitize_masked_array(data: ma.MaskedArray) -> np.ndarray:
if mask.any():
dtype, fill_value = maybe_promote(data.dtype, np.nan)
dtype = cast(np.dtype, dtype)
# Incompatible types in assignment (expression has type "ndarray[Any,
# dtype[Any]]", variable has type "MaskedArray[Any, Any]")
data = data.astype(dtype, copy=True) # type: ignore[assignment]
data = ma.asarray(data.astype(dtype, copy=True))
Copy link
Member

Choose a reason for hiding this comment

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

thanks for your PR - would it work to just rename data? looks like the issue that it's getting reassigned to a different type

something like

    data_newname = data.astype(dtype, copy=True)
    data_newname.soften_mask()
    data_newname[mask] = fill_value
    return data_newname
else:
    return data.copy()

(the hardest part would arguably be coming up with a good name, i.e. not data_newname but something more descriptive, but I haven't looked at this carefully enough yet to think of what)

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, @MarcoGorelli for your comment. I will do, as you suggest. What do you think, could be sanitized_data or sanitized_ma a suitable new name for data?

data.soften_mask() # set hardmask False if it was True
data[mask] = fill_value
else:
Expand Down