X Tutup
Skip to content

num2date ignoring tz in v1.5.0 #5543

@brendene

Description

@brendene

The behavior of matplotlib.dates.num2date changed between stable versions 1.4.3 and 1.5.

In version 1.5 the implementation of helper function, _from_ordinalf ignores the tz argument and always returns datetimes in UTC.

def _from_ordinalf(x, tz=None):
    """                                                                                                                                                         
    Convert Gregorian float of the date, preserving hours, minutes,                                                                                             
    seconds and microseconds.  Return value is a :class:`datetime`.                                                                                             

    The input date `x` is a float in ordinal days at UTC, and the output will                                                                                   
    be the specified :class:`datetime` object corresponding to that time in                                                                                     
    timezone `tz`, or if `tz` is `None`, in the timezone specified in                                                                                           
    `rcParams['timezone']`.                                                                                                                                     
    """
    if tz is None:
        tz = _get_rc_timezone()

    ix = int(x)
    dt = datetime.datetime.fromordinal(ix).replace(tzinfo=UTC)

    remainder = float(x) - ix

    # Round down to the nearest microsecond.                                                                                                                    
    dt += datetime.timedelta(microseconds=int(remainder * MUSECONDS_PER_DAY))

    # Compensate for rounding errors                                                                                                                            
    if dt.microsecond < 10:
        dt = dt.replace(microsecond=0)
    elif dt.microsecond > 999990:
        dt += datetime.timedelta(microseconds=1e6 - dt.microsecond)

    return dt

In version 1.4.3 this is handled correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup