Skip to content

Commit

Permalink
Fix bumpy deprecation warnings
Browse files Browse the repository at this point in the history
Make datetime input timezone unaware before feeding them to numpy.
Fixes pingswept#135
  • Loading branch information
w00kie authored Jan 26, 2021
1 parent 9226356 commit 441c2a6
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pysolar/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
pysolar.use_math()
"""

import datetime
from math import degrees, cos, sin, radians, tan, pi
from math import acos, atan, asin, atan2, exp, e

Expand Down Expand Up @@ -59,6 +60,12 @@ def tm_yday_math(d):


def tm_yday_numpy(d):
if isinstance(d, datetime.datetime):
""" numpy no longer accepts parsing timezone aware datetimes
convert input to UTC and make it timezone unaware
"""
d = d.astimezone(tz=datetime.timezone.utc).replace(tzinfo=None)

dd = numpy.array(d, dtype='datetime64[D]')
dy = numpy.array(d, dtype='datetime64[Y]')
return (dd - dy).astype('int') + 1
Expand All @@ -71,6 +78,12 @@ def tm_hour_math(d):


def tm_hour_numpy(d):
if isinstance(d, datetime.datetime):
""" numpy no longer accepts parsing timezone aware datetimes
convert input to UTC and make it timezone unaware
"""
d = d.astimezone(tz=datetime.timezone.utc).replace(tzinfo=None)

dh = numpy.array(d, dtype='datetime64[h]')
dd = numpy.array(d, dtype='datetime64[D]')
return (dh - dd).astype('int')
Expand All @@ -83,6 +96,12 @@ def tm_min_math(d):


def tm_min_numpy(d):
if isinstance(d, datetime.datetime):
""" numpy no longer accepts parsing timezone aware datetimes
convert input to UTC and make it timezone unaware
"""
d = d.astimezone(tz=datetime.timezone.utc).replace(tzinfo=None)

dm = numpy.array(d, dtype='datetime64[m]')
dh = numpy.array(d, dtype='datetime64[h]')
return (dm - dh).astype('int')
Expand Down

0 comments on commit 441c2a6

Please sign in to comment.