Skip to content

BUG: to_csv output formatting for datetimes #30180

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

Closed
wants to merge 2 commits into from

Conversation

burkbre
Copy link

@burkbre burkbre commented Dec 10, 2019

closes #29711

…ssue and provides rounding variable to csv formatter to handle datetimes differently. I decided to try and tackle this issue for one of the classes I am in at university. The issue seems to be stemming from the fact that BlockManager is grouping together two differently formatted datetime values in the DataFrame thus making it so the second datetime value is formatted like the first(leading to the trailing zeroes in the example). If you want to format all datetimes the same in the csv you can simply make use of the date_format attribute which the CsvFormatter takes as a variable to format the datetimes however you like. I decided to add a rounding_milliseconds attribute to the csv formatter which would remove the milliseconds from the end of the datetime if they are all equal to '0'.

  • tests added / passed
  • passes black pandas

…ssue and provides rounding variable to csv formatter to handle datetimes differently.
@pep8speaks
Copy link

pep8speaks commented Dec 10, 2019

Hello @burkbre! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 1365:79: E231 missing whitespace after ','
Line 1370:89: E501 line too long (89 > 88 characters)
Line 1388:79: E231 missing whitespace after ','
Line 1399:89: E501 line too long (89 > 88 characters)
Line 1405:79: E231 missing whitespace after ','
Line 1416:89: E501 line too long (89 > 88 characters)

Comment last updated at 2019-12-10 20:42:15 UTC

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

we are not going to add a keyword arg to to_csv like this. rather I date_format could take a dict of column -> format to handle

@jreback jreback added the Output-Formatting __repr__ of pandas objects, to_string label Dec 10, 2019
@jreback jreback changed the title BUG: Addresses GH29711 issue. Adds test case to expose the original i… BUG: to_csv output formatting for datetimes Dec 10, 2019
@jreback
Copy link
Contributor

jreback commented Dec 10, 2019

pls search the issue queue, IIRC there are a number of issues about this

@WillAyd
Copy link
Member

WillAyd commented Jan 2, 2020

@burkbre is this still active? As mentioned don't want to add new keywords so would need an alternate approach like the dict argument for date_format

@WillAyd
Copy link
Member

WillAyd commented Jan 17, 2020

Thanks @burkbre for the PR but I think has gone stale. I think also needs a different approach but ping if you'd like to continue and can address comments

@WillAyd WillAyd closed this Jan 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dropna Subnet changes timestamp format in to_csv()
4 participants