-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: to_csv() date formatting #4313
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
I think only bug fixes for now. Really trying to get v0.12 out ASAP! |
Alright, just wanted to check. Thanks. |
Btw Thanks for the Pr! |
@qwhelan I think you need to either raise or warn if the stringified datetimes are not == to the current otherwise its pretty easy to chop say datetimes to dates (which is fine, except it should be done explicity by resetting the index, rather than a typo/incorrect format)
|
@jreback I don't see |
yep have to add it (that's why I put it out there!) |
@qwhelan can you rebase to current? this looks pretty good otherwise |
@qwhelan this somehow got lost....can you rebase to current master.....can get this in for 0.13...thxs |
also...need to make sure this handles |
perf test? |
Sorry for neglecting this. I'll make the changes later this week. |
Added a perf test and tested/handled NaTs. I was caught in rebase hell for the last week, but it should be ready to go unless there are additional requests. |
move example to 0.13.0 (from 0.12) |
rvalues.flat[imask] = np.array( | ||
[Timestamp(val)._repr_base for val in values.ravel()[imask]], dtype=object) | ||
|
||
if self.dtype == 'datetime64[ns]': |
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 changed in master, (as the timedelta stuff was moved); pls start with the current and don't add (which prob happened in a rebase)
@qwhelan almost there....just need those 2 changes! |
@jreback Just pushed the changes. Let me know if you're looking for something different. |
@qwhelan can you move the v0.12.0 announcement to v0.13.0? |
@jreback Made those changes. |
@@ -1001,7 +1017,15 @@ def _helper_csv(self, writer, na_rep=None, cols=None, | |||
if float_format is not None and com.is_float(val): | |||
val = float_format % val | |||
elif isinstance(val, np.datetime64): | |||
val = lib.Timestamp(val)._repr_base |
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 can all be collapsed down, something like:
if date_format is None:
date_formatter = lambda x: x._repr_base
else
date_formatter = lambda x: x.strftime(date_format) if notnull(x)
if isinstance(val, (np.datetime64, datetime.datetime)):
val = date_formatter(lib.Timestamp(val))
@qwhelan can you update to my comments....? |
DOC: add date_format to release notes
@jreback All done. Thanks for the suggestions. |
thanks...merged |
This commit adds support for formatting datetime object output from to_csv()
closes #2583
The
date_format=
keyword will be applied to every element of a DatetimeIndex (index or columns) and DatetimeBlock (values). It works for both the Python engine and the new Cython engine:Let me know if there are any questions or issues.