Skip to content

datar.core.names

module

datar.core.names

Name repairing

Classes
Functions
  • repair_names(names, repair) (List) Repair names based on the method</>
class

datar.core.names.NameNonUniqueError()

Bases
ValueError Exception BaseException

Error for non-unique names

function

datar.core.names.repair_names(names, repair)

Repair names based on the method

Parameters
  • names (Iterable) The names to be repaired
  • repair (Union) The method to repair
    • - minimal: Minimal names are never None or NA.
        When an element doesn't have a name, its minimal name
        is an empty string.
    • - unique: Unique names are unique. A suffix is appended to
        duplicate names to make them unique.
    • - universal: Universal names are unique and syntactic,
        meaning that you can safely use the names as variables without
        causing a syntax error (like f.<name>).
    • - A function, accepts either a list of names or a single name.
        Function accepts a list of names must annotate the first
        argument with typing.Iterable or typing.Sequence.
Examples
>>> repair_names([None]*3, repair="minimal")>>> # ["", "", ""]
>>> repair_names(["x", NA], repair="minimal")
>>> # ["x", ""]
>>> repair_names(["", "x", "", "y", "x", "_2", "__"], repair="unique")
>>> # ["__1", "x__2", "__3", "y", "x__5", "__6", "__7"]
>>> repair_names(["", "x", NA, "x"], repair="universal")
>>> # ["__1", "x__2", "__3", "x__4"]
>>> repair_names(["(y)"  "_z"  ".2fa"  "False"], repair="universal")
>>> # ["_y_", "_z", "_2fa", "_False"]
Returns (List)

The repaired names

Raises
  • NameNonUniqueError when check_unique fails
  • ValueError when repair is not a string or callable