Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor change to avoid numpy DeprecationWarning #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions tzwhere/tzwhere.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ class are instantiated and queried directly
import numpy
WRAP = numpy.asarray

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be cleaner if you did:

WRAP = functools.partial(numpy.asarray, dtype=object)

Then WRAP will always get the dtype=object argument, and you won't have to add or branch onnumpy_avail.

Although you will have to import functools. :-)

COLLECTION_TYPE = numpy.ndarray
numpy_avail = True
except ImportError:
WRAP = tuple
COLLECTION_TYPE = tuple
numpy_avail = False

# for navigation and pulling values/files
this_dir, this_filename = os.path.split(__file__)
Expand Down Expand Up @@ -59,10 +61,14 @@ def __init__(self, forceTZ=False):
for tzname, poly in pgen:
self.timezoneNamesToPolygons[tzname].append(poly)
for tzname, polys in self.timezoneNamesToPolygons.items():
self.timezoneNamesToPolygons[tzname] = WRAP(polys)

if forceTZ:
self.unprepTimezoneNamesToPolygons[tzname] = WRAP(polys)
if numpy_avail:
self.timezoneNamesToPolygons[tzname] = WRAP(polys, dtype=object)
if forceTZ:
self.unprepTimezoneNamesToPolygons[tzname] = WRAP(polys, dtype=object)
else:
self.timezoneNamesToPolygons[tzname] = WRAP(polys)
if forceTZ:
self.unprepTimezoneNamesToPolygons[tzname] = WRAP(polys)

with open(tzwhere.DEFAULT_SHORTCUTS, 'r') as f:
self.timezoneLongitudeShortcuts, self.timezoneLatitudeShortcuts = json.load(f)
Expand Down