diff options
author | Mark Wiebe <mwiebe@enthought.com> | 2011-06-22 16:05:26 -0500 |
---|---|---|
committer | Mark Wiebe <mwiebe@enthought.com> | 2011-06-22 16:20:43 -0500 |
commit | 8b29cac3f3fd68daf95bd89887da1635909c9a35 (patch) | |
tree | ad4f2777e53336c606ffa2fcbbac466f46b57f38 /numpy/core/arrayprint.py | |
parent | d4ea04b4531f218bd7752f675c30b8c8472a5243 (diff) | |
download | numpy-8b29cac3f3fd68daf95bd89887da1635909c9a35.tar.gz |
BUG: datetime-print: str() and repr() weren't handling the local tz properly
Diffstat (limited to 'numpy/core/arrayprint.py')
-rw-r--r-- | numpy/core/arrayprint.py | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py index 567573af5..508056a26 100644 --- a/numpy/core/arrayprint.py +++ b/numpy/core/arrayprint.py @@ -15,7 +15,7 @@ __docformat__ = 'restructuredtext' import sys import numerictypes as _nt from umath import maximum, minimum, absolute, not_equal, isnan, isinf -from multiarray import format_longfloat, datetime_as_string +from multiarray import format_longfloat, datetime_as_string, datetime_data from fromnumeric import ravel @@ -245,7 +245,7 @@ def _array2string(a, max_line_width, precision, suppress_small, separator=' ', 'complexfloat' : ComplexFormat(data, precision, suppress_small), 'longcomplexfloat' : LongComplexFormat(precision), - 'datetime' : DatetimeFormat(), + 'datetime' : DatetimeFormat(data), 'timedelta' : TimedeltaFormat(data), 'numpystr' : repr, 'str' : str} @@ -698,10 +698,25 @@ class ComplexFormat(object): return r + i class DatetimeFormat(object): - def __init__(self, overrideunit=None, - timezone='local', casting='same_kind'): - self.timezone = timezone - self.unit = overrideunit + def __init__(self, x, unit=None, + timezone=None, casting='same_kind'): + # Get the unit from the dtype + if unit is None: + if x.dtype.kind == 'M': + unit = datetime_data(x.dtype)[0] + else: + unit = 's' + + # If timezone is default, make it 'local' or 'UTC' based on the unit + if timezone is None: + # Date units -> UTC, time units -> local + if unit in ('Y', 'M', 'W', 'D'): + self.timezone = 'UTC' + else: + self.timezone = 'local' + else: + self.timezone = timezone + self.unit = unit self.casting = casting def __call__(self, x): |