-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: allow conversion of Timestamp and Timedelta to string in astype #9758
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
Conversation
this needs some discussion |
# GH9757 | ||
ts = Series([Timestamp('2010-01-04 00:00:00')]) | ||
ts = ts.astype(str) | ||
self.assertEqual(ts.dtype, np.object_) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be a more specific test. assert what this is actuallly converted.
ok, seems reasonable. can you rebase / squash. ping on green. |
@@ -66,3 +66,4 @@ Bug Fixes | |||
|
|||
|
|||
- Bug in ``Series.quantile`` on empty Series of type ``Datetime`` or ``Timedelta`` (:issue:`9675`) | |||
- Bug causing ``astype(str)`` to fail for dtype ``datetime64`` or ``timedelta64`` (:issue:`9757`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And move this to enhancements (and change wording to say allow astype(str))
@@ -5511,6 +5511,17 @@ def test_astype_str(self): | |||
expec = s.map(compat.text_type) | |||
assert_series_equal(res, expec) | |||
|
|||
# GH9757 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you add a test for converting a dataframe, ideally one with multiple dtypes?
Also, this would test for above astype(unicode)
and astype(str)
on Python 2.
Added a test for |
OK, this seems good to from my perspective. I'll merge unless there are any further objections.... |
ns = Series(range(5)) | ||
fs = Series([0.0, 0.2, 0.4, 0.6, 0.8]) | ||
|
||
df = pd.DataFrame({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just for consistency can u add an index with a timezone (and also do a test on a time stamp with a timezone separately)
I've totally borked this branch with an accidental force push. I'll fix it tonight. On the positive side, I finally learned what push.default=simple does :). |
Should be fixed. |
BUG: allow conversion of Timestamp and Timedelta to string in astype
Thanks @evanpw |
Fixes GH #9757