Skip to content

Commit

Permalink
Remove Python 2.6 compatibility function
Browse files Browse the repository at this point in the history
  • Loading branch information
pganssle committed Apr 2, 2016
1 parent 66c0ed7 commit 3e6e8d1
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions lib/matplotlib/dates.py
Expand Up @@ -229,31 +229,14 @@ def _to_ordinalf(dt):
rdt = datetime.datetime.combine(cdate, midnight_time)

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

return base


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

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


def _from_ordinalf(x, tz=None):
"""
Expand Down Expand Up @@ -433,7 +416,7 @@ def drange(dstart, dend, delta):
"""
f1 = _to_ordinalf(dstart)
f2 = _to_ordinalf(dend)
step = _total_seconds(delta) / SEC_PER_DAY
step = delta.total_seconds() / SEC_PER_DAY

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

nums = [numYears, numMonths, numDays, numHours, numMinutes,
numSeconds, numMicroseconds]
Expand Down Expand Up @@ -1403,7 +1386,7 @@ def _close_to_dt(d1, d2, epsilon=5):
Assert that datetimes *d1* and *d2* are within *epsilon* microseconds.
"""
delta = d2 - d1
mus = abs(_total_seconds(delta) * 1e6)
mus = abs(delta.total_seconds() * 1e6)
assert mus < epsilon


Expand Down

0 comments on commit 3e6e8d1

Please sign in to comment.