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: support .strftime for datetimelikes (closes #10086) #10110

Merged
merged 1 commit into from Aug 3, 2015

Conversation

Projects
None yet
3 participants
@mortada
Contributor

mortada commented May 12, 2015

closes #10086

@jreback

This comment has been minimized.

Show comment
Hide comment
@jreback

jreback May 12, 2015

Contributor

this works for DatetimeIndex, something broken for PeriodIndex. And should not work for TimedeltaIndex (as I don't think the strftime codes are meaningful). Further want to actually define .strftime on the index itself as well (maybe def strftime(self, format):).

needs tests for the same

Contributor

jreback commented May 12, 2015

this works for DatetimeIndex, something broken for PeriodIndex. And should not work for TimedeltaIndex (as I don't think the strftime codes are meaningful). Further want to actually define .strftime on the index itself as well (maybe def strftime(self, format):).

needs tests for the same

@mortada

This comment has been minimized.

Show comment
Hide comment
@mortada

mortada May 13, 2015

Contributor

that makes sense

I've added to both DatetimeIndex and PeriodIndex. Also added a few tests.

Contributor

mortada commented May 13, 2015

that makes sense

I've added to both DatetimeIndex and PeriodIndex. Also added a few tests.

@jreback

This comment has been minimized.

Show comment
Hide comment
@jreback

jreback May 13, 2015

Contributor

pls add strftime to API.rst
also I think a mini section in time series.rst would be ok too

Contributor

jreback commented May 13, 2015

pls add strftime to API.rst
also I think a mini section in time series.rst would be ok too

Show outdated Hide outdated pandas/tseries/index.py Outdated
@mortada

This comment has been minimized.

Show comment
Hide comment
@mortada

mortada May 14, 2015

Contributor

@jreback it's updated

Contributor

mortada commented May 14, 2015

@jreback it's updated

@mortada

This comment has been minimized.

Show comment
Hide comment
@mortada

mortada Jun 1, 2015

Contributor

@jreback I added a mini section to basics.rst instead, but otherwise this is ready for review

Contributor

mortada commented Jun 1, 2015

@jreback I added a mini section to basics.rst instead, but otherwise this is ready for review

Show outdated Hide outdated doc/source/basics.rst Outdated
def test_strftime(self):
# GH 10086
s = Series(date_range('20130101', periods=5))
result = s.dt.strftime('%Y/%m/%d')

This comment has been minimized.

@jreback

jreback Jun 1, 2015

Contributor

add something with say millseconds, and show various formats for that (e.g. very common to eliminate hh:mm:dd......) and things like that

@jreback

jreback Jun 1, 2015

Contributor

add something with say millseconds, and show various formats for that (e.g. very common to eliminate hh:mm:dd......) and things like that

result = s.dt.strftime('%Y/%m/%d')
expected = Series(['2013/01/01', '2013/01/02', '2013/01/03', '2013/01/04', '2013/01/05'])
tm.assert_series_equal(result, expected)

This comment has been minimized.

@jreback

jreback Jun 1, 2015

Contributor

also test for periods, and a test for an invalid strftime formatter (e.g. the codes, I think raises ValueError)

@jreback

jreback Jun 1, 2015

Contributor

also test for periods, and a test for an invalid strftime formatter (e.g. the codes, I think raises ValueError)

This comment has been minimized.

@jreback

jreback Jul 30, 2015

Contributor

did you add an invalid formatter test?

@jreback

jreback Jul 30, 2015

Contributor

did you add an invalid formatter test?

This comment has been minimized.

@mortada

mortada Jul 30, 2015

Contributor

I did not - I couldn't find a formatter string that would raise, seems like it'd just get printed / ignored when a code is invalid. Do you know an invalid code I could try?

@mortada

mortada Jul 30, 2015

Contributor

I did not - I couldn't find a formatter string that would raise, seems like it'd just get printed / ignored when a code is invalid. Do you know an invalid code I could try?

@jreback

This comment has been minimized.

Show comment
Hide comment
@jreback

jreback Jun 26, 2015

Contributor

can you update for comments. also related to #10442. I want this method to be the 'primary' date-string formatting (though .astype(str) will be supported by calling what this calls, namely .format), but this should be the goto method

copy your example that you added to basics.rst and put in 0.17.0 (in a separate section, maybe datetime-string formatting or somesuch)

Contributor

jreback commented Jun 26, 2015

can you update for comments. also related to #10442. I want this method to be the 'primary' date-string formatting (though .astype(str) will be supported by calling what this calls, namely .format), but this should be the goto method

copy your example that you added to basics.rst and put in 0.17.0 (in a separate section, maybe datetime-string formatting or somesuch)

@mortada

This comment has been minimized.

Show comment
Hide comment
@mortada

mortada Jun 27, 2015

Contributor

@jreback updated according to your comments except for one thing: I couldn't actually find an invalid formatting string that would cause strftime to raise an exception

Contributor

mortada commented Jun 27, 2015

@jreback updated according to your comments except for one thing: I couldn't actually find an invalid formatting string that would cause strftime to raise an exception

@jreback

View changes

Show outdated Hide outdated doc/source/basics.rst Outdated
@jreback

View changes

Show outdated Hide outdated doc/source/whatsnew/v0.17.0.txt Outdated
@jreback

View changes

Show outdated Hide outdated pandas/tseries/period.py Outdated
@jorisvandenbossche

This comment has been minimized.

Show comment
Hide comment
@jorisvandenbossche

jorisvandenbossche Jul 29, 2015

Member

We also have a tslib.format_array_from_datetime function. Can you check if this is faster? (also uses strftime, but the loop is cythonized)

Member

jorisvandenbossche commented Jul 29, 2015

We also have a tslib.format_array_from_datetime function. Can you check if this is faster? (also uses strftime, but the loop is cythonized)

@mortada

This comment has been minimized.

Show comment
Hide comment
@mortada

mortada Jul 30, 2015

Contributor

@jorisvandenbossche sure I'll check

Contributor

mortada commented Jul 30, 2015

@jorisvandenbossche sure I'll check

@jreback

View changes

Show outdated Hide outdated pandas/tseries/period.py Outdated
@jreback

This comment has been minimized.

Show comment
Hide comment
@jreback

jreback Jul 30, 2015

Contributor

@jorisvandenbossche this calls .format(date_format=...) which ultimately calls the cython tslib.format_array_from_datetime, so this is just syntatic sugar.

Contributor

jreback commented Jul 30, 2015

@jorisvandenbossche this calls .format(date_format=...) which ultimately calls the cython tslib.format_array_from_datetime, so this is just syntatic sugar.

@mortada

This comment has been minimized.

Show comment
Hide comment
@mortada

mortada Jul 30, 2015

Contributor

@jreback reordered the lambdas and the if/else as you suggested, also added more unit tests

Contributor

mortada commented Jul 30, 2015

@jreback reordered the lambdas and the if/else as you suggested, also added more unit tests

@jreback

This comment has been minimized.

Show comment
Hide comment
@jreback

jreback Jul 30, 2015

Contributor

ok, lgtm. ping when green.

Contributor

jreback commented Jul 30, 2015

ok, lgtm. ping when green.

@mortada

This comment has been minimized.

Show comment
Hide comment
@mortada

mortada Jul 30, 2015

Contributor

sure will do

Contributor

mortada commented Jul 30, 2015

sure will do

@jorisvandenbossche

View changes

Show outdated Hide outdated doc/source/basics.rst Outdated
@jorisvandenbossche

View changes

Show outdated Hide outdated pandas/tseries/base.py Outdated
@jorisvandenbossche

View changes

Show outdated Hide outdated pandas/tseries/base.py Outdated
@mortada

This comment has been minimized.

Show comment
Hide comment
@mortada

mortada Jul 31, 2015

Contributor

@jorisvandenbossche @jreback updated to return ndarray instead of list

Contributor

mortada commented Jul 31, 2015

@jorisvandenbossche @jreback updated to return ndarray instead of list

@mortada

This comment has been minimized.

Show comment
Hide comment
@mortada

mortada Aug 2, 2015

Contributor

@jorisvandenbossche @jreback it's green now, please take a look

Contributor

mortada commented Aug 2, 2015

@jorisvandenbossche @jreback it's green now, please take a look

@jreback

View changes

Show outdated Hide outdated pandas/tseries/tests/test_timeseries.py Outdated
@jreback

View changes

Show outdated Hide outdated doc/source/whatsnew/v0.17.0.txt Outdated
@jreback

This comment has been minimized.

Show comment
Hide comment
@jreback

jreback Aug 2, 2015

Contributor

@mortada couple of comments. ping when green.

Contributor

jreback commented Aug 2, 2015

@mortada couple of comments. ping when green.

@mortada

This comment has been minimized.

Show comment
Hide comment
@mortada

mortada Aug 3, 2015

Contributor

@jreback updated, please take a look

Contributor

mortada commented Aug 3, 2015

@jreback updated, please take a look

@jreback jreback merged commit 4348781 into pandas-dev:master Aug 3, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@jreback

This comment has been minimized.

Show comment
Hide comment
@jreback

jreback Aug 3, 2015

Contributor

thanks!

Contributor

jreback commented Aug 3, 2015

thanks!

@mortada mortada deleted the mortada:dt_strftime branch Aug 3, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment