Skip to content
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

Fix Xl(sx|wt)Writer always using date_format even if a datetime is supplied. #7075

Merged
merged 1 commit into from
May 8, 2014

Conversation

filmor
Copy link
Contributor

@filmor filmor commented May 8, 2014

In the XlsxWriter and XlwtWriter implementations there is a minor bug resulting in the datetime_format being discarded (i.e. https://github.com/pydata/pandas/blob/master/pandas/io/excel.py#L662):

if isinstance(cell.val, datetime.datetime):
    num_format_str = self.datetime_format
if isinstance(cell.val, datetime.date):
    num_format_str = self.date_format

Since datetime.datetime derives from datetime.date the second if-clause in the will always trigger, leading to the num_format_str being overwritten by the date_format.

@filmor filmor changed the title Fix XlsxWriter always using date_format. Fix Xl(sx|wt)Writer always using date_format even if a datetime is supplied. May 8, 2014
@jreback
Copy link
Contributor

jreback commented May 8, 2014

can you add a test for this?

pls add a release note as well (reference this PR) as this doesn't have an associated issue?

@jreback jreback added this to the 0.14.0 milestone May 8, 2014
@filmor
Copy link
Contributor Author

filmor commented May 8, 2014

Adding a test is difficult, as this only shows in Excel itself (by showing 2014-05-08 instead of 2014-05-08 15:23 in a timestamp column). In particular rereading the file will give proper datetime or Timestamp objects again.

I'll add a release-note.

@jreback
Copy link
Contributor

jreback commented May 8, 2014

ok then

@jreback
Copy link
Contributor

jreback commented May 8, 2014

ping when pushed

Since `datetime.datetime` derives from `datetime.date` the second
`if`-clause will always trigger, leading to the `num_format_str` being
overwritten by the `date_format`.
@filmor
Copy link
Contributor Author

filmor commented May 8, 2014

Ping.

jreback added a commit that referenced this pull request May 8, 2014
Fix Xl(sx|wt)Writer always using date_format even if a datetime is supplied.
@jreback jreback merged commit 3ec742a into pandas-dev:master May 8, 2014
@jreback
Copy link
Contributor

jreback commented May 8, 2014

thanks!

@filmor filmor deleted the patch-1 branch May 8, 2014 14:03
@filmor filmor restored the patch-1 branch July 15, 2014 14:47
@filmor filmor deleted the patch-1 branch January 6, 2015 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO Excel read_excel, to_excel Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants