TotalDepth.common.Slice (Data Slicing)

class TotalDepth.common.Slice.SliceABC
first(length: int) → int

The index of the first element of a sequence of length.

last(length: int) → int

The index of the last element of a sequence of length.

step(length: int) → int

The sequence of length step.

count(length: int) → int

Returns the number of values that will result if the slice is applied to a sequence of given length.

gen_indices(length: int) → range

Generates the indices for the sequence of the given length.

indices(length: int) → List[int]

Returns a fully composed list of indices for the sequence of the given length.

__eq__(other) → bool

Mostly used for testing.

long_str(length: int) → str

Return a long string.

__str__() → str

String representation.

__weakref__

list of weak references to the object (if defined)

class TotalDepth.common.Slice.Slice(start: Union[None, int] = None, stop: Union[None, int] = None, step: Union[None, int] = None)

Class that wraps a builtin slice object for integers and provides some useful APIs. NOTE: The builtin slice object can take non-integer values but raises later, for example:

slice(1, 4, 2.0).indices(45)
__init__(start: Union[None, int] = None, stop: Union[None, int] = None, step: Union[None, int] = None)

Initialize self. See help(type(self)) for accurate signature.

first(length: int) → int

The index of the first element of a sequence of length.

last(length: int) → int

The index of the last element of a sequence of length.

step(length: int) → int

The sequence of length step.

count(length: int) → int

Returns the number of values that will result if the slice is applied to a sequence of given length.

gen_indices(length: int) → range

Generates the indices for the sequence of the given length.

indices(length: int) → List[int]

Returns a fully composed list of indices for the sequence of the given length.

__eq__(other) → bool

Mostly used for testing.

long_str(length: int) → str

Return a long string.

__str__() → str

String representation.

class TotalDepth.common.Slice.Sample(sample_size: int)

This has the same API as Slice but takes a single integer.

NOTE: This may not produce a regular sequence. For example sampling 7 items out of a 12 element list gives the indices [0, 1, 3, 5, 6, 8, 10]

__init__(sample_size: int)

Initialize self. See help(type(self)) for accurate signature.

first(length) → int

The index of the first element of a sequence of length.

last(length) → int

The index of the last element of a sequence of length.

step(length) → int

The sequence of length step.

count(length: int) → int

Returns the number of values that will result if the slice is applied to a sequence of given length.

gen_indices(length: int) → range

Generates the indices for the sequence of the given length.

indices(length: int) → List[int]

Returns a fully composed list of indices for the sequence of the given length.

__eq__(other) → bool

Mostly used for testing.

long_str(length: int) → str

Long descriptive string.

__str__() → str

String representation.

TotalDepth.common.Slice.create_slice_or_sample(slice_string: str) → Union[TotalDepth.common.Slice.Slice, TotalDepth.common.Slice.Sample]

Returns a Slice object from a string such as: ‘’, ‘None,72’, ‘None,72,14’