From 050fe634884b2a0dd2d87cf7b5a382f803662a77 Mon Sep 17 00:00:00 2001 From: Alex Morling Date: Fri, 11 Oct 2024 13:51:57 +0200 Subject: [PATCH] remove custom cached prop and replace with builtin --- ecoscope/base/__init__.py | 2 -- ecoscope/base/base.py | 8 ++++---- ecoscope/base/utils.py | 27 --------------------------- 3 files changed, 4 insertions(+), 33 deletions(-) diff --git a/ecoscope/base/__init__.py b/ecoscope/base/__init__.py index 4a10c84b..bc98e5e5 100644 --- a/ecoscope/base/__init__.py +++ b/ecoscope/base/__init__.py @@ -7,7 +7,6 @@ ) from ecoscope.base.base import EcoDataFrame, Relocations, Trajectory from ecoscope.base.utils import ( - cachedproperty, create_meshgrid, groupby_intervals, hex_to_rgba, @@ -23,7 +22,6 @@ "RelocsSpeedFilter", "TrajSegFilter", "Trajectory", - "cachedproperty", "create_meshgrid", "groupby_intervals", "hex_to_rgba", diff --git a/ecoscope/base/base.py b/ecoscope/base/base.py index 38234a45..b96f86f0 100644 --- a/ecoscope/base/base.py +++ b/ecoscope/base/base.py @@ -13,7 +13,7 @@ RelocsSpeedFilter, TrajSegFilter, ) -from ecoscope.base.utils import cachedproperty +from functools import cached_property class EcoDataFrame(gpd.GeoDataFrame): @@ -285,13 +285,13 @@ def apply_reloc_filter(self, fix_filter=None, inplace=False): if not inplace: return frame - @cachedproperty + @cached_property def distance_from_centroid(self): # calculate the distance between the centroid and the fix gs = self.geometry.to_crs(crs=self.estimate_utm_crs()) return gs.distance(gs.unary_union.centroid) - @cachedproperty + @cached_property def cluster_radius(self): """ The cluster radius is the largest distance between a point in the relocationss and the @@ -300,7 +300,7 @@ def cluster_radius(self): distance = self.distance_from_centroid return distance.max() - @cachedproperty + @cached_property def cluster_std_dev(self): """ The cluster standard deviation is the standard deviation of the radii from the centroid diff --git a/ecoscope/base/utils.py b/ecoscope/base/utils.py index ae2b0368..d257f3b7 100644 --- a/ecoscope/base/utils.py +++ b/ecoscope/base/utils.py @@ -74,33 +74,6 @@ def create_meshgrid( return gs.to_crs(out_crs) -class cachedproperty: # noqa - """ - The ``cachedproperty`` is used similar to :class:`property`, except - that the wrapped method is only called once. This is commonly used - to implement lazy attributes. - """ - - def __init__(self, func): - self.func = func - - def __doc__(self): - return getattr(self.func, "__doc__") - - def __isabstractmethod__(self): - return getattr(self.func, "__isabstractmethod__", False) - - def __get__(self, obj, objtype=None): - if obj is None: - return self - value = obj.__dict__[self.func.__name__] = self.func(obj) - return value - - def __repr__(self): - cls = self.__class__.__name__ - return f"<{cls} func={self.func}>" - - def groupby_intervals(df, col, intervals): """ Parameters