1# Licensed to the Apache Software Foundation (ASF) under one
2# or more contributor license agreements.  See the NOTICE file
3# distributed with this work for additional information
4# regarding copyright ownership.  The ASF licenses this file
5# to you under the Apache License, Version 2.0 (the
6# "License"); you may not use this file except in compliance
7# with the License.  You may obtain a copy of the License at
8#
9#   http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing,
12# software distributed under the License is distributed on an
13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14# KIND, either express or implied.  See the License for the
15# specific language governing permissions and limitations
16# under the License.
17
18# cython: profile=False
19# distutils: language = c++
20# cython: embedsignature = True
21
22import datetime
23import decimal as _pydecimal
24import json
25import numpy as np
26import os
27
28from pyarrow.compat import frombytes, tobytes, ordered_dict
29
30from cython.operator cimport dereference as deref
31from pyarrow.includes.libarrow cimport *
32from pyarrow.includes.common cimport PyObject_to_object
33cimport pyarrow.includes.libarrow as libarrow
34cimport cpython as cp
35
36# Initialize NumPy C API
37arrow_init_numpy()
38# Initialize PyArrow C++ API
39# (used from some of our C++ code, see e.g. ARROW-5260)
40import_pyarrow()
41set_numpy_nan(np.nan)
42
43
44def cpu_count():
45    """
46    Return the number of threads to use in parallel operations.
47
48    The number of threads is determined at startup by inspecting the
49    ``OMP_NUM_THREADS`` and ``OMP_THREAD_LIMIT`` environment variables.
50    If neither is present, it will default to the number of hardware threads
51    on the system. It can be modified at runtime by calling
52    :func:`set_cpu_count()`.
53    """
54    return GetCpuThreadPoolCapacity()
55
56
57def set_cpu_count(int count):
58    """
59    Set the number of threads to use in parallel operations.
60    """
61    if count < 1:
62        raise ValueError("CPU count must be strictly positive")
63    check_status(SetCpuThreadPoolCapacity(count))
64
65
66Type_NA = _Type_NA
67Type_BOOL = _Type_BOOL
68Type_UINT8 = _Type_UINT8
69Type_INT8 = _Type_INT8
70Type_UINT16 = _Type_UINT16
71Type_INT16 = _Type_INT16
72Type_UINT32 = _Type_UINT32
73Type_INT32 = _Type_INT32
74Type_UINT64 = _Type_UINT64
75Type_INT64 = _Type_INT64
76Type_HALF_FLOAT = _Type_HALF_FLOAT
77Type_FLOAT = _Type_FLOAT
78Type_DOUBLE = _Type_DOUBLE
79Type_DECIMAL = _Type_DECIMAL
80Type_DATE32 = _Type_DATE32
81Type_DATE64 = _Type_DATE64
82Type_TIMESTAMP = _Type_TIMESTAMP
83Type_TIME32 = _Type_TIME32
84Type_TIME64 = _Type_TIME64
85Type_DURATION = _Type_DURATION
86Type_BINARY = _Type_BINARY
87Type_STRING = _Type_STRING
88Type_LARGE_BINARY = _Type_LARGE_BINARY
89Type_LARGE_STRING = _Type_LARGE_STRING
90Type_FIXED_SIZE_BINARY = _Type_FIXED_SIZE_BINARY
91Type_LIST = _Type_LIST
92Type_LARGE_LIST = _Type_LARGE_LIST
93Type_MAP = _Type_MAP
94Type_FIXED_SIZE_LIST = _Type_FIXED_SIZE_LIST
95Type_STRUCT = _Type_STRUCT
96Type_UNION = _Type_UNION
97Type_DICTIONARY = _Type_DICTIONARY
98
99UnionMode_SPARSE = _UnionMode_SPARSE
100UnionMode_DENSE = _UnionMode_DENSE
101
102
103def _pc():
104    import pyarrow.compute as pc
105    return pc
106
107
108# pandas API shim
109include "pandas-shim.pxi"
110
111# Exception types
112include "error.pxi"
113
114# Memory pools and allocation
115include "memory.pxi"
116
117# DataType, Field, Schema
118include "types.pxi"
119
120# Array scalar values
121include "scalar.pxi"
122
123# Array types
124include "array.pxi"
125
126# Builders
127include "builder.pxi"
128
129# Column, Table, Record Batch
130include "table.pxi"
131
132# Tensors
133include "tensor.pxi"
134
135# File IO
136include "io.pxi"
137include "io-hdfs.pxi"
138
139# IPC / Messaging
140include "ipc.pxi"
141
142# Feather format
143include "feather.pxi"
144
145# Python serialization
146include "serialization.pxi"
147
148# Micro-benchmark routines
149include "benchmark.pxi"
150
151# Public API
152include "public-api.pxi"
153