Thanks to visit codestin.com
Credit goes to sshmo.github.io

Skip to content

Base

Base implementation.

Base

Bases: ABC

Base.

Attributes:

Name Type Description
input_count int

number of entry data.

keys Set[str]

set of keys for which we calculate and represent statistics.

key_data Any

data structure for saving key data.

key_stats Any

data structure for calculating key statistics.

Source code in pytry/general/base.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class Base(ABC):
    """Base.

    Attributes:
        input_count: number of entry data.
        keys: set of keys for which we calculate and represent statistics.
        key_data: data structure for saving key data.
        key_stats: data structure for calculating key statistics.
    """

    @abstractmethod
    def __init__(self, input_func: Any, default_count: Optional[int]) -> None:
        """Given input_func; Inits Base attributes.

        Args:
            input_func: A function for generating input data.
            default_count: default number of keys if input_count is not specified.
        """
        if isinstance(default_count, int) and default_count < 0:
            raise ValueError(f"Invalid value for default count: {default_count}")
        self.input_count: int = default_count if default_count is not None else self.get_input_count(input_func)
        self.keys: Set[str]
        self.key_stats: Any
        self.key_data: Any

    @staticmethod
    @abstractmethod
    def _get_key_data(input_func: Any, input_count: int):
        """get_key_data."""

    @staticmethod
    def get_input_count(input_func: Any) -> int:
        """get_input_count."""
        while True:
            num: str = input_func()
            input_count = int(num) if num.isdigit() else None
            if input_count and input_count > 0:
                break
            print("Invalid number!")
        return input_count

    def __repr__(self) -> str:  # pragma: no cover
        """Given key_stats; create key_stats representation for all keys."""
        return ""

    @abstractmethod
    def update_stats(self, key_stats, key) -> Any:
        """Update stats of a key for a single row.

        Returns:
            updated stats for each key
        """

    @abstractmethod
    def main(self) -> None:
        """Given key_data from the input; calculates key_stats."""

__init__(input_func, default_count) abstractmethod

Given input_func; Inits Base attributes.

Parameters:

Name Type Description Default
input_func Any

A function for generating input data.

required
default_count Optional[int]

default number of keys if input_count is not specified.

required
Source code in pytry/general/base.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
@abstractmethod
def __init__(self, input_func: Any, default_count: Optional[int]) -> None:
    """Given input_func; Inits Base attributes.

    Args:
        input_func: A function for generating input data.
        default_count: default number of keys if input_count is not specified.
    """
    if isinstance(default_count, int) and default_count < 0:
        raise ValueError(f"Invalid value for default count: {default_count}")
    self.input_count: int = default_count if default_count is not None else self.get_input_count(input_func)
    self.keys: Set[str]
    self.key_stats: Any
    self.key_data: Any

__repr__()

Given key_stats; create key_stats representation for all keys.

Source code in pytry/general/base.py
48
49
50
def __repr__(self) -> str:  # pragma: no cover
    """Given key_stats; create key_stats representation for all keys."""
    return ""

get_input_count(input_func) staticmethod

get_input_count.

Source code in pytry/general/base.py
37
38
39
40
41
42
43
44
45
46
@staticmethod
def get_input_count(input_func: Any) -> int:
    """get_input_count."""
    while True:
        num: str = input_func()
        input_count = int(num) if num.isdigit() else None
        if input_count and input_count > 0:
            break
        print("Invalid number!")
    return input_count

main() abstractmethod

Given key_data from the input; calculates key_stats.

Source code in pytry/general/base.py
60
61
62
@abstractmethod
def main(self) -> None:
    """Given key_data from the input; calculates key_stats."""

update_stats(key_stats, key) abstractmethod

Update stats of a key for a single row.

Returns:

Type Description
Any

updated stats for each key

Source code in pytry/general/base.py
52
53
54
55
56
57
58
@abstractmethod
def update_stats(self, key_stats, key) -> Any:
    """Update stats of a key for a single row.

    Returns:
        updated stats for each key
    """