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

Version 0.5.0 with numpy fails on Decimal values #40

Open
emakarov opened this issue Jul 10, 2019 · 4 comments
Open

Version 0.5.0 with numpy fails on Decimal values #40

emakarov opened this issue Jul 10, 2019 · 4 comments
Assignees
Labels

Comments

@emakarov
Copy link

UTM version:

pip freeze | grep utm
utm==0.5.0

Numpy version:

pip freeze | grep numpy
numpy==1.16.4

(tested on some other numpy versions below 1.16.4)

Code:

from decimal import *
import utm
lat, lon = 1.286834229215, 103.796852963067
utm.from_latlon(Decimal(lat), Decimal(lon))

fails with such traceback:

~/dev/envs/p3/lib/python3.6/site-packages/utm/conversion.py in from_latlon(latitude, longitude, force_zone_number, force_zone_letter)
    187        .. _[1]: http://www.jaworski.ca/utmzones.htm
    188     """
--> 189     if not in_bounds(latitude, -80.0, 84.0):
    190         raise OutOfRangeError('latitude out of range (must be between 80 deg S and 84 deg N)')
    191     if not in_bounds(longitude, -180.0, 180.0):

~/dev/envs/p3/lib/python3.6/site-packages/utm/conversion.py in in_bounds(x, lower, upper, upper_strict)
     47         return lower <= x < upper
     48     elif use_numpy:
---> 49         return lower <= mathlib.min(x) and mathlib.max(x) <= upper
     50     return lower <= x <= upper
     51

~/dev/envs/p3/lib/python3.6/site-packages/numpy/core/fromnumeric.py in amin(a, axis, out, keepdims, initial)
   2616     """
   2617     return _wrapreduction(a, np.minimum, 'min', axis, None, out, keepdims=keepdims,
-> 2618                           initial=initial)
   2619
   2620

~/dev/envs/p3/lib/python3.6/site-packages/numpy/core/fromnumeric.py in _wrapreduction(obj, ufunc, method, axis, dtype, out, **kwargs)
     82                 return reduction(axis=axis, dtype=dtype, out=out, **passkwargs)
     83             else:
---> 84                 return reduction(axis=axis, out=out, **passkwargs)
     85
     86     return ufunc.reduce(obj, axis, dtype, out, **passkwargs)

TypeError: Required argument 'other' (pos 1) not found
@TheBB
Copy link
Collaborator

TheBB commented Jul 10, 2019

We're going to have to wrap a few of the math functions if we want to support Decimals in numpy-mode I think. Few numpy functions understand them, even when used as straight-up scalars, including some we need: sin, cos, radians, degrees, max and min. Interestingly sqrt is fine with them.

I'm not sure if numpy would consider this a bug.

@emakarov
Copy link
Author

I'm not sure about numpy strategy about Decimal support in future.
The issue was found working with django project where lat/lon values are kept in decimals in database.

I see two options:

  1. Consider this not a bug and raise specific Exception about attribute type (I think it's less preferred variant)
  2. Cast Decimals to float explicitly in the code of utm

@emakarov
Copy link
Author

emakarov commented Jul 10, 2019

the situation is also following:

if you call numpy.max with single float argument, it works
if you call numpy.max with array of floats, it works
if you call numpy.max with array of Decimals, it works
if you call numpy.max with single Decimal, it fails

@bartvanandel
Copy link
Collaborator

bartvanandel commented Dec 15, 2024

Just as a reminder, this is still unsupported by (our required version of) numpy and therefore by utm (both the current release, 0.7.0, and current git).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants