paleolimbot commented on code in PR #366: URL: https://github.com/apache/arrow-nanoarrow/pull/366#discussion_r1459714963
########## python/src/nanoarrow/schema.py: ########## @@ -0,0 +1,448 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import enum +from typing import Union + +from nanoarrow._lib import CArrowTimeUnit, CArrowType, CSchemaBuilder, CSchemaView +from nanoarrow.c_lib import c_schema + + +class Type(enum.Enum): + """The Type enumerator provides a means by which the various type + categories can be identified. Type values can be used in place of + :class:`Schema` instances in most places for parameter-free types.""" + + UNINITIALIZED = CArrowType.UNINITIALIZED + NA = CArrowType.NA + BOOL = CArrowType.BOOL + UINT8 = CArrowType.UINT8 + INT8 = CArrowType.INT8 + UINT16 = CArrowType.UINT16 + INT16 = CArrowType.INT16 + UINT32 = CArrowType.UINT32 + INT32 = CArrowType.INT32 + UINT64 = CArrowType.UINT64 + INT64 = CArrowType.INT64 + HALF_FLOAT = CArrowType.HALF_FLOAT + FLOAT = CArrowType.FLOAT + DOUBLE = CArrowType.DOUBLE + STRING = CArrowType.STRING + BINARY = CArrowType.BINARY + FIXED_SIZE_BINARY = CArrowType.FIXED_SIZE_BINARY + DATE32 = CArrowType.DATE32 + DATE64 = CArrowType.DATE64 + TIMESTAMP = CArrowType.TIMESTAMP + TIME32 = CArrowType.TIME32 + TIME64 = CArrowType.TIME64 + INTERVAL_MONTHS = CArrowType.INTERVAL_MONTHS + INTERVAL_DAY_TIME = CArrowType.INTERVAL_DAY_TIME + DECIMAL128 = CArrowType.DECIMAL128 + DECIMAL256 = CArrowType.DECIMAL256 + LIST = CArrowType.LIST + STRUCT = CArrowType.STRUCT + SPARSE_UNION = CArrowType.SPARSE_UNION + DENSE_UNION = CArrowType.DENSE_UNION + DICTIONARY = CArrowType.DICTIONARY + MAP = CArrowType.MAP + EXTENSION = CArrowType.EXTENSION + FIXED_SIZE_LIST = CArrowType.FIXED_SIZE_LIST + DURATION = CArrowType.DURATION + LARGE_STRING = CArrowType.LARGE_STRING + LARGE_BINARY = CArrowType.LARGE_BINARY + LARGE_LIST = CArrowType.LARGE_LIST + INTERVAL_MONTH_DAY_NANO = CArrowType.INTERVAL_MONTH_DAY_NANO + + def __arrow_c_schema__(self): + # This will only work for parameter-free types + c_schema = CSchemaBuilder.allocate().set_type(self.value).finish() + return c_schema._capsule + + +class TimeUnit(enum.Enum): + """Unit enumerator for timestamp, duration, and time types.""" + + SECOND = CArrowTimeUnit.SECOND + MILLI = CArrowTimeUnit.MILLI + MICRO = CArrowTimeUnit.MICRO + NANO = CArrowTimeUnit.NANO + + +class Schema: + """The Schema is nanoarrow's data type representation, encompasing the role + of PyArrow's ``Schema``, ``Field``, and ``DataType``. This scope maps to + that of the ArrowSchema in the Arrow C Data interface.""" + + def __init__( + self, + obj, + *, + nullable=None, + **params, + ) -> None: + """Create Schema objects Review Comment: I moved it to `nanoarrow.schema()`, since I'm envisioning that as the entry point for most people to construct one. I wish handling repetition in docstrings were a bit easier. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
