[Python-modules-commits] [python-mplexporter] 82/135: fix pandas dataframe date conversion

Wolfgang Borgert debacle at moszumanska.debian.org
Tue Sep 23 21:19:06 UTC 2014


This is an automated email from the git hooks/post-receive script.

debacle pushed a commit to branch master
in repository python-mplexporter.

commit b35fa6ca3fe3a4c55e26b1bc63fb318e27e21ac2
Author: Jake Vanderplas <vanderplas at astro.washington.edu>
Date:   Fri Mar 7 14:44:34 2014 -0800

    fix pandas dataframe date conversion
---
 mplexporter/utils.py | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/mplexporter/utils.py b/mplexporter/utils.py
index 529eaa3..33af978 100644
--- a/mplexporter/utils.py
+++ b/mplexporter/utils.py
@@ -265,10 +265,24 @@ def get_axes_properties(ax):
         lim = domain
         if isinstance(axis.converter, matplotlib.dates.DateConverter):
             scale = 'date'
-            domain = [(d.year, d.month - 1, d.day,
-                       d.hour, d.minute, d.second,
-                       d.microsecond * 1E-3)
-                      for d in matplotlib.dates.num2date(domain)]
+            try:
+                import pandas as pd
+                from pandas.tseries.converter import PeriodConverter
+            except ImportError:
+                pd = None
+
+            if (pd is not None and isinstance(axis.converter,
+                                              PeriodConverter)):
+                _dates = [pd.Period(ordinal=int(d), freq=axis.freq)
+                          for d in domain]
+                domain = [(d.year, d.month - 1, d.day,
+                           d.hour, d.minute, d.second, 0)
+                          for d in _dates]
+            else:
+                domain = [(d.year, d.month - 1, d.day,
+                           d.hour, d.minute, d.second,
+                           d.microsecond * 1E-3)
+                          for d in matplotlib.dates.num2date(domain)]
         else:
             scale = axis.get_scale()
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-mplexporter.git



More information about the Python-modules-commits mailing list