MCPcopy Create free account
hub / github.com/dask/dask / format_bytes

Function format_bytes

dask/utils.py:1771–1799  ·  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

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