> ## 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.

# StringComparison

> atoti.StringComparison(\
>
>     \*,\
>
>     *case*: [Literal](https://docs.python.org/3/library/typing.html#typing.Literal)\['sensitive', 'insensitive'] = `'sensitive'`,\
>
>     *digits*: [Literal](https://docs.python.org/3/library/typing.html#typing.Literal)\['lexicographic', 'numeric'] = `'lexicographic'`,\
>
> )

How [`strings`](./atoti.type#atoti.type.STRING) are compared.

[`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) are compared through their string representation, so these options apply to them too.
Ignored for all the other [`data types`](./atoti.type#module-atoti.type).

```pycon theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
>>> df = pd.DataFrame(
...     {"File": ["file1", "file10", "file2", "File1", "File10", "File2"]}
... )
>>> table = session.read_pandas(df, table_name="Example")
>>> cube = session.create_cube(table)
>>> l, m = cube.levels, cube.measures
```

Comparing digits character by character:

```pycon theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
>>> l["File"].ordering = tt.Ordering(
...     string_comparison=tt.StringComparison(digits="lexicographic"),
... )
>>> cube.query(m["contributors.COUNT"], levels=[l["File"]]).index.tolist()
['File1', 'File10', 'File2', 'file1', 'file10', 'file2']
```

Comparing digits by their numeric value:

```pycon theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
>>> l["File"].ordering = tt.Ordering(
...     string_comparison=tt.StringComparison(digits="numeric"),
... )
>>> cube.query(m["contributors.COUNT"], levels=[l["File"]]).index.tolist()
['File1', 'File2', 'File10', 'file1', 'file2', 'file10']
```

When letters are compared case-sensitively, uppercase elements come first:

```pycon theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
>>> l["File"].ordering = tt.Ordering(
...     string_comparison=tt.StringComparison(case="sensitive"),
... )
>>> cube.query(m["contributors.COUNT"], levels=[l["File"]]).index.tolist()
['File1', 'File10', 'File2', 'file1', 'file10', 'file2']
```

When letters are compared case-insensitively, elements differing only by case remain distinct, with the uppercase one first:

```pycon theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
>>> l["File"].ordering = tt.Ordering(
...     string_comparison=tt.StringComparison(case="insensitive"),
... )
>>> l["File"].ordering.string_comparison.case
'insensitive'
>>> cube.query(m["contributors.COUNT"], levels=[l["File"]]).index.tolist()
['File1', 'file1', 'File10', 'file10', 'File2', 'file2']
```

**See also**:
[`atoti.Ordering.string_comparison`](./atoti.ordering.Ordering#atoti.Ordering.string_comparison).

> [!NOTE]
>
> Added in version 6.2.1.

### Attributes

#### *case*

How letters are compared.

* `"sensitive"`: letters differing only by case are different.
* `"insensitive"`: the case is ignored.

#### *digits*

How digit sequences are compared.

* `"lexicographic"`: character by character.
* `"numeric"`: by their value.
