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)
| 1766 | |
| 1767 | |
| 1768 | def 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 | |
| 1799 | timedelta_sizes = { |
no outgoing calls
searching dependent graphs…