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

Skip to content

Commit 68f3018

Browse files
committed
Adjust calculation of numSeconds and numMicroseconds, since the timedelta object actually calculates those for us as is.
Signed-off-by: Paul G <[email protected]>
1 parent ca284d1 commit 68f3018

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/matplotlib/dates.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -957,13 +957,17 @@ def get_locator(self, dmin, dmax):
957957
delta = -delta
958958
tdelta = -tdelta
959959

960-
numYears = delta.years * 1.0
960+
# The following uses a mix of calls to relativedelta and timedelta
961+
# methods because there is incomplete overlap in the functionality of
962+
# these similar functions, and it's best to avoid doing our own math
963+
# whenever possible.
964+
numYears = float(delta.years)
961965
numMonths = (numYears * MONTHS_PER_YEAR) + delta.months
962-
numDays = tdelta.days # Avoid estimates of days/month, days/year
966+
numDays = tdelta.days # Avoids estimates of days/month, days/year
963967
numHours = (numDays * HOURS_PER_DAY) + delta.hours
964968
numMinutes = (numHours * MIN_PER_HOUR) + delta.minutes
965-
numSeconds = (numMinutes * SEC_PER_MIN) + delta.seconds
966-
numMicroseconds = (numSeconds * 1e6) + delta.microseconds
969+
numSeconds = np.floor(tdelta.total_seconds())
970+
numMicroseconds = np.floor(tdelta.total_seconds() * 1e6)
967971

968972
nums = [numYears, numMonths, numDays, numHours, numMinutes,
969973
numSeconds, numMicroseconds]

0 commit comments

Comments
 (0)