Skip to content
Open
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion earthaccess/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
29 changes: 19 additions & 10 deletions earthaccess/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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(" ", "")

Expand All @@ -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"]
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions earthaccess/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
Loading