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

CLN: Don't use astype_nansafe after to_numpy #34110

Merged
merged 2 commits into from
Jun 1, 2020
Merged

CLN: Don't use astype_nansafe after to_numpy #34110

merged 2 commits into from
Jun 1, 2020

Conversation

dsaxton
Copy link
Member

@dsaxton dsaxton commented May 10, 2020

I'm not 100% sure about the change in the tests, but it seems to align with numpy:

[ins] In [1]: np.array([1, 2]).astype(str)                                                                                                                                                                   
Out[1]: array(['1', '2'], dtype='<U21')

[ins] In [2]: pd.array([1, 2]).astype(str)                                                                                                                                                                   
Out[2]: array(['1', '2'], dtype='<U21')
[ins] In [1]: np.array([True, False]).astype(str)                                                                                                                                                            
Out[1]: array(['True', 'False'], dtype='<U5')

[ins] In [2]: pd.array([True, False]).astype(str)                                                                                                                                                            
Out[2]: array(['True', 'False'], dtype='<U5')

@jorisvandenbossche
Copy link
Member

Personally, I think those rather should convert to StringArray

@dsaxton
Copy link
Member Author

dsaxton commented May 11, 2020

Personally, I think those rather should convert to StringArray

Interesting idea, that does seem better

@jreback jreback added the Clean label May 12, 2020
@jreback jreback added this to the 1.1 milestone May 12, 2020
@jreback
Copy link
Contributor

jreback commented May 25, 2020

Personally, I think those rather should convert to StringArray

not at all, str conversion here is NOT the same as string.

@jreback
Copy link
Contributor

jreback commented May 25, 2020

@dsaxton can you merge master

@jorisvandenbossche
Copy link
Member

not at all, str conversion here is NOT the same as string.

That's true. So in pandas, we generally see astype(str) or dtype=str as converting to strings *as object dtype. But that's not what this PR is doing. So the question is whether we want to be consistent with numpy (convert to numpy string dtype), or consistent with pandas (convert to string as object dtype).

But so, I personally think we can already interpret str to mean StringDtype if the array you start with is already using a nullable dtype (it's one thing less to deprecate in the future, and it's not a backwards incompatible change since StringDtype is opt-in anways).

@jreback
Copy link
Contributor

jreback commented May 25, 2020

not at all, str conversion here is NOT the same as string.

That's true. So in pandas, we generally see astype(str) or dtype=str as converting to strings *as object dtype. But that's not what this PR is doing. So the question is whether we want to be consistent with numpy (convert to numpy string dtype), or consistent with pandas (convert to string as object dtype).

But so, I personally think we can already interpret str to mean StringDtype if the array you start with is already using a nullable dtype (it's one thing less to deprecate in the future, and it's not a backwards incompatible change since StringDtype is opt-in anways).

I disagree, we always have str to mean string / object, NEVER string. I think changing this is way out of scope; changing for nullable types is VERY confusing. so -1 on this.

@jorisvandenbossche
Copy link
Member

we always have str to mean string / object,

Which is also not what this PR is doing ...

@jreback jreback added the Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate label Jun 1, 2020
@jreback jreback merged commit 45d0898 into pandas-dev:master Jun 1, 2020
@dsaxton dsaxton deleted the rm-astype_nansafe branch June 1, 2020 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants