Skip to content

Commit 3e6e8d1

Browse files
committed
Remove Python 2.6 compatibility function
1 parent 66c0ed7 commit 3e6e8d1

File tree

1 file changed

+5
-22
lines changed

1 file changed

+5
-22
lines changed

lib/matplotlib/dates.py

+5-22
Original file line numberDiff line numberDiff line change
@@ -229,31 +229,14 @@ def _to_ordinalf(dt):
229229
rdt = datetime.datetime.combine(cdate, midnight_time)
230230

231231
# Append the seconds as a fraction of a day
232-
base += _total_seconds(dt - rdt) / SEC_PER_DAY
232+
base += (dt - rdt).total_seconds() / SEC_PER_DAY
233233

234234
return base
235235

236236

237237
# a version of _to_ordinalf that can operate on numpy arrays
238238
_to_ordinalf_np_vectorized = np.vectorize(_to_ordinalf)
239239

240-
try:
241-
# Available as a native method in Python >= 2.7.
242-
_total_seconds = datetime.timedelta.total_seconds
243-
except AttributeError:
244-
def _total_seconds(tdelta):
245-
"""
246-
Alias providing support for datetime.timedelta.total_seconds() function
247-
calls even in Python < 2.7.
248-
249-
The input `tdelta` is a datetime.timedelta object, and returns a float
250-
containing the total number of seconds representing the `tdelta`
251-
duration. For large durations (> 270 on most platforms), this loses
252-
microsecond accuracy.
253-
"""
254-
return (tdelta.microseconds +
255-
(tdelta.seconds + tdelta.days * SEC_PER_DAY) * 1e6) * 1e-6
256-
257240

258241
def _from_ordinalf(x, tz=None):
259242
"""
@@ -433,7 +416,7 @@ def drange(dstart, dend, delta):
433416
"""
434417
f1 = _to_ordinalf(dstart)
435418
f2 = _to_ordinalf(dend)
436-
step = _total_seconds(delta) / SEC_PER_DAY
419+
step = delta.total_seconds() / SEC_PER_DAY
437420

438421
# calculate the difference between dend and dstart in times of delta
439422
num = int(np.ceil((f2 - f1) / step))
@@ -1062,8 +1045,8 @@ def get_locator(self, dmin, dmax):
10621045
numDays = tdelta.days # Avoids estimates of days/month, days/year
10631046
numHours = (numDays * HOURS_PER_DAY) + delta.hours
10641047
numMinutes = (numHours * MIN_PER_HOUR) + delta.minutes
1065-
numSeconds = np.floor(_total_seconds(tdelta))
1066-
numMicroseconds = np.floor(_total_seconds(tdelta) * 1e6)
1048+
numSeconds = np.floor(tdelta.total_seconds())
1049+
numMicroseconds = np.floor(tdelta.total_seconds() * 1e6)
10671050

10681051
nums = [numYears, numMonths, numDays, numHours, numMinutes,
10691052
numSeconds, numMicroseconds]
@@ -1403,7 +1386,7 @@ def _close_to_dt(d1, d2, epsilon=5):
14031386
Assert that datetimes *d1* and *d2* are within *epsilon* microseconds.
14041387
"""
14051388
delta = d2 - d1
1406-
mus = abs(_total_seconds(delta) * 1e6)
1389+
mus = abs(delta.total_seconds() * 1e6)
14071390
assert mus < epsilon
14081391

14091392

0 commit comments

Comments
 (0)