MCPcopy
hub / github.com/dask/dask / format_bytes

Function format_bytes

dask/utils.py:1768–1796  ·  view source on GitHub ↗

Format bytes as text >>> from dask.utils import format_bytes >>> format_bytes(1) '1 B' >>> format_bytes(1234) '1.21 kiB' >>> format_bytes(12345678) '11.77 MiB' >>> format_bytes(1234567890) '1.15 GiB' >>> format_bytes(1234567890000) '1.12 TiB' >>> form

(n: int)

Source from the content-addressed store, hash-verified

1766
1767
1768def format_bytes(n: int) -> str:
1769 """Format bytes as text
1770
1771 >>> from dask.utils import format_bytes
1772 >>> format_bytes(1)
1773 '1 B'
1774 >>> format_bytes(1234)
1775 '1.21 kiB'
1776 >>> format_bytes(12345678)
1777 '11.77 MiB'
1778 >>> format_bytes(1234567890)
1779 '1.15 GiB'
1780 >>> format_bytes(1234567890000)
1781 '1.12 TiB'
1782 >>> format_bytes(1234567890000000)
1783 '1.10 PiB'
1784
1785 For all values < 2**60, the output is always <= 10 characters.
1786 """
1787 for prefix, k in (
1788 ("Pi", 2**50),
1789 ("Ti", 2**40),
1790 ("Gi", 2**30),
1791 ("Mi", 2**20),
1792 ("ki", 2**10),
1793 ):
1794 if n >= k * 0.9:
1795 return f"{n / k:.2f} {prefix}B"
1796 return f"{n} B"
1797
1798
1799timedelta_sizes = {

Callers 3

test_format_bytesFunction · 0.90
test_filtersFunction · 0.90
_repr_html_Method · 0.90

Calls

no outgoing calls

Tested by 2

test_format_bytesFunction · 0.72
test_filtersFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…