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

Skip to content

Commit 7fd2d36

Browse files
committed
Fixed issue with _to_ordinalf(), should work fine now. Build will still fail, but that's fine for now.
Signed-off-by: Paul G <[email protected]>
1 parent 72ef748 commit 7fd2d36

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

lib/matplotlib/dates.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -213,24 +213,22 @@ def _to_ordinalf(dt):
213213
is a :func:`float`.
214214
"""
215215

216-
if isinstance(dt, datetime.date):
217-
return float(datetime.datetime.toordinal(dt))
218-
219216
if hasattr(dt, 'tzinfo') and dt.tzinfo is not None:
220217
delta = dt.tzinfo.utcoffset(dt)
221218
if delta is not None:
222219
dt -= delta
223220

224-
# Get a datetime object at midnight in the same time zone as dt.
225-
cdate = dt.date()
226-
midnight_time = datetime.time(0, 0, 0, tzinfo=dt.tzinfo)
221+
base = float(dt.toordinal())
222+
if isinstance(dt, datetime.datetime):
223+
# Get a datetime object at midnight in the same time zone as dt.
224+
cdate = dt.date()
225+
midnight_time = datetime.time(0, 0, 0, tzinfo=dt.tzinfo)
227226

228-
rdt = datetime.datetime.combine(cdate, midnight_time)
229-
td_remainder = (dt - rdt).total_seconds()
227+
rdt = datetime.datetime.combine(cdate, midnight_time)
228+
td_remainder = (dt - rdt).total_seconds()
230229

231-
base = float(dt.toordinal())
232-
if td_remainder > 0:
233-
base += td_remainder / SEC_PER_DAY
230+
if td_remainder > 0:
231+
base += td_remainder / SEC_PER_DAY
234232

235233
return base
236234

@@ -382,10 +380,9 @@ def drange(dstart, dend, delta):
382380
*dend* are :class:`datetime` instances. *delta* is a
383381
:class:`datetime.timedelta` instance.
384382
"""
385-
step = (delta.days + delta.seconds / SEC_PER_DAY +
386-
delta.microseconds / MUSECONDS_PER_DAY)
387383
f1 = _to_ordinalf(dstart)
388384
f2 = _to_ordinalf(dend)
385+
step = delta.total_seconds() / SEC_PER_DAY
389386

390387
# calculate the difference between dend and dstart in times of delta
391388
num = int(np.ceil((f2 - f1) / step))

0 commit comments

Comments
 (0)