LegendQL TDS Frame

The LegendQLApiBaseTdsFrame class provides a python-like interface for working with TDS (Tabular Data Store) frames.

Methods

sort

LegendQLApiBaseTdsFrame.sort(sort_infos)[source]

Sort the TDS frame based on the given columns.

Parameters:

sort_infos (Union[str, List[str], Callable[[LegendQLApiTdsRow], Union[LegendQLApiPrimitive, LegendQLApiSortInfo, List[Union[LegendQLApiPrimitive, LegendQLApiSortInfo]]]]]) –

str, list of str, or callable. A string or list of column names to sort by (ascending). Alternatively, a callable that takes a TDS row and returns one of:

  • a column (LegendQLApiPrimitive),

  • a LegendQLApiSortInfo (to specify direction), or

  • a list of columns and/or LegendQLApiSortInfo objects.

Returns:

A new TDS frame with the sort operation applied.

Return type:

LegendQLApiTdsFrame

In [1]: import pylegend

In [2]: from legendql_api_local_tds_client import legendql_api_local_tds_client

In [3]: tds_client = legendql_api_local_tds_client()  # for local testing

In [4]: frame = tds_client.legend_service_frame(
   ...:     service_pattern="/allOrders",
   ...:     group_id="org.finos.legend.pylegend",
   ...:     artifact_id="pylegend-northwind-models",
   ...:     version="0.0.1-SNAPSHOT"
   ...: )
   ...: 

In [5]: frame.schema()
Out[5]: 'Columns: Order Id(Integer), Order Date(StrictDate), Required Date(StrictDate), Shipped Date(StrictDate), Ship Name(String)'

In [6]: frame = frame.sort(lambda r: [r["Ship Name"].descending(), r["Order Id"].ascending()])

In [7]: frame.to_pandas_df()
Out[7]: 
     Order Id Order Date Required Date Shipped Date             Ship Name
0       10374 1996-12-05    1997-01-02   1996-12-09         Wolski Zajazd
1       10611 1997-07-25    1997-08-22   1997-08-01         Wolski Zajazd
2       10792 1997-12-23    1998-01-20   1997-12-31         Wolski Zajazd
3       10870 1998-02-04    1998-03-04   1998-02-13         Wolski Zajazd
4       10906 1998-02-25    1998-03-11   1998-03-03         Wolski Zajazd
..        ...        ...           ...          ...                   ...
825     10692 1997-10-03    1997-10-31   1997-10-13  Alfred's Futterkiste
826     10702 1997-10-13    1997-11-24   1997-10-21  Alfred's Futterkiste
827     10835 1998-01-15    1998-02-12   1998-01-21  Alfred's Futterkiste
828     10952 1998-03-16    1998-04-27   1998-03-24  Alfred's Futterkiste
829     11011 1998-04-09    1998-05-07   1998-04-13  Alfred's Futterkiste

[830 rows x 5 columns]