composeui.core.dataframesource

A dataframe’s rows in a large table, a chart or a map: pandas, Polars, PyArrow, lazy…

narwhals (the dataframe extra) reads each library’s frame through one API, so the library sorts and filters the rows with its own expressions, never row by row in Python.

class composeui.core.dataframesource.DataFrameSource[source]

Bases: object

A TableSource of a dataframe’s rows, which a large table reads a window at a time.

Build it with any frame narwhals reads (pandas, Polars, PyArrow, a Polars LazyFrame…) and the headers by column: DataFrameSource(frame, {"lat": T("Latitude")}), every column under its name without them. A row’s id is its position in the frame, or its id_column when it has one: a lazy frame needs one, its rows having no position of their own. Assign a new frame to change the rows, which emits changed.

The frame’s library sorts and filters: a text compares in lower case, which isn’t Python’s casefold (“ß” doesn’t find “SS”), and a /regex/ is in the library’s syntax (Rust’s regex for Polars, re for pandas). Equal cells, and the rows unsorted, keep the frame’s order.

__init__(frame, headers=None, *, id_column=None)[source]
Parameters:
  • frame (IntoFrame)

  • headers (Optional[Mapping[str, str]])

  • id_column (Optional[str])

Return type:

None

property columns: Sequence[SourceColumn]
property changed: Signal
property frame: IntoFrame

Get the frame given, in its own library.

count()[source]
Return type:

int

ordered_ids(sort, search, filters)[source]
Parameters:
Return type:

list[Hashable]

cells(ids, columns)[source]
Parameters:
  • ids (Sequence[Hashable])

  • columns (Sequence[str])

Return type:

dict[Hashable, list[Any]]

composeui.core.dataframesource.points_of(frame, latitude, longitude)[source]

Get a map’s points of a frame’s columns latitude and longitude, in degrees.

The rows missing either value, or out of a Web Mercator map (see MapPoint), are left out.

Parameters:
  • frame (IntoFrame)

  • latitude (str)

  • longitude (str)

Return type:

list[MapPoint]

composeui.core.dataframesource.series_of(frame, x, y, *, name=None)[source]

Make a chart’s series of a frame’s columns x and y, under name, else y.

The rows missing either value are left out, in the frame’s order otherwise.

Parameters:
  • frame (IntoFrame)

  • x (str)

  • y (str)

  • name (Optional[str])

Return type:

Series