Skip to content

Commit

Permalink
Include type in failed sizeof warning (#8580)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbourbeau committed Mar 15, 2024
1 parent 37ff154 commit 8c93366
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions distributed/sizeof.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging

from dask.sizeof import sizeof
from dask.utils import format_bytes
from dask.utils import format_bytes, typename

logger = logging.getLogger(__name__)

Expand All @@ -17,7 +17,8 @@ def safe_sizeof(obj: object, default_size: float = 1e6) -> int:
return sizeof(obj)
except Exception:
logger.warning(
f"Sizeof calculation failed. Defaulting to {format_bytes(int(default_size))}",
f"Sizeof calculation for object of type '{typename(obj)}' failed. "
f"Defaulting to {format_bytes(int(default_size))}",
exc_info=True,
)
return int(default_size)
5 changes: 4 additions & 1 deletion distributed/tests/test_sizeof.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ def __sizeof__(self):
with captured_logger("distributed.sizeof") as logs:
assert safe_sizeof(foo) == 1e6

assert "Sizeof calculation failed. Defaulting to 0.95 MiB" in logs.getvalue()
assert (
"Sizeof calculation for object of type 'test_sizeof.BadlySized' failed. Defaulting to 0.95 MiB"
in logs.getvalue()
)

# Can provide custom `default_size`
with captured_logger("distributed.sizeof") as logs:
Expand Down

0 comments on commit 8c93366

Please sign in to comment.