From 58cad39966351af4278459251b11b1d92c3252de Mon Sep 17 00:00:00 2001 From: Andy Barrett Date: Tue, 4 Aug 2026 11:37:59 -0600 Subject: [PATCH 1/3] add _size provate issue to avoid deprecation warning --- earthaccess/results.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/earthaccess/results.py b/earthaccess/results.py index 7c0c4225..3e2c76a5 100644 --- a/earthaccess/results.py +++ b/earthaccess/results.py @@ -393,19 +393,13 @@ def get_s3_credentials_endpoint(self) -> str | None: return link["URL"] return None - def size(self) -> float: + @property + def _size(self) -> float: """Return the total granule size in MB. Returns: The total size for the granule in MB. """ - warnings.warn( - "As of version 1.0, `DataGranule.size` will be accessed as an " - "attribute; e.g. use `DataCollection.size` **not** " - "`DataCollection.size()`", - category=FutureWarning, - stacklevel=2, - ) try: data_granule = self["umm"]["DataGranule"] @@ -430,6 +424,21 @@ def size(self) -> float: total_size = 0 return total_size + def size(self) -> float: + """Return the total granule size in MB. + + Returns: + The total size for the granule in MB. + """ + warnings.warn( + "As of version 1.0, `DataGranule.size` will be accessed as an " + "attribute; e.g. use `DataCollection.size` **not** " + "`DataCollection.size()`", + category=FutureWarning, + stacklevel=2, + ) + return self._size + def _derive_s3_link(self, links: list[str]) -> list[str]: s3_links = [] for link in links: From 39e9e9d218b5fef7ea6e403293818e70ad616156 Mon Sep 17 00:00:00 2001 From: Andy Barrett Date: Tue, 4 Aug 2026 11:46:52 -0600 Subject: [PATCH 2/3] change internal calls to size() to private _size --- earthaccess/formatters.py | 2 +- earthaccess/results.py | 4 ++-- earthaccess/store.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/earthaccess/formatters.py b/earthaccess/formatters.py index ae58872f..f1a87b35 100644 --- a/earthaccess/formatters.py +++ b/earthaccess/formatters.py @@ -37,7 +37,7 @@ def _repr_granule_html(granule: Any) -> str: for link in granule.data_links() ], ) - granule_size = round(granule.size(), 2) + granule_size = round(granule._size, 2) # TODO: probably this needs to be integrated on a list data structure return f""" diff --git a/earthaccess/results.py b/earthaccess/results.py index 3e2c76a5..281a3e85 100644 --- a/earthaccess/results.py +++ b/earthaccess/results.py @@ -345,7 +345,7 @@ def __init__( super().__init__(collection) self.cloud_hosted = cloud_hosted # TODO: maybe add area, start date and all that as an instance value - self["size"] = self.size() + self["size"] = self._size self.uuid = str(uuid.uuid4()) self.render_dict: Any if fields is None: @@ -372,7 +372,7 @@ def __repr__(self) -> str: Collection: {self["umm"]["CollectionReference"]} Spatial coverage: {self["umm"]["SpatialExtent"]} Temporal coverage: {self["umm"]["TemporalExtent"]} - Size(MB): {self.size()} + Size(MB): {self._size} Data: {data_links}\n\n """.strip().replace(" ", "") diff --git a/earthaccess/store.py b/earthaccess/store.py index 60e63147..12a376ae 100644 --- a/earthaccess/store.py +++ b/earthaccess/store.py @@ -524,7 +524,7 @@ def _open_granules( pqdm_kwargs: Mapping[str, Any] | None = None, open_kwargs: dict[str, Any] | None = None, ) -> list[Any]: - total_size = round(sum([granule.size() for granule in granules]) / 1024, 2) + total_size = round(sum([granule._size for granule in granules]) / 1024, 2) logger.info( "Opening %s granules, approx size: %s GB", len(granules), @@ -840,7 +840,7 @@ def _get_granules( # noqa: PLR0913 for granule in granules ), ) - total_size = round(sum(granule.size() for granule in granules) / 1024, 2) + total_size = round(sum(granule._size for granule in granules) / 1024, 2) logger.info( "Getting %s granules, approx download size: %s GB", len(granules), From e52b7c8c973535810cca104914f55ccd49d4fb1c Mon Sep 17 00:00:00 2001 From: Andy Barrett Date: Tue, 4 Aug 2026 12:16:19 -0600 Subject: [PATCH 3/3] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ae04d27..ba0b07b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ and this project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html) now derives each S3 link from its own HTTPS link instead of repeating the first one, so multi-file granules no longer drop their other files. ([#1373](https://github.com/earthaccess-dev/earthaccess/pull/1373)) +- Refactored `results.DataGranule.size` to prevent Deprecation warning from occurring when size is called. + ([#1420](https://github.com/earthaccess-dev/earthaccess/pull/1420)) ## [v0.18.0] - 2026-05-12