Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fixes tzname return type #7705

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

Merged
merged 1 commit into from
Dec 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/matplotlib/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def utcoffset(self, dt):
return datetime.timedelta(0)

def tzname(self, dt):
return "UTC"
return str("UTC")

def dst(self, dt):
return datetime.timedelta(0)
Expand Down
5 changes: 5 additions & 0 deletions lib/matplotlib/tests/test_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,11 @@ def test_DayLocator():
mdates.DayLocator(interval=1.0)


def test_tz_utc():
dt = datetime.datetime(1970, 1, 1, tzinfo=mdates.UTC)
dt.tzname()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not check the return value of dt.tzname() rather than making this just a smoke test?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should add that my big complaint here is that this test, while exercising the method, does nothing to actually catch the original problem.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does, the exception is coming out of datetime

Python 2.7.13 |Continuum Analytics, Inc.| (default, Dec 20 2016, 23:09:15)                                                                                                                                                                                                                                                                                                                                                              
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2                                                                                                                                                                                                                                                                                                                                                                                        
Type "help", "copyright", "credits" or "license" for more information.                                                                                                                                                                                                                                                                                                                                                                  
Anaconda is brought to you by Continuum Analytics.                                                                                                                                                                                                                                                                                                                                                                                      
Please check out: http://continuum.io/thanks and https://anaconda.org                                                                                                                                                                                                                                                                                                                                                                   
>>> import matplotlib.dates as mdates                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
>>> import datetime                                                                                                                                                                                                                                                                                                                                                                                                                     
>>> dt = datetime.datetime(1970, 1, 1, tzinfo=mdates.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'                                                                                                                                                                                                                                                                                                                                                                  
>>>                                                                                                                                                                                                                                                                                                                                                                                                                                     
        

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AH. I see now. My mistake.



if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)