Module pypestutils.enum

Enumeration module.

Expand source code
"""Enumeration module."""
from __future__ import annotations

from enum import IntEnum


class ParamEnum(IntEnum):
    """Wraps IntEnum to provide validation of a requested item.

    Intended for enums used for function parameters.

    Use enum.get_value(item) for this behavior instead of builtin enum[item].
    """

    @classmethod
    def get_valid_options(cls) -> dict[int, str]:
        """Get valid options as a dict."""
        return dict((e.value, e.name) for e in cls)

    @classmethod
    def get_value(cls, item: str) -> int:
        """Get integer value from str key.

        Validate item and raise a ValueError with valid options.
        """
        try:
            return cls[item].value
        except KeyError:
            valid_options_list = [
                f"'{n}' ({v})" for (v, n) in cls.get_valid_options().items()
            ]
            raise ValueError(
                "{}: '{}' is not a valid option, must be one of {}".format(
                    cls.__name__, item, ", ".join(valid_options_list)
                )
            )


class Prec(ParamEnum):
    """Floating precision type, where 1 is single and 2 is double precision."""

    single = 1
    double = 2


class KrigType(ParamEnum):
    """Kriging type, where 0 is simple and 1 is ordinary."""

    simple = 0
    ordinary = 1


class VarioType(ParamEnum):
    """Variogram type, where 1:spher, 2:exp, 3:gauss and 4:pow."""

    spher = 1
    exp = 2
    gauss = 3
    pow = 4


class FactorFileType(ParamEnum):
    """Factor file type, where 0 is binary and 1 is text."""

    binary = 0
    text = 1


class StrucType(ParamEnum):
    """Structure type, where 0 is for polylinear and 1 for polygonal."""

    polylinear = 0
    polygonal = 1


class TransType(ParamEnum):
    """Enable log-transformation of values."""

    none = 0
    log = 1

Classes

class FactorFileType (*args, **kwds)

Factor file type, where 0 is binary and 1 is text.

Expand source code
class FactorFileType(ParamEnum):
    """Factor file type, where 0 is binary and 1 is text."""

    binary = 0
    text = 1

Ancestors

  • ParamEnum
  • enum.IntEnum
  • builtins.int
  • enum.ReprEnum
  • enum.Enum

Class variables

var binary
var text

Inherited members

class KrigType (*args, **kwds)

Kriging type, where 0 is simple and 1 is ordinary.

Expand source code
class KrigType(ParamEnum):
    """Kriging type, where 0 is simple and 1 is ordinary."""

    simple = 0
    ordinary = 1

Ancestors

  • ParamEnum
  • enum.IntEnum
  • builtins.int
  • enum.ReprEnum
  • enum.Enum

Class variables

var ordinary
var simple

Inherited members

class ParamEnum (*args, **kwds)

Wraps IntEnum to provide validation of a requested item.

Intended for enums used for function parameters.

Use enum.get_value(item) for this behavior instead of builtin enum[item].

Expand source code
class ParamEnum(IntEnum):
    """Wraps IntEnum to provide validation of a requested item.

    Intended for enums used for function parameters.

    Use enum.get_value(item) for this behavior instead of builtin enum[item].
    """

    @classmethod
    def get_valid_options(cls) -> dict[int, str]:
        """Get valid options as a dict."""
        return dict((e.value, e.name) for e in cls)

    @classmethod
    def get_value(cls, item: str) -> int:
        """Get integer value from str key.

        Validate item and raise a ValueError with valid options.
        """
        try:
            return cls[item].value
        except KeyError:
            valid_options_list = [
                f"'{n}' ({v})" for (v, n) in cls.get_valid_options().items()
            ]
            raise ValueError(
                "{}: '{}' is not a valid option, must be one of {}".format(
                    cls.__name__, item, ", ".join(valid_options_list)
                )
            )

Ancestors

  • enum.IntEnum
  • builtins.int
  • enum.ReprEnum
  • enum.Enum

Subclasses

Static methods

def get_valid_options() ‑> dict[int, str]

Get valid options as a dict.

Expand source code
@classmethod
def get_valid_options(cls) -> dict[int, str]:
    """Get valid options as a dict."""
    return dict((e.value, e.name) for e in cls)
def get_value(item: str) ‑> int

Get integer value from str key.

Validate item and raise a ValueError with valid options.

Expand source code
@classmethod
def get_value(cls, item: str) -> int:
    """Get integer value from str key.

    Validate item and raise a ValueError with valid options.
    """
    try:
        return cls[item].value
    except KeyError:
        valid_options_list = [
            f"'{n}' ({v})" for (v, n) in cls.get_valid_options().items()
        ]
        raise ValueError(
            "{}: '{}' is not a valid option, must be one of {}".format(
                cls.__name__, item, ", ".join(valid_options_list)
            )
        )
class Prec (*args, **kwds)

Floating precision type, where 1 is single and 2 is double precision.

Expand source code
class Prec(ParamEnum):
    """Floating precision type, where 1 is single and 2 is double precision."""

    single = 1
    double = 2

Ancestors

  • ParamEnum
  • enum.IntEnum
  • builtins.int
  • enum.ReprEnum
  • enum.Enum

Class variables

var double
var single

Inherited members

class StrucType (*args, **kwds)

Structure type, where 0 is for polylinear and 1 for polygonal.

Expand source code
class StrucType(ParamEnum):
    """Structure type, where 0 is for polylinear and 1 for polygonal."""

    polylinear = 0
    polygonal = 1

Ancestors

  • ParamEnum
  • enum.IntEnum
  • builtins.int
  • enum.ReprEnum
  • enum.Enum

Class variables

var polygonal
var polylinear

Inherited members

class TransType (*args, **kwds)

Enable log-transformation of values.

Expand source code
class TransType(ParamEnum):
    """Enable log-transformation of values."""

    none = 0
    log = 1

Ancestors

  • ParamEnum
  • enum.IntEnum
  • builtins.int
  • enum.ReprEnum
  • enum.Enum

Class variables

var log
var none

Inherited members

class VarioType (*args, **kwds)

Variogram type, where 1:spher, 2:exp, 3:gauss and 4:pow.

Expand source code
class VarioType(ParamEnum):
    """Variogram type, where 1:spher, 2:exp, 3:gauss and 4:pow."""

    spher = 1
    exp = 2
    gauss = 3
    pow = 4

Ancestors

  • ParamEnum
  • enum.IntEnum
  • builtins.int
  • enum.ReprEnum
  • enum.Enum

Class variables

var exp
var gauss
var pow
var spher

Inherited members