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

remove custom cached prop and replace with builtin #293

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading