MCPcopy
hub / github.com/pydata/xarray / render_human_readable_nbytes

Function render_human_readable_nbytes

xarray/core/formatting.py:1298–1338  ·  view source on GitHub ↗

Renders simple human-readable byte count representation This is only a quick representation that should not be relied upon for precise needs. To get the exact byte count, please use the ``nbytes`` attribute directly. Parameters ---------- nbytes Byte count attempt_

(
    nbytes: int,
    /,
    *,
    attempt_constant_width: bool = False,
)

Source from the content-addressed store, hash-verified

1296
1297
1298def render_human_readable_nbytes(
1299 nbytes: int,
1300 /,
1301 *,
1302 attempt_constant_width: bool = False,
1303) -> str:
1304 """Renders simple human-readable byte count representation
1305
1306 This is only a quick representation that should not be relied upon for precise needs.
1307
1308 To get the exact byte count, please use the ``nbytes`` attribute directly.
1309
1310 Parameters
1311 ----------
1312 nbytes
1313 Byte count
1314 attempt_constant_width
1315 For reasonable nbytes sizes, tries to render a fixed-width representation.
1316
1317 Returns
1318 -------
1319 Human-readable representation of the byte count
1320 """
1321 dividend = float(nbytes)
1322 divisor = 1000.0
1323 last_unit_available = UNITS[-1]
1324
1325 for unit in UNITS:
1326 if dividend < divisor or unit == last_unit_available:
1327 break
1328 dividend /= divisor
1329
1330 dividend_str = f"{dividend:.0f}"
1331 unit_str = f"{unit}"
1332
1333 if attempt_constant_width:
1334 dividend_str = dividend_str.rjust(3)
1335 unit_str = unit_str.ljust(2)
1336
1337 string = f"{dividend_str}{unit_str}"
1338 return string

Callers 3

summarize_variableFunction · 0.85
array_reprFunction · 0.85
dataset_reprFunction · 0.85

Calls 2

rjustMethod · 0.80
ljustMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…