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

Class _PrettyBlocks

dask/array/rechunk.py:753–789  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

751
752
753class _PrettyBlocks:
754 def __init__(self, blocks):
755 self.blocks = blocks
756
757 def __str__(self):
758 runs = []
759 run = []
760 repeats = 0
761 for c in self.blocks:
762 if run and run[-1] == c:
763 if repeats == 0 and len(run) > 1:
764 runs.append((None, run[:-1]))
765 run = run[-1:]
766 repeats += 1
767 else:
768 if repeats > 0:
769 assert len(run) == 1
770 runs.append((repeats + 1, run[-1]))
771 run = []
772 repeats = 0
773 run.append(c)
774 if run:
775 if repeats == 0:
776 runs.append((None, run))
777 else:
778 assert len(run) == 1
779 runs.append((repeats + 1, run[-1]))
780
781 parts = []
782 for repeats, run in runs:
783 if repeats is None:
784 parts.append(str(run))
785 else:
786 parts.append(f"{repeats}*[{run}]")
787 return " | ".join(parts)
788
789 __repr__ = __str__
790
791
792def format_blocks(blocks):

Callers 1

format_blocksFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected