---
sidebar:
  hidden: true
title: roboto.formats.parquet.arrow_to_roboto
---
## Module Contents

### arrow_type_to_canonical_type()

```python
def roboto.formats.parquet.arrow_to_roboto.arrow_type_to_canonical_type(
    arrow_type: pyarrow.DataType,
) -> roboto.domain.topics.record.CanonicalDataType
```

`from roboto.formats.parquet.arrow_to_roboto import arrow_type_to_canonical_type`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/parquet/arrow_to_roboto.py#L28-L86)

Return the [`CanonicalDataType`](/docs/reference/python-sdk/roboto/domain/topics/record#roboto.domain.topics.record.CanonicalDataType) Roboto gives a Parquet field of `arrow_type`.

`generate_message_path_requests` gives each field its canonical data type through it, so most code never calls it. That function gives the file's timestamp field `Timestamp` whatever this returns. Types map as follows:

- Booleans: `Boolean`.
- Integers, decimals and floating-point numbers: `Number`.
- Timestamps in UTC: `Timestamp`. A timestamp in any other time zone, or in none, is `Unknown`.
- Strings: `String`.
- Dictionary-encoded columns: `Categorical`.
- Maps and structs: `Object`.
- Lists, of any of pyarrow's three list types: `NumberArray` when the elements are integers wider than 8 bits, floating-point numbers or decimals, and `Array` otherwise. A list of 8-bit integers is `Array` because it typically holds raw bytes, such as an image or a serialized blob, rather than a signal to plot.
- Binary values: `Byte`.
- Any other type: `Unknown`.

**Parameters**

- **arrow_type** (`pyarrow.DataType`): pyarrow type of the field.

**Returns**

- `roboto.domain.topics.record.CanonicalDataType`

### compute_boolean_statistics()

```python
def roboto.formats.parquet.arrow_to_roboto.compute_boolean_statistics(
    data: Union[pyarrow.Array, pyarrow.ChunkedArray],
) -> dict[str, Any]
```

`from roboto.formats.parquet.arrow_to_roboto import compute_boolean_statistics`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/parquet/arrow_to_roboto.py#L136-L157)

Count the true and false values in `data`, skipping nulls.

`generate_message_path_requests` counts the values of `Boolean` fields through it, so most code never calls it.

**Parameters**

- **data** (`Union[pyarrow.Array, pyarrow.ChunkedArray]`): Boolean values of the field.

**Returns**

- `dict[str, Any]`: `{"true_count": <count>, "false_count": <count>}`.

### compute_dictionary_metadata()

```python
def roboto.formats.parquet.arrow_to_roboto.compute_dictionary_metadata(
    column_name: str,
    data: Union[pyarrow.Array, pyarrow.ChunkedArray],
    max_dictionary_size: int = 2048,
) -> dict[str, Any]
```

`from roboto.formats.parquet.arrow_to_roboto import compute_dictionary_metadata`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/parquet/arrow_to_roboto.py#L160-L208)

Build the categories metadata of a dictionary-encoded field: its dictionary's values, in order.

`generate_message_path_requests` records the categories of `Categorical` fields through it, so most code never calls it. The categories let Roboto show each stored integer as the value it stands for.

**Parameters**

- **column_name** (`str`): Path of the field, used only to name it in the warning logged when its categories are too large.
- **data** (`Union[pyarrow.Array, pyarrow.ChunkedArray]`): Values of the field.
- **max_dictionary_size** (`int`): Largest combined size of the categories, in bytes, to record, which keeps the message path record small. A string counts its UTF-8 length and a value with no length, such as an integer, counts as zero. Larger categories are left out and a warning is logged; the field stays `Categorical`.

**Returns**

- `dict[str, Any]`: The categories under the [`Categories`](/docs/reference/python-sdk/roboto/domain/topics/record#roboto.domain.topics.record.MessagePathMetadataWellKnown.Categories) key, or an empty dictionary when `data` is not dictionary-encoded or its categories are larger than `max_dictionary_size`.

### compute_field_metadata()

```python
def roboto.formats.parquet.arrow_to_roboto.compute_field_metadata(
    parser: roboto.formats.parquet.parquet_parser.ParquetParser,
    column_name: str,
    field_path: list[str],
    canonical_data_type: roboto.domain.topics.record.CanonicalDataType,
    is_inside_list: bool = False,
) -> dict[str, Any]
```

`from roboto.formats.parquet.arrow_to_roboto import compute_field_metadata`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/parquet/arrow_to_roboto.py#L274-L339)

Compute the statistics metadata of one field from its values in the Parquet file.

`generate_message_path_requests` computes the metadata of every field except structs through it, so most code never calls it. The field's [`CanonicalDataType`](/docs/reference/python-sdk/roboto/domain/topics/record#roboto.domain.topics.record.CanonicalDataType) selects the metadata:

- `Number` and `NumberArray`: minimum, maximum, mean and approximate median, over every element of an array.
- `Boolean`: `true_count` and `false_count`.
- `Categorical`: the field's categories.
- Any other type: none.

When reading the values or computing the statistics raises any exception, logs a warning and returns an empty dictionary, so one field's failure leaves the file's other fields with their statistics.

**Parameters**

- **parser** (`roboto.formats.parquet.parquet_parser.ParquetParser`): Parser of the Parquet file to read the field's values from.
- **column_name** (`str`): Name of the top-level column that holds the field.
- **field_path** (`list[str]`): Names of the struct fields from the column down to the field, or, inside a list of structs, from the list's elements down to the field. Empty for the column itself.
- **canonical_data_type** (`roboto.domain.topics.record.CanonicalDataType`): Canonical data type of the field.
- **is_inside_list** (`bool`): Whether the field is inside a list of structs, so its values are read across every list element.

**Returns**

- `dict[str, Any]`

### compute_numeric_statistics()

```python
def roboto.formats.parquet.arrow_to_roboto.compute_numeric_statistics(
    data: Union[pyarrow.Array, pyarrow.ChunkedArray],
) -> dict[str, Any]
```

`from roboto.formats.parquet.arrow_to_roboto import compute_numeric_statistics`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/parquet/arrow_to_roboto.py#L100-L133)

Compute the minimum, maximum, mean and approximate median of `data`, skipping nulls.

`generate_message_path_requests` computes the statistics of `Number` and `NumberArray` fields through it, so most code never calls it.

**Parameters**

- **data** (`Union[pyarrow.Array, pyarrow.ChunkedArray]`): Numeric values of the field.

**Returns**

- `dict[str, Any]`: The four statistics, keyed by their [`MessagePathStatistic`](/docs/reference/python-sdk/roboto/domain/topics/record#roboto.domain.topics.record.MessagePathStatistic) values (`min`, `max`, `mean` and `median`). Each is `None` when `data` has no values other than nulls.

### generate_message_path_requests()

```python
def roboto.formats.parquet.arrow_to_roboto.generate_message_path_requests(
    parser: roboto.formats.parquet.parquet_parser.ParquetParser,
    timestamp: roboto.formats.parquet.timestamp.TimestampInfo,
    max_depth: int = 10,
) -> Generator[roboto.domain.topics.operations.AddMessagePathRequest, None, None]
```

`from roboto.formats.parquet import generate_message_path_requests`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/parquet/arrow_to_roboto.py#L470-L524)

Yield an [`AddMessagePathRequest`](/docs/reference/python-sdk/roboto/domain/topics/operations#roboto.domain.topics.operations.AddMessagePathRequest) for every field of a Parquet file.

[`create_from_df()`](/docs/reference/python-sdk/roboto/domain/topics/topic#roboto.domain.topics.topic.Topic.create_from_df) passes the requests to [`create()`](/docs/reference/python-sdk/roboto/domain/topics/topic#roboto.domain.topics.topic.Topic.create) as the new topic's message paths. Each request carries:

- A message path that joins the field's name to the names of the fields it is nested in, with dots. A dot within a name becomes an underscore; `path_in_schema` keeps the names unchanged.
- The [`CanonicalDataType`](/docs/reference/python-sdk/roboto/domain/topics/record#roboto.domain.topics.record.CanonicalDataType) that `arrow_type_to_canonical_type` gives the field's type. The file's timestamp field is always `Timestamp` and records its unit under the [`Unit`](/docs/reference/python-sdk/roboto/domain/topics/record#roboto.domain.topics.record.MessagePathMetadataWellKnown.Unit) metadata key.
- Statistics for numeric and boolean fields and categories for categorical ones, as `compute_field_metadata` computes them. A field whose statistics cannot be computed gets none, and a warning is logged.

A struct yields an `Object` message path and then one for each of its fields. A list of structs yields a message path for the list and then one for each struct field, whose statistics cover that field's values in every list element. For example:

- `position: struct<x: double, y: double>` yields `position` (`Object`), then `position.x` and `position.y` (`Number`).
- `values: list<double>` yields `values` (`NumberArray`).
- `points: list<struct<x: double, y: double>>` yields `points` (`Array`), then `points.x` and `points.y` (`Number`).

**Parameters**

- **parser** (`roboto.formats.parquet.parquet_parser.ParquetParser`): Parser of the Parquet file to describe, which the statistics are computed from.
- **timestamp** (`roboto.formats.parquet.timestamp.TimestampInfo`): Timestamp field of the file and its unit, from [`extract_timestamp_info()`](/docs/reference/python-sdk/roboto/formats/parquet/parquet_parser#roboto.formats.parquet.parquet_parser.ParquetParser.extract_timestamp_info).
- **max_depth** (`int`): Number of levels below a top-level column that get message paths. A struct or list of structs at the deepest level gets a message path, but its fields do not, and a warning is logged.

**Returns**

- `Generator[roboto.domain.topics.operations.AddMessagePathRequest, None, None]`

**Usage**

```python
import pathlib
from roboto.formats.parquet import ParquetParser, generate_message_path_requests
parser = ParquetParser(pathlib.Path("sensor_data.parquet"))
timestamp = parser.extract_timestamp_info("timestamp")
for request in generate_message_path_requests(parser, timestamp):
    print(request.message_path, request.canonical_data_type)
```

### get_list_element_data()

```python
def roboto.formats.parquet.arrow_to_roboto.get_list_element_data(
    parser: roboto.formats.parquet.parquet_parser.ParquetParser,
    column_name: str,
    field_path: list[str],
) -> Union[pyarrow.Array, pyarrow.ChunkedArray]
```

`from roboto.formats.parquet.arrow_to_roboto import get_list_element_data`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/parquet/arrow_to_roboto.py#L240-L271)

Read the values of a field inside a top-level list column of the Parquet file, across every list element.

`generate_message_path_requests` reads the values of a field inside a list of structs through it, so most code never calls it. The elements of every row's list are joined into one array, so statistics computed from it cover all of them.

**Parameters**

- **parser** (`roboto.formats.parquet.parquet_parser.ParquetParser`): Parser of the Parquet file to read from.
- **column_name** (`str`): Name of the top-level column, which must be a list.
- **field_path** (`list[str]`): Names of the struct fields from the list's elements down to the field. Empty reads the elements themselves.

**Raises**

- `IndexError`: The file has no column named `column_name`.
- `pyarrow.ArrowNotImplementedError`: The column is not a list.
- `pyarrow.ArrowInvalid`: A name in `field_path` matches no field of the struct it is looked up in.

**Returns**

- `Union[pyarrow.Array, pyarrow.ChunkedArray]`

### get_nested_column_data()

```python
def roboto.formats.parquet.arrow_to_roboto.get_nested_column_data(
    parser: roboto.formats.parquet.parquet_parser.ParquetParser,
    column_name: str,
    field_path: list[str],
) -> Union[pyarrow.Array, pyarrow.ChunkedArray]
```

`from roboto.formats.parquet.arrow_to_roboto import get_nested_column_data`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/parquet/arrow_to_roboto.py#L211-L237)

Read the values of a field nested in structs under a top-level column of the Parquet file.

`generate_message_path_requests` reads the values of a field that is not inside a list of structs through it, so most code never calls it.

**Parameters**

- **parser** (`roboto.formats.parquet.parquet_parser.ParquetParser`): Parser of the Parquet file to read from.
- **column_name** (`str`): Name of the top-level column that holds the field.
- **field_path** (`list[str]`): Names of the struct fields from the column down to the field. Empty reads the column itself.

**Raises**

- `IndexError`: The file has no column named `column_name`.
- `pyarrow.ArrowInvalid`: A name in `field_path` matches no field of the struct it is looked up in.

**Returns**

- `Union[pyarrow.Array, pyarrow.ChunkedArray]`

### logger

```python
roboto.formats.parquet.arrow_to_roboto.logger
```

`from roboto.formats.parquet.arrow_to_roboto import logger`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/parquet/arrow_to_roboto.py#L25-L25)

### sanitize_column_name()

```python
def roboto.formats.parquet.arrow_to_roboto.sanitize_column_name(
    field: pyarrow.Field,
) -> str
```

`from roboto.formats.parquet.arrow_to_roboto import sanitize_column_name`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/parquet/arrow_to_roboto.py#L89-L97)

Return the field's name with each `.` replaced by `_`, the form a message path uses for it.

A message path separates nested fields with dots, so a dot within a field name would read as nesting.

**Parameters**

- **field** (`pyarrow.Field`): pyarrow field whose name to convert.

**Returns**

- `str`
