forked from lance-format/lance
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.py
More file actions
32 lines (23 loc) · 756 Bytes
/
schema.py
File metadata and controls
32 lines (23 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright The Lance Authors
import json
from typing import Any, Dict
import pyarrow as pa
from .lance import LanceSchema as LanceSchema
from .lance import _json_to_schema, _schema_to_json
def schema_to_json(schema: pa.Schema) -> Dict[str, Any]:
"""
Converts a pyarrow schema to a JSON string.
Parameters
----------
"""
return json.loads(_schema_to_json(schema))
def json_to_schema(schema_json: Dict[str, Any]) -> pa.Schema:
"""
Converts a JSON string to a PyArrow schema.
Parameters
----------
schema_json: Dict[str, Any]
The JSON payload to convert to a PyArrow Schema.
"""
return _json_to_schema(json.dumps(schema_json))