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

ENH: Add na_value to DataFrame.to_numpy #33820

Closed
TomAugspurger opened this issue Apr 27, 2020 · 1 comment · Fixed by #33857
Closed

ENH: Add na_value to DataFrame.to_numpy #33820

TomAugspurger opened this issue Apr 27, 2020 · 1 comment · Fixed by #33857
Labels
API - Consistency Internal Consistency of API/Behavior API Design Enhancement
Milestone

Comments

@TomAugspurger
Copy link
Contributor

Is your feature request related to a problem?

Control the NA value used when converting a DataFrame to an ndarray.

Describe the solution you'd like

Add an na_value argument to DataFrame.to_numpy(). Has the same meaning as na_value in Series.to_numpy, except it applies to all the columns.

Additional context

In [8]: df = pd.DataFrame({"A": pd.array([1, None])})

In [9]: df.to_numpy(na_value=np.nan)

This has come up in a few places (cc @jorisvandenbossche @dsaxton)

@TomAugspurger TomAugspurger added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 27, 2020
@TomAugspurger TomAugspurger added this to the 1.1 milestone Apr 27, 2020
@TomAugspurger TomAugspurger added API - Consistency Internal Consistency of API/Behavior API Design and removed Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 27, 2020
@dsaxton
Copy link
Member

dsaxton commented Apr 28, 2020

Thanks @TomAugspurger. #33809 took the approach of using DataFrame.astype(float).to_numpy() to coerce NA to np.nan which should likely be fixed once this becomes available.

mat = numeric_df.astype(float, copy=False).to_numpy()

@simonjayhawkins simonjayhawkins changed the title ENH: Add na_value to DataFrame.to_nupmy ENH: Add na_value to DataFrame.to_numpy Apr 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API - Consistency Internal Consistency of API/Behavior API Design Enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants