> ## Documentation Index
> Fetch the complete documentation index at: https://docs.activeviam.com/llms.txt
> Use this file to discover all available pages before exploring further.

# LexicographicalOrder

<span id="atoti.LexicographicalOrder" />

> atoti.LexicographicalOrder(<br />
>     \*,<br />
>     *ascending*: [bool](https://docs.python.org/3/library/functions.html#bool) = `True`,<br />
> )

[Lexicographical order](https://en.wikipedia.org/wiki/Lexicographic_order).

This order only differs from [`atoti.NaturalOrder`](./atoti.order.NaturalOrder#atoti.NaturalOrder) for [`strings`](./atoti.type#atoti.type.STRING) and for [`objects`](./atoti.type#atoti.type.OBJECT) that do not implement [Comparable](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Comparable.html).

```pycon theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
>>> df = pd.DataFrame(
...     {
...         "File": ["file10", "file2", "file1"],
...         "Quantity": [10, 2, 1],
...     }
... )
>>> table = session.read_pandas(df, table_name="String")
>>> cube = session.create_cube(table)
>>> l, m = cube.levels, cube.measures
>>> l["File"].order
LexicographicalOrder(ascending=True)
```

Digit sequences in strings are compared character by character rather than by their numeric value:

```pycon theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
>>> cube.query(m["Quantity.SUM"], levels=[l["File"]])
       Quantity.SUM
File
file1             1
file10           10
file2             2
>>> l["File"].order = tt.LexicographicalOrder(ascending=False)
>>> cube.query(m["Quantity.SUM"], levels=[l["File"]])
       Quantity.SUM
File
file2             2
file10           10
file1             1
```

Objects that do not implement `Comparable` are compared through their string representation:

```pycon theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
>>> import pyarrow as pa
>>> table = session.create_table(
...     "Object", data_types={"Point": "Object", "Quantity": "int"}
... )
>>> table.load(
...     pa.Table.from_pydict(
...         {
...             "Point": pa.array(
...                 [{"x": 10, "y": 0}, {"x": 2, "y": 0}, {"x": 1, "y": 0}],
...                 type=pa.struct([("x", pa.int64()), ("y", pa.int64())]),
...             ),
...             "Quantity": pa.array([10, 2, 1]),
...         }
...     )
... )
>>> cube = session.create_cube(table)
>>> l, m = cube.levels, cube.measures
>>> l["Point"].order
LexicographicalOrder(ascending=True)
>>> cube.query(m["Quantity.SUM"], levels=[l["Point"]])
               Quantity.SUM
Point
{"x":1,"y":0}             1
{"x":10,"y":0}           10
{"x":2,"y":0}             2
>>> l["Point"].order = tt.NaturalOrder()
>>> l["Point"].order
NaturalOrder(ascending=True)
>>> cube.query(m["Quantity.SUM"], levels=[l["Point"]])
               Quantity.SUM
Point
{"x":1,"y":0}             1
{"x":2,"y":0}             2
{"x":10,"y":0}           10
```

<Callout icon="link">
  **See also**:
  All the available [`orders`](./atoti.order#module-atoti.order).
</Callout>

### Attributes

<h4 id="atoti.LexicographicalOrder.ascending">
  *ascending*
</h4>

> [bool](https://docs.python.org/3/library/functions.html#bool)
