Columns

class rolumns.Columns(cursor: Optional[Union[Cursor, Group, str]] = None)[source]

A set of columns.

from rolumns import Columns

data = [
    {
        "name": "Robert Pringles",
        "email": "bob@pringles.pop",
    },
]

columns = Columns()
columns.add("Name", "name")
columns.add("Email", "email")
add(name: str, source: Optional[Union[Source, str]] = None) None[source]

Adds a column.

source describes the data source for the column, which can be:

  • an explicit Source

  • a string that describes the .-separated path to the value

  • None if this set’s record is an iterable list of primitives

from rolumns import Columns, Source

data = [
    {
        "name": "Robert Pringles",
        "email": "bob@pringles.pop",
        "awards": [
            "Fastest Doughnut Run",
            "Tie of the Year",
        ],
    },
]

columns = Columns()
columns.add("Name", "name")
columns.add("Email", Source(path="email"))

awards = columns.group("awards")
# "awards" is also a column set
awards.add("Awards")
property cursor: Cursor

Cursor.

group(cursor: Union[Cursor, Group, str]) Columns[source]

Creates and adds a grouped column set.

A column set cannot have multiple groups (though each group can have its own group). Will raise exceptions.MultipleGroups if you try to add a second group.

from rolumns import Columns, Source

data = [
    {
        "name": "Robert Pringles",
        "awards": [
            "Fastest Doughnut Run",
            "Tie of the Year",
        ],
    },
]

columns = Columns()
columns.add("Name", "name")

awards = columns.group("awards")
awards.add("Awards")
names() List[str][source]

Gets the names of the columns within this set and its children.

normalize() List[Dict[str, Any]][source]

Normalises data into a list of dictionaries describing column names and values.

static normalized_to_column_values(normalized: List[Dict[str, Any]]) Dict[str, List[Any]][source]

Translates the normalised list of values normalized to a dictionary of column names and values.

to_column_values() Dict[str, List[Any]][source]

Translates data to a dictionary of column names and values.