From 0dc6f9e826395353059b5d695c5957f4d52d790a Mon Sep 17 00:00:00 2001 From: Jeff Tratner Date: Mon, 11 Nov 2013 22:45:53 -0500 Subject: [PATCH] PERF: Use faster version of list comprehension Using index lookups is ~20% slower (and less pythonic) than unpacking with comprehension. Plus use lazy iterator. --- geopandas/geoseries.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/geopandas/geoseries.py b/geopandas/geoseries.py index d268ecc..bd78675 100644 --- a/geopandas/geoseries.py +++ b/geopandas/geoseries.py @@ -101,8 +101,9 @@ class GeoSeries(Series): if self.crs != other.crs: warn('GeoSeries crs mismatch: {0} and {1}'.format(self.crs, other.crs)) this, other = self.align(other) - return GeoSeries([getattr(s[0], op)(s[1]) for s in zip(this, other)], - index=this.index, crs=self.crs) + return GeoSeries([getattr(this_elem, op)(other_elem) + for this_elem, other_elem in zip(this, other)], + index=this.index, crs=self.crs) else: return GeoSeries([getattr(s, op)(other) for s in self], index=self.index, crs=self.crs) @@ -112,7 +113,8 @@ class GeoSeries(Series): """Geometric operation that returns a pandas Series""" if isinstance(other, GeoSeries): this, other = self.align(other) - return Series([getattr(s[0], op)(s[1], **kwargs) for s in zip(this, other)], + return Series([getattr(this_elem, op)(other_elem, **kwargs) for + this_elem, other_elem in zip(this, other)], index=this.index) else: return Series([getattr(s, op)(other, **kwargs) for s in self],