pyarrow.map_

pyarrow.map_(key_type, item_type, keys_sorted=False) MapType

Create MapType instance from key and item data types or fields.

Parameters:
key_typeDataType or Field
item_typeDataType or Field
keys_sortedbool
Returns:
map_typeDataType

Examples

Create an instance of MapType:

>>> import pyarrow as pa
>>> pa.map_(pa.string(), pa.int32())
MapType(map<string, int32>)
>>> pa.map_(pa.string(), pa.int32(), keys_sorted=True)
MapType(map<string, int32, keys_sorted>)

Use MapType to create an array:

>>> data = [[{'key': 'a', 'value': 1}, {'key': 'b', 'value': 2}], [{'key': 'c', 'value': 3}]]
>>> pa.array(data, type=pa.map_(pa.string(), pa.int32(), keys_sorted=True))
<pyarrow.lib.MapArray object at ...>
[
  keys:
  [
    "a",
    "b"
  ]
  values:
  [
    1,
    2
  ],
  keys:
  [
    "c"
  ]
  values:
  [
    3
  ]
]