Skip to content

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

Merged
merged 2 commits into from
Apr 10, 2015

Conversation

evanpw
Copy link
Contributor

@evanpw evanpw commented Mar 31, 2015

Fixes GH #9757

@jreback
Copy link
Contributor

jreback commented Mar 31, 2015

this needs some discussion
pls post in the issue why this should actually be allowed
this is string formatting and not the meaning of astype

# GH9757
ts = Series([Timestamp('2010-01-04 00:00:00')])
ts = ts.astype(str)
self.assertEqual(ts.dtype, np.object_)
Copy link
Contributor

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.

@jreback jreback added Datetime Datetime data dtype API Design Timedelta Timedelta data type labels Apr 2, 2015
@jreback
Copy link
Contributor

jreback commented Apr 8, 2015

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`)
Copy link
Contributor

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))

@jreback jreback added this to the 0.16.1 milestone Apr 8, 2015
@@ -5511,6 +5511,17 @@ def test_astype_str(self):
expec = s.map(compat.text_type)
assert_series_equal(res, expec)

# GH9757
Copy link
Member

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.

@evanpw
Copy link
Contributor Author

evanpw commented Apr 9, 2015

Added a test for astype(unicode) on Python 2, and a test for DataFrame.

@shoyer
Copy link
Member

shoyer commented Apr 9, 2015

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({
Copy link
Contributor

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)

@evanpw
Copy link
Contributor Author

evanpw commented Apr 9, 2015

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 :).

@evanpw
Copy link
Contributor Author

evanpw commented Apr 10, 2015

Should be fixed.

shoyer added a commit that referenced this pull request Apr 10, 2015
BUG: allow conversion of Timestamp and Timedelta to string in astype
@shoyer shoyer merged commit 9b842a0 into pandas-dev:master Apr 10, 2015
@shoyer
Copy link
Member

shoyer commented Apr 10, 2015

Thanks @evanpw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Datetime Datetime data dtype Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants