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
Problem with datetime #4557
Comments
I can not reproduce this.
Does
give you the same result in both cases? what version of mpl are you using and how did you install it? |
perhaps this is a locale issue? On Fri, Jun 26, 2015 at 12:03 PM, Thomas A Caswell <notifications@github.com
|
I install matplotlib through pip3 datetime.__file__ return in both case : import matplotlib
print(matplotlib.__version__)
print(matplotlib.__file__)
print(matplotlib.get_configdir()) return : |
What is the native locale of your machine? |
I'm not sure it's respond to the question but the command : $ locale return : LANG=en_US.UTF-8 |
On Mon, Jun 29, 2015 at 11:27 AM, Jean-Baptiste PHILIPPE <
Could you try the french word for September? LC_TIME indicates that it is |
Do the French month abbreviations work after you import matplotlib? My guess as to what is happening is that mpl is inspecting the Can you get the same error from just importing |
I test with 'Sep' because I assume it's the same in french(Septembre) and English(September).
|
The documentation reads to me like it is just using an example for Dutch. What does datetime.strptime("Sep", '%b')
import locale
datetime.strptime("Sep", '%b') do on your system? |
This looks like things working correctly, but not in the way you expect. In [1]: import locale
In [2]: from datetime import datetime
In [3]: datetime.strptime("Sep", '%b')
Out[3]: datetime.datetime(1900, 9, 1, 0, 0)
In [4]: locale.setlocale(locale.LC_TIME, 'fr_FR.UTF-8')
Out[4]: 'fr_FR.UTF-8'
In [5]: datetime.strptime("Sep", '%b')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-5-2fa518be5c22> in <module>()
----> 1 datetime.strptime("Sep", '%b')
/home/tcaswell/.virtualenvs/dd_3k/lib/python3.4/_strptime.py in _strptime_datetime(cls, data_string, format)
498 """Return a class cls instance based on the input string and the
499 format string."""
--> 500 tt, fraction = _strptime(data_string, format)
501 tzname, gmtoff = tt[-2:]
502 args = tt[:6] + (fraction,)
/home/tcaswell/.virtualenvs/dd_3k/lib/python3.4/_strptime.py in _strptime(data_string, format)
335 if not found:
336 raise ValueError("time data %r does not match format %r" %
--> 337 (data_string, format))
338 if len(data_string) != found.end():
339 raise ValueError("unconverted data remains: %s" %
ValueError: time data 'Sep' does not match format '%b' (to get this to run I had to generate the French locale files on my system) It looks like in the top-level ex 12:20 $ LC_TIME=fr_FR.UTF-8 python
Python 3.4.3 |Continuum Analytics, Inc.| (default, Jun 4 2015, 15:29:08)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import datetime
>>> datetime.strptime("Sep", '%b')
datetime.datetime(1900, 9, 1, 0, 0)
>>> import locale
>>> locale.setlocale(locale.LC_ALL, '')
'LC_CTYPE=en_US.UTF-8;LC_NUMERIC=en_US.UTF-8;LC_TIME=fr_FR.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=en_US.UTF-8;LC_ADDRESS=en_US.UTF-8;LC_TELEPHONE=en_US.UTF-8;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=en_US.UTF-8'
>>> datetime.strptime("Sep", '%b')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/tcaswell/.virtualenvs/dd_3k/lib/python3.4/_strptime.py", line 500, in _strptime_datetime
tt, fraction = _strptime(data_string, format)
File "/home/tcaswell/.virtualenvs/dd_3k/lib/python3.4/_strptime.py", line 337, in _strptime
(data_string, format))
ValueError: time data 'Sep' does not match format '%b'
>>> If I set that rcparam to True I can reproduce this: (dd_3k) ✔ ~
12:26 $ LC_TIME=fr_FR.UTF-8 python
Python 3.4.3 |Continuum Analytics, Inc.| (default, Jun 4 2015, 15:29:08)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import datetime
>>> datetime.strptime("Sep", '%b')
datetime.datetime(1900, 9, 1, 0, 0)
>>> import matplotlib
>>> datetime.strptime("Sep", '%b')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/tcaswell/.virtualenvs/dd_3k/lib/python3.4/_strptime.py", line 500, in _strptime_datetime
tt, fraction = _strptime(data_string, format)
File "/home/tcaswell/.virtualenvs/dd_3k/lib/python3.4/_strptime.py", line 337, in _strptime
(data_string, format))
ValueError: time data 'Sep' does not match format '%b'
>>>
>>> datetime.now().strftime('%b')
'juil.'
>>> I do not think this is a bug, I think this is the system behaving in the intended way (even if that way is a bit annoying). Note the flip side of this is that you get dates printed out in the locale you have set. If you need to be able to parse dates in a given locale, see http://stackoverflow.com/questions/18593661/how-do-i-strftime-a-date-object-in-a-different-locale |
Sorry that last message is rather rambling, I was sorting out out while I was writing. |
Thank, now I understand. from matplotlib import pyplot as plt
from datetime import datetime
for i in range(1,13):
date = datetime.strptime(str(i), '%m')
print(date.strftime('%b')) give me my local month abbreviation:
But the rcparam Anyway thank you for helping me to solve this problem and I learned some things about python. It's a good days. |
Hm, something is using Closing this as there isn't a bug in MPL, just tricksy internationalization. |
@Kangomnawe That should probably be reported against pandas as Matplotlib does not appear to be involved on what you posted. |
throw an exception :
Traceback (most recent call last):
File "/home/workspace/python/ephemeride/t.py", line 10, in
datetime.strptime("Sep", '%b')
File "/usr/lib/python3.4/_strptime.py", line 500, in _strptime_datetime
tt, fraction = _strptime(data_string, format)
File "/usr/lib/python3.4/_strptime.py", line 337, in _strptime
(data_string, format))
ValueError: time data 'Sep' does not match format '%b'
The exception doesn't occur if the matplotlib is not imported.
python 3.4.2/Ubuntu 14.10
The text was updated successfully, but these errors were encountered: