Skip to content

Commit

Permalink
MNT: Add an equals method on CRS objects
Browse files Browse the repository at this point in the history
pyproj == comparison is slow, so if we are comparing two Cartopy
CRSs, return a fast-path comparison. Let the pyproj comparison
handle the other cases.
  • Loading branch information
greglucas committed Aug 29, 2021
1 parent dea2d9d commit 75856be
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/cartopy/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ def __init__(self, proj4_params, globe=None):
self.proj4_init = ' '.join(init_items) + ' +no_defs'
super().__init__(self.proj4_init)

def __eq__(self, other):
if isinstance(other, CRS):
# Fast path Cartopy's CRS
return self.proj4_init == other.proj4_init
# For everything else, we let pyproj handle the comparison
return super().__eq__(other)

def __hash__(self):
"""Hash the CRS based on its proj4_init string."""
return hash(self.proj4_init)
Expand Down

0 comments on commit 75856be

Please sign in to comment.