-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: Excel writer takes locale setting for date and datetime into account #5583
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 have officially added it to my todo list - I'll take a look soon - but |
this is okay, but I don't want to merge yet...I'm not sure how the defaults work with the writers and I'd rather match them. Allowing users to specify date format is a good thing though (but I'd imagine there must be engine-specific ways to do that?) @jmcnamara - do you have thoughts on this? |
A couple of comments on this:
Excel allows a limited number of date formats which adjust automatically to regional settings. For example in the number format dialog in Excel you will see a message like this:
Xlsxwriter allows the regional date formats to be set. I'm not sure about I would suggest that the localisation part of this PR is dropped and that the keyword |
I have made a version following the suggestion of jmcnamara. You can set date_format and datetime_format arguments, but if you don't the behavior does not change in contrast to previous versions. |
@jmcnamara I hope it fulfils all requirements now? |
@@ -355,6 +355,11 @@ class ExcelWriter(object): | |||
Engine to use for writing. If None, defaults to | |||
``io.excel.<extension>.writer``. NOTE: can only be passed as a keyword | |||
argument. | |||
date_format : string, default None | |||
Format string for dates written into Excel files (e.g. 'YYYY-MM-DD') | |||
datetime_format : sting, default None |
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.
Small typo "sting" -> "string"
@Jaydyou Apart from the couple of minor issues above that looks good. I'll pull down your fork and do some local testing. |
There is a typo in the new testcase name so the test doesn't get run. Also, # At the start add date to the datetime import:
from datetime import datetime, date
...
def test_excel_date_datetime_format(self):
df = DataFrame([[date(2014, 1, 31),
date(1999, 9, 24)],
[datetime(1998, 5, 26, 23, 33, 4),
datetime(2014, 2, 28, 13, 5, 13)]],
index=['DATE', 'DATETIME'], columns=['X', 'Y'])
... However, after that the tests fail. Try running the new test on its own:
|
I have improved my test setup and double checked if everything is working as expected now. Please try the latest version. |
@@ -70,6 +70,8 @@ New features | |||
- Added ``FY5253``, and ``FY5253Quarter`` DateOffsets (:issue:`4511`) | |||
- Added ``mode()`` method to ``Series`` and ``DataFrame`` to get the | |||
statistical mode(s) of a column/series. (:issue:`5367`) | |||
- Added ``date_format`` and ``datetime_format`` attribute to ExcelWriter. | |||
(:issue:`4133`) |
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 release notes needs to be moved to the 0.14 section
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.
correct...now called 0.13.1
@Jaydyou can you rebase, remove the tracking branch commit Jaydyou@d0963b2 thanks |
with ExcelWriter(date_format='YYYY-MM-DD', datetime_format='YYYY-MM-DD HH:MM:SS') you can set the formatstrings for Excel export
The travis fail was spurious, restarted and now green. |
does this close #4133? or is it just the comments near the end? |
@Jaydyou I think we need to test this on all engines to see if it works @jmcnamara right? |
@@ -355,6 +355,11 @@ class ExcelWriter(object): | |||
Engine to use for writing. If None, defaults to | |||
``io.excel.<extension>.writer``. NOTE: can only be passed as a keyword | |||
argument. | |||
date_format : string, default None | |||
Format string for dates written into Excel files (e.g. 'YYYY-MM-DD') |
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 needs to be added to io.rst (in the excel section) as well with a small example
- pls add the same example in v0.13.1.txt as well
@jreback The way the excel.py tests are structured now each test gets run with each engine. |
@jmcnamara ok great |
@Jaydyou just need those small doc updates and can get this in |
merged via 19ae1dc thanks! |
I think this also closes #976. |
closes #4133
Based on the locale setting the date and datetime values are formatted in
excel exports. Moreover the this behaviour can be overruled by keyword
arguments. Old behavior can be enforced by
ExcelWriter(file, date_format='YYYY-MM-DD', datetime_format='YYYY-MM-DD HH:MM:SS')