Skip to content

Commit

Permalink
remove custom cached prop and replace with builtin (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
atmorling authored Oct 31, 2024
1 parent bbe23ca commit daf746f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 33 deletions.
2 changes: 0 additions & 2 deletions ecoscope/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -23,7 +22,6 @@
"RelocsSpeedFilter",
"TrajSegFilter",
"Trajectory",
"cachedproperty",
"create_meshgrid",
"groupby_intervals",
"hex_to_rgba",
Expand Down
8 changes: 4 additions & 4 deletions ecoscope/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
RelocsSpeedFilter,
TrajSegFilter,
)
from ecoscope.base.utils import cachedproperty
from functools import cached_property


class EcoDataFrame(gpd.GeoDataFrame):
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
27 changes: 0 additions & 27 deletions ecoscope/base/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit daf746f

Please sign in to comment.