Apache Arrow (C++)
A columnar in-memory analytics layer designed to accelerate big data.
numpy_convert.h
Go to the documentation of this file.
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 // Functions for converting between pandas's NumPy-based data representation
19 // and Arrow data structures
20 
21 #ifndef ARROW_PYTHON_NUMPY_CONVERT_H
22 #define ARROW_PYTHON_NUMPY_CONVERT_H
23 
24 #include "arrow/python/platform.h"
25 
26 #include <memory>
27 #include <string>
28 
29 #include "arrow/buffer.h"
30 #include "arrow/util/visibility.h"
31 
32 namespace arrow {
33 
34 class DataType;
35 class MemoryPool;
36 class Status;
37 class Tensor;
38 
39 namespace py {
40 
41 class ARROW_EXPORT NumPyBuffer : public Buffer {
42  public:
43  explicit NumPyBuffer(PyObject* arr);
44  virtual ~NumPyBuffer();
45 
46  private:
47  PyObject* arr_;
48 };
49 
50 // Handle misbehaved types like LONGLONG and ULONGLONG
51 ARROW_EXPORT
52 int cast_npy_type_compat(int type_num);
53 
54 ARROW_EXPORT
55 bool is_contiguous(PyObject* array);
56 
57 ARROW_EXPORT
58 Status NumPyDtypeToArrow(PyObject* dtype, std::shared_ptr<DataType>* out);
59 
60 Status GetTensorType(PyObject* dtype, std::shared_ptr<DataType>* out);
61 Status GetNumPyType(const DataType& type, int* type_num);
62 
63 ARROW_EXPORT Status NdarrayToTensor(MemoryPool* pool, PyObject* ao,
64  std::shared_ptr<Tensor>* out);
65 
66 ARROW_EXPORT Status TensorToNdarray(const Tensor& tensor, PyObject* base, PyObject** out);
67 
68 } // namespace py
69 } // namespace arrow
70 
71 #endif // ARROW_PYTHON_NUMPY_CONVERT_H
Definition: numpy_convert.h:41
Status GetNumPyType(const DataType &type, int *type_num)
Definition: tensor.h:53
Status NdarrayToTensor(MemoryPool *pool, PyObject *ao, std::shared_ptr< Tensor > *out)
Definition: status.h:106
int cast_npy_type_compat(int type_num)
bool is_contiguous(PyObject *array)
Status GetTensorType(PyObject *dtype, std::shared_ptr< DataType > *out)
Top-level namespace for Apache Arrow C++ API.
Definition: allocator.h:29
Status NumPyDtypeToArrow(PyObject *dtype, std::shared_ptr< DataType > *out)
Base class for memory allocation.
Definition: memory_pool.h:34
Immutable API for a chunk of bytes which may or may not be owned by the class instance.
Definition: buffer.h:48
Definition: type.h:150
Status TensorToNdarray(const Tensor &tensor, PyObject *base, PyObject **out)