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

Fix Series.astype to work properly #1818

Merged
merged 3 commits into from
Oct 7, 2020
Merged

Conversation

itholic
Copy link
Contributor

@itholic itholic commented Oct 5, 2020

This should fix #1806

>>> data = ks.Series(['a', 'b', 'c', None])
>>> sorted(data.astype(str).tolist())
['None', 'a', 'b', 'c']

For DataFrame.astype also works.

>>> kdf
   A     B     C
0  3  10.0     a
1  4  20.0     b
2  5  30.0     c
3  6  40.0     d
4  7  50.0  None

>>> sorted(kdf.astype(str).C.tolist())
['None', 'a', 'b', 'c', 'd']

@itholic
Copy link
Contributor Author

itholic commented Oct 6, 2020

Hmm... pandas>=1.1.1 seems work differently for None.

>>> pser = pd.Series(["hi", "hi ", " ", " \t", "", None], name="x")
>>> pser
0      hi
1     hi
2
3      \t
4
5    None
Name: x, dtype: object

>>> pser.astype(str)
0     hi
1    hi
2
3     \t
4
5    nan  # casted to `nan`
Name: x, dtype: object

Will report to pandas repo if this behavior is intended because it's not even written in the What's new in pandas 1.1.1

Comment on lines +1126 to +1128
# TODO: restore after pandas 1.1.4 is released.
# self.assert_eq(kser.astype(str).tolist(), pser.astype(str).tolist())
self.assert_eq(kser.astype(str).tolist(), ["hi", "hi ", " ", " \t", "", "None"])
Copy link
Contributor Author

@itholic itholic Oct 7, 2020

Choose a reason for hiding this comment

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

After pandas 1.1.4 is released and fixed related bug, I'll come back here to restore this.

Related issue: pandas-dev/pandas#36904 (comment)

@itholic
Copy link
Contributor Author

itholic commented Oct 7, 2020

I'd merge this now and revisit later for #1818 (comment)

@itholic itholic merged commit 399126b into databricks:master Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

astype() handling of None
1 participant