Skip to content

BUG: PandasArray.to_numpy mishandles na_value #40638

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

Closed
mzeitlin11 opened this issue Mar 25, 2021 · 1 comment · Fixed by #50331
Closed

BUG: PandasArray.to_numpy mishandles na_value #40638

mzeitlin11 opened this issue Mar 25, 2021 · 1 comment · Fixed by #50331
Assignees
Labels
Bug ExtensionArray Extending pandas with custom dtypes or arrays. NA - MaskedArrays Related to pd.NA and nullable extension arrays

Comments

@mzeitlin11
Copy link
Member

Problem is here:

result = np.asarray(self._ndarray, dtype=dtype)
if (copy or na_value is not lib.no_default) and result is self._ndarray:
result = result.copy()
if na_value is not lib.no_default:
result[self.isna()] = na_value

Since na_value is handled after the dtype conversion, calls like

arr = pd.array([pd.NA, 1], dtype="string")
arr.to_numpy(na_value=True, dtype=bool)

fail.

@mzeitlin11 mzeitlin11 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 25, 2021
@Sudomarko
Copy link

take

Sudomarko added a commit to Sudomarko/pandas that referenced this issue Apr 18, 2021
Sudomarko added a commit to Sudomarko/pandas that referenced this issue Apr 19, 2021
@lithomas1 lithomas1 added ExtensionArray Extending pandas with custom dtypes or arrays. NA - MaskedArrays Related to pd.NA and nullable extension arrays and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug ExtensionArray Extending pandas with custom dtypes or arrays. NA - MaskedArrays Related to pd.NA and nullable extension arrays
Projects
None yet
3 participants