Skip to content

Unicode issue in matplotlib.dates #7630

@djkirkham

Description

@djkirkham

The import of __future__.unicode_literals in matplotlib.dates causes an error when calling datetime.datetime.tzname() on a datetime created with tzinfo=matplotlib.dates.UTC:

>>> import matplotlib.dates
>>> import datetime
>>> dt = datetime.datetime(2000,1,1, tzinfo=matplotlib.dates.UTC)
>>> dt.tzname()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: tzinfo.tzname() must return None or a string, not 'unicode'

This causes issues when plotting with a date formatter:

>>> import matplotlib.pyplot as plt
>>> import matplotlib.dates
>>> plt.plot([700000], [0])
[<matplotlib.lines.Line2D object at 0x7fe41dbb4050>]
>>> plt.gca().xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%Z'))
>>> plt.show()
...
  File .../lib/python2.7/site-packages/matplotlib/dates.py", line 589, in strftime
    return cbook.unicode_safe(dt.strftime(fmt))
TypeError: tzinfo.tzname() must return None or a string, not 'unicode'

(I've omitted most of the call stack)

Matplotlib 1.5.3, Python 2.7.12, Linux
Installed from source
The issue doesn't exist in Matplotlib 1.3.1

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy