Revision: 8222
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8222&view=rev
Author:   efiring
Date:     2010-04-05 18:46:18 +0000 (Mon, 05 Apr 2010)

Log Message:
-----------
Don't import pytz unless and until it is needed

Modified Paths:
--------------
    trunk/matplotlib/CHANGELOG
    trunk/matplotlib/examples/pylab_examples/finance_demo.py
    trunk/matplotlib/lib/matplotlib/config/cutils.py
    trunk/matplotlib/lib/matplotlib/dates.py

Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG  2010-04-05 01:06:57 UTC (rev 8221)
+++ trunk/matplotlib/CHANGELOG  2010-04-05 18:46:18 UTC (rev 8222)
@@ -1,3 +1,6 @@
+2010-04-05 Speed up import: import pytz only if and when it is
+           needed.  It is not needed if the rc timezone is UTC. - EF
+
 2010-04-03 Added color kwarg to Axes.hist(), based on work by
            Jeff Klukas. - EF
 

Modified: trunk/matplotlib/examples/pylab_examples/finance_demo.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/finance_demo.py    2010-04-05 
01:06:57 UTC (rev 8221)
+++ trunk/matplotlib/examples/pylab_examples/finance_demo.py    2010-04-05 
18:46:18 UTC (rev 8222)
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 from pylab import *
 from matplotlib.dates import  DateFormatter, WeekdayLocator, HourLocator, \
-     DayLocator, MONDAY, timezone
+     DayLocator, MONDAY
 from matplotlib.finance import quotes_historical_yahoo, candlestick,\
      plot_day_summary, candlestick2
 

Modified: trunk/matplotlib/lib/matplotlib/config/cutils.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/config/cutils.py    2010-04-05 01:06:57 UTC 
(rev 8221)
+++ trunk/matplotlib/lib/matplotlib/config/cutils.py    2010-04-05 18:46:18 UTC 
(rev 8222)
@@ -4,7 +4,6 @@
 
 # Stdlib imports
 import os
-import pytz
 import sys
 import tempfile
 import warnings

Modified: trunk/matplotlib/lib/matplotlib/dates.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/dates.py    2010-04-05 01:06:57 UTC (rev 
8221)
+++ trunk/matplotlib/lib/matplotlib/dates.py    2010-04-05 18:46:18 UTC (rev 
8222)
@@ -92,15 +92,6 @@
 """
 import re, time, math, datetime
 
-import pytz
-
-# compatability for 2008c and older versions
-try:
-   import pytz.zoneinfo
-except ImportError:
-   pytz.zoneinfo = pytz.tzinfo
-   pytz.zoneinfo.UTC = pytz.UTC
-
 import matplotlib
 import numpy as np
 
@@ -108,7 +99,6 @@
 import matplotlib.cbook as cbook
 import matplotlib.ticker as ticker
 
-from pytz import timezone
 from dateutil.rrule import rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY, \
      MONTHLY, WEEKLY, DAILY, HOURLY, MINUTELY, SECONDLY
 from dateutil.relativedelta import relativedelta
@@ -127,11 +117,28 @@
             'seconds', 'minutes', 'hours', 'weeks')
 
 
+# Make a simple UTC instance so we don't always have to import
+# pytz.  From the python datetime library docs:
 
-UTC = pytz.timezone('UTC')
+class _UTC(datetime.tzinfo):
+    """UTC"""
 
+    def utcoffset(self, dt):
+        return datetime.timedelta(0)
+
+    def tzname(self, dt):
+        return "UTC"
+
+    def dst(self, dt):
+        return datetime.timedelta(0)
+
+UTC = _UTC()
+
 def _get_rc_timezone():
     s = matplotlib.rcParams['timezone']
+    if s == 'UTC':
+        return UTC
+    import pytz
     return pytz.timezone(s)
 
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to