FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

DOC: Better error when float on datetime axis by jklymak · Pull Request #10084 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 4 additions & 0 deletions lib/matplotlib/axis.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import six

import logging

from matplotlib import rcParams
import matplotlib.artist as artist
from matplotlib.artist import allow_rasterization
Expand All @@ -22,6 +24,8 @@
import numpy as np
import warnings

_log = logging.getLogger(__name__)

GRIDLINE_INTERPOLATION_STEPS = 180


Expand Down
24 changes: 20 additions & 4 deletions lib/matplotlib/dates.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@

import six
from six.moves import zip
from matplotlib import rcParams
import re
import time
import math
Expand All @@ -129,20 +128,22 @@

import warnings


from dateutil.rrule import (rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY,
MONTHLY, WEEKLY, DAILY, HOURLY, MINUTELY,
SECONDLY)
from dateutil.relativedelta import relativedelta
import dateutil.parser
import logging
import numpy as np


import matplotlib
from matplotlib import rcParams
import matplotlib.units as units
import matplotlib.cbook as cbook
import matplotlib.ticker as ticker

_log = logging.getLogger(__name__)

__all__ = ('date2num', 'num2date', 'num2timedelta', 'drange', 'epoch2num',
'num2epoch', 'mx2num', 'DateFormatter',
Expand Down Expand Up @@ -282,6 +283,11 @@ def _from_ordinalf(x, tz=None):
tz = _get_rc_timezone()

ix = int(x)
if ix < 1:
raise ValueError('cannot convert {} to a date. This '
'often happens if non-datetime values are passed to '
'an axis that expects datetime objects. '
.format(ix))
dt = datetime.datetime.fromordinal(ix).replace(tzinfo=UTC)

remainder = float(x) - ix
Expand Down Expand Up @@ -941,7 +947,12 @@ def datalim_to_dt(self):
dmin, dmax = self.axis.get_data_interval()
if dmin > dmax:
dmin, dmax = dmax, dmin

if dmin < 1:
raise ValueError('datalim minimum {} is less than 1 and '
'is an invalid Matplotlib date value. This often '
'happens if you pass a non-datetime '
'value to an axis that has datetime units'
.format(dmin))
return num2date(dmin, self.tz), num2date(dmax, self.tz)

def viewlim_to_dt(self):
Expand All @@ -951,7 +962,12 @@ def viewlim_to_dt(self):
vmin, vmax = self.axis.get_view_interval()
if vmin > vmax:
vmin, vmax = vmax, vmin

if vmin < 1:
raise ValueError('view limit minimum {} is less than 1 and '
'is an invalid Matplotlib date value. This '
'often happens if you pass a non-datetime '
'value to an axis that has datetime units'
.format(vmin))
return num2date(vmin, self.tz), num2date(vmax, self.tz)

def _get_unit(self):
Expand Down

Back | FazBrowse Home | New Git URL