120
120
121
121
import six
122
122
from six .moves import zip
123
- from matplotlib import rcParams
124
123
import re
125
124
import time
126
125
import math
129
128
130
129
import warnings
131
130
132
-
133
131
from dateutil .rrule import (rrule , MO , TU , WE , TH , FR , SA , SU , YEARLY ,
134
132
MONTHLY , WEEKLY , DAILY , HOURLY , MINUTELY ,
135
133
SECONDLY )
136
134
from dateutil .relativedelta import relativedelta
137
135
import dateutil .parser
136
+ import logging
138
137
import numpy as np
139
138
140
139
141
140
import matplotlib
141
+ from matplotlib import rcParams
142
142
import matplotlib .units as units
143
143
import matplotlib .cbook as cbook
144
144
import matplotlib .ticker as ticker
145
145
146
+ _log = logging .getLogger (__name__ )
146
147
147
148
__all__ = ('date2num' , 'num2date' , 'num2timedelta' , 'drange' , 'epoch2num' ,
148
149
'num2epoch' , 'mx2num' , 'DateFormatter' ,
@@ -282,6 +283,11 @@ def _from_ordinalf(x, tz=None):
282
283
tz = _get_rc_timezone ()
283
284
284
285
ix = int (x )
286
+ if ix < 1 :
287
+ raise ValueError ('cannot convert {} to a date. This '
288
+ 'often happens if non-datetime values are passed to '
289
+ 'an axis that expects datetime objects. '
290
+ .format (ix ))
285
291
dt = datetime .datetime .fromordinal (ix ).replace (tzinfo = UTC )
286
292
287
293
remainder = float (x ) - ix
@@ -941,7 +947,12 @@ def datalim_to_dt(self):
941
947
dmin , dmax = self .axis .get_data_interval ()
942
948
if dmin > dmax :
943
949
dmin , dmax = dmax , dmin
944
-
950
+ if dmin < 1 :
951
+ raise ValueError ('datalim minimum {} is less than 1 and '
952
+ 'is an invalid Matplotlib date value. This often '
953
+ 'happens if you pass a non-datetime '
954
+ 'value to an axis that has datetime units'
955
+ .format (dmin ))
945
956
return num2date (dmin , self .tz ), num2date (dmax , self .tz )
946
957
947
958
def viewlim_to_dt (self ):
@@ -951,7 +962,12 @@ def viewlim_to_dt(self):
951
962
vmin , vmax = self .axis .get_view_interval ()
952
963
if vmin > vmax :
953
964
vmin , vmax = vmax , vmin
954
-
965
+ if vmin < 1 :
966
+ raise ValueError ('view limit minimum {} is less than 1 and '
967
+ 'is an invalid Matplotlib date value. This '
968
+ 'often happens if you pass a non-datetime '
969
+ 'value to an axis that has datetime units'
970
+ .format (vmin ))
955
971
return num2date (vmin , self .tz ), num2date (vmax , self .tz )
956
972
957
973
def _get_unit (self ):
0 commit comments