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

GeoVector.__eq__crash on inconsistent types #123

Open
penguinolog opened this issue Aug 14, 2018 · 6 comments
Open

GeoVector.__eq__crash on inconsistent types #123

penguinolog opened this issue Aug 14, 2018 · 6 comments

Comments

@penguinolog
Copy link

Expected behavior and actual behavior

from telluric import GeoVector, constants
from shapely import geometry
from rasterio.crs import CRS

poly = geometry.Polygon.from_bounds(4334065.7375318575650454, 5627100.9060072815045714, 4337359.6036174902692437,5630885.4445580849424005)

roi = GeoVector(poly, crs=constants.WEB_MERCATOR_CRS)
roi == 1

will crush with AttributeError instead of return False

OS independent, version = trunk.

@drnextgis
Copy link
Contributor

@penguinolog is it common practice to return False as result of comparison of incompatible types? For me personally it looks like problem masking and making debugging more complicated.

@penguinolog
Copy link
Author

It's common practice to make simple compare for equality and separately make type check.
Sometimes not exactly the same types are equal and sometimes not.

@drnextgis
Copy link
Contributor

This is an upstream issue:

In [1]: from rasterio.crs import CRS

In [2]: crs = CRS({'init': 'epsg:3857'})

In [3]: crs == 5
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-813cf943d3dc> in <module>()
----> 1 crs == 5

~/git/rasterio/rasterio/_crs.pyx in rasterio._crs._CRS.__eq__()

~/git/rasterio/rasterio/_base.pyx in rasterio._base._osr_from_crs()

/usr/lib/python3.5/collections/__init__.py in __init__(*args, **kwargs)
    975         self.data = {}
    976         if dict is not None:
--> 977             self.update(dict)
    978         if len(kwargs):
    979             self.update(kwargs)

/usr/lib/python3.5/_collections_abc.py in update(*args, **kwds)
    776                     self[key] = other[key]
    777             else:
--> 778                 for key, value in other:
    779                     self[key] = value
    780         for key, value in kwds.items():

TypeError: 'int' object is not iterable

I will open issue there.

@astrojuanlu
Copy link
Contributor

Upstream response was "this is expected". Anyway, I would say this is also our fault in the GeoVector.__eq__ method, which only expects another GeoVector:

def __eq__(self, other):
""" invariant to crs and topology."""
# Explicitly include method here instead of in GEOM_BINARY_PREDICATES,
# otherwise the delegation won't happen
return (
self.crs == other.crs
and self._shape.equals(other.get_shape(self.crs))
)

@astrojuanlu
Copy link
Contributor

This is similar to what attrs does:

http://www.attrs.org/en/stable/why.html#hand-written-classes

@penguinolog
Copy link
Author

penguinolog commented Aug 27, 2018 via email

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

No branches or pull requests

3 participants