applied-ai-018 commited on
Commit
9eff8f1
·
verified ·
1 Parent(s): 7a1cef4

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. ckpts/universal/global_step80/zero/21.attention.dense.weight/fp32.pt +3 -0
  2. ckpts/universal/global_step80/zero/23.attention.query_key_value.weight/exp_avg_sq.pt +3 -0
  3. venv/lib/python3.10/site-packages/pyarrow/include/arrow/adapters/orc/adapter.h +323 -0
  4. venv/lib/python3.10/site-packages/pyarrow/include/arrow/adapters/orc/options.h +120 -0
  5. venv/lib/python3.10/site-packages/pyarrow/include/arrow/adapters/tensorflow/convert.h +128 -0
  6. venv/lib/python3.10/site-packages/pyarrow/include/arrow/flight/client.h +436 -0
  7. venv/lib/python3.10/site-packages/pyarrow/include/arrow/flight/client_auth.h +62 -0
  8. venv/lib/python3.10/site-packages/pyarrow/include/arrow/flight/client_tracing_middleware.h +34 -0
  9. venv/lib/python3.10/site-packages/pyarrow/include/arrow/flight/pch.h +26 -0
  10. venv/lib/python3.10/site-packages/pyarrow/include/arrow/flight/platform.h +31 -0
  11. venv/lib/python3.10/site-packages/pyarrow/include/arrow/flight/server_auth.h +125 -0
  12. venv/lib/python3.10/site-packages/pyarrow/include/arrow/flight/server_middleware.h +105 -0
  13. venv/lib/python3.10/site-packages/pyarrow/include/arrow/flight/server_tracing_middleware.h +68 -0
  14. venv/lib/python3.10/site-packages/pyarrow/include/arrow/flight/test_util.h +264 -0
  15. venv/lib/python3.10/site-packages/pyarrow/include/arrow/flight/transport_server.h +133 -0
  16. venv/lib/python3.10/site-packages/pyarrow/include/arrow/flight/type_fwd.h +65 -0
  17. venv/lib/python3.10/site-packages/pyarrow/include/arrow/flight/visibility.h +48 -0
  18. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/api.h +30 -0
  19. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/arrow_to_pandas.h +146 -0
  20. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/async.h +60 -0
  21. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/benchmark.h +36 -0
  22. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/common.h +458 -0
  23. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/csv.h +42 -0
  24. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/datetime.h +231 -0
  25. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/decimal.h +128 -0
  26. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/deserialize.h +106 -0
  27. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/extension_type.h +85 -0
  28. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/filesystem.h +130 -0
  29. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/flight.h +350 -0
  30. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/gdb.h +29 -0
  31. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/helpers.h +159 -0
  32. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/inference.h +64 -0
  33. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/init.h +26 -0
  34. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/io.h +121 -0
  35. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/ipc.h +72 -0
  36. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/iterators.h +194 -0
  37. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/lib.h +83 -0
  38. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/lib_api.h +201 -0
  39. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/numpy_convert.h +122 -0
  40. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/numpy_interop.h +103 -0
  41. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/numpy_to_arrow.h +72 -0
  42. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/parquet_encryption.h +132 -0
  43. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/pch.h +24 -0
  44. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/platform.h +41 -0
  45. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/pyarrow.h +89 -0
  46. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/pyarrow_api.h +19 -0
  47. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/pyarrow_lib.h +19 -0
  48. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/python_test.h +42 -0
  49. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/python_to_arrow.h +80 -0
  50. venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/serialize.h +145 -0
ckpts/universal/global_step80/zero/21.attention.dense.weight/fp32.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:27f5af4eed6bfb1246378654bfd1efb455cf5fe6fe2fe2bc137f9b9ded569a45
3
+ size 16778317
ckpts/universal/global_step80/zero/23.attention.query_key_value.weight/exp_avg_sq.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e802d89a5be62321a3558a50151f10ca716555914e04d4b31e001db4ec0ae311
3
+ size 50332843
venv/lib/python3.10/site-packages/pyarrow/include/arrow/adapters/orc/adapter.h ADDED
@@ -0,0 +1,323 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include <cstdint>
21
+ #include <memory>
22
+ #include <vector>
23
+
24
+ #include "arrow/adapters/orc/options.h"
25
+ #include "arrow/io/interfaces.h"
26
+ #include "arrow/memory_pool.h"
27
+ #include "arrow/record_batch.h"
28
+ #include "arrow/status.h"
29
+ #include "arrow/type.h"
30
+ #include "arrow/type_fwd.h"
31
+ #include "arrow/util/macros.h"
32
+ #include "arrow/util/visibility.h"
33
+
34
+ namespace arrow {
35
+ namespace adapters {
36
+ namespace orc {
37
+
38
+ /// \brief Information about an ORC stripe
39
+ struct StripeInformation {
40
+ /// \brief Offset of the stripe from the start of the file, in bytes
41
+ int64_t offset;
42
+ /// \brief Length of the stripe, in bytes
43
+ int64_t length;
44
+ /// \brief Number of rows in the stripe
45
+ int64_t num_rows;
46
+ /// \brief Index of the first row of the stripe
47
+ int64_t first_row_id;
48
+ };
49
+
50
+ /// \class ORCFileReader
51
+ /// \brief Read an Arrow Table or RecordBatch from an ORC file.
52
+ class ARROW_EXPORT ORCFileReader {
53
+ public:
54
+ ~ORCFileReader();
55
+
56
+ /// \brief Creates a new ORC reader
57
+ ///
58
+ /// \param[in] file the data source
59
+ /// \param[in] pool a MemoryPool to use for buffer allocations
60
+ /// \return the returned reader object
61
+ static Result<std::unique_ptr<ORCFileReader>> Open(
62
+ const std::shared_ptr<io::RandomAccessFile>& file, MemoryPool* pool);
63
+
64
+ /// \brief Return the schema read from the ORC file
65
+ ///
66
+ /// \return the returned Schema object
67
+ Result<std::shared_ptr<Schema>> ReadSchema();
68
+
69
+ /// \brief Read the file as a Table
70
+ ///
71
+ /// The table will be composed of one record batch per stripe.
72
+ ///
73
+ /// \return the returned Table
74
+ Result<std::shared_ptr<Table>> Read();
75
+
76
+ /// \brief Read the file as a Table
77
+ ///
78
+ /// The table will be composed of one record batch per stripe.
79
+ ///
80
+ /// \param[in] schema the Table schema
81
+ /// \return the returned Table
82
+ Result<std::shared_ptr<Table>> Read(const std::shared_ptr<Schema>& schema);
83
+
84
+ /// \brief Read the file as a Table
85
+ ///
86
+ /// The table will be composed of one record batch per stripe.
87
+ ///
88
+ /// \param[in] include_indices the selected field indices to read
89
+ /// \return the returned Table
90
+ Result<std::shared_ptr<Table>> Read(const std::vector<int>& include_indices);
91
+
92
+ /// \brief Read the file as a Table
93
+ ///
94
+ /// The table will be composed of one record batch per stripe.
95
+ ///
96
+ /// \param[in] include_names the selected field names to read
97
+ /// \return the returned Table
98
+ Result<std::shared_ptr<Table>> Read(const std::vector<std::string>& include_names);
99
+
100
+ /// \brief Read the file as a Table
101
+ ///
102
+ /// The table will be composed of one record batch per stripe.
103
+ ///
104
+ /// \param[in] schema the Table schema
105
+ /// \param[in] include_indices the selected field indices to read
106
+ /// \return the returned Table
107
+ Result<std::shared_ptr<Table>> Read(const std::shared_ptr<Schema>& schema,
108
+ const std::vector<int>& include_indices);
109
+
110
+ /// \brief Read a single stripe as a RecordBatch
111
+ ///
112
+ /// \param[in] stripe the stripe index
113
+ /// \return the returned RecordBatch
114
+ Result<std::shared_ptr<RecordBatch>> ReadStripe(int64_t stripe);
115
+
116
+ /// \brief Read a single stripe as a RecordBatch
117
+ ///
118
+ /// \param[in] stripe the stripe index
119
+ /// \param[in] include_indices the selected field indices to read
120
+ /// \return the returned RecordBatch
121
+ Result<std::shared_ptr<RecordBatch>> ReadStripe(
122
+ int64_t stripe, const std::vector<int>& include_indices);
123
+
124
+ /// \brief Read a single stripe as a RecordBatch
125
+ ///
126
+ /// \param[in] stripe the stripe index
127
+ /// \param[in] include_names the selected field names to read
128
+ /// \return the returned RecordBatch
129
+ Result<std::shared_ptr<RecordBatch>> ReadStripe(
130
+ int64_t stripe, const std::vector<std::string>& include_names);
131
+
132
+ /// \brief Seek to designated row. Invoke NextStripeReader() after seek
133
+ /// will return stripe reader starting from designated row.
134
+ ///
135
+ /// \param[in] row_number the rows number to seek
136
+ Status Seek(int64_t row_number);
137
+
138
+ /// \brief Get a stripe level record batch iterator.
139
+ ///
140
+ /// Each record batch will have up to `batch_size` rows.
141
+ /// NextStripeReader serves as a fine-grained alternative to ReadStripe
142
+ /// which may cause OOM issues by loading the whole stripe into memory.
143
+ ///
144
+ /// Note this will only read rows for the current stripe, not the entire
145
+ /// file.
146
+ ///
147
+ /// \param[in] batch_size the maximum number of rows in each record batch
148
+ /// \return the returned stripe reader
149
+ Result<std::shared_ptr<RecordBatchReader>> NextStripeReader(int64_t batch_size);
150
+
151
+ /// \brief Get a stripe level record batch iterator.
152
+ ///
153
+ /// Each record batch will have up to `batch_size` rows.
154
+ /// NextStripeReader serves as a fine-grained alternative to ReadStripe
155
+ /// which may cause OOM issues by loading the whole stripe into memory.
156
+ ///
157
+ /// Note this will only read rows for the current stripe, not the entire
158
+ /// file.
159
+ ///
160
+ /// \param[in] batch_size the maximum number of rows in each record batch
161
+ /// \param[in] include_indices the selected field indices to read
162
+ /// \return the stripe reader
163
+ Result<std::shared_ptr<RecordBatchReader>> NextStripeReader(
164
+ int64_t batch_size, const std::vector<int>& include_indices);
165
+
166
+ /// \brief Get a record batch iterator for the entire file.
167
+ ///
168
+ /// Each record batch will have up to `batch_size` rows.
169
+ ///
170
+ /// \param[in] batch_size the maximum number of rows in each record batch
171
+ /// \param[in] include_names the selected field names to read, if not empty
172
+ /// (otherwise all fields are read)
173
+ /// \return the record batch iterator
174
+ Result<std::shared_ptr<RecordBatchReader>> GetRecordBatchReader(
175
+ int64_t batch_size, const std::vector<std::string>& include_names);
176
+
177
+ /// \brief The number of stripes in the file
178
+ int64_t NumberOfStripes();
179
+
180
+ /// \brief The number of rows in the file
181
+ int64_t NumberOfRows();
182
+
183
+ /// \brief StripeInformation for each stripe.
184
+ StripeInformation GetStripeInformation(int64_t stripe);
185
+
186
+ /// \brief Get the format version of the file.
187
+ /// Currently known values are 0.11 and 0.12.
188
+ ///
189
+ /// \return The FileVersion of the ORC file.
190
+ FileVersion GetFileVersion();
191
+
192
+ /// \brief Get the software instance and version that wrote this file.
193
+ ///
194
+ /// \return a user-facing string that specifies the software version
195
+ std::string GetSoftwareVersion();
196
+
197
+ /// \brief Get the compression kind of the file.
198
+ ///
199
+ /// \return The kind of compression in the ORC file.
200
+ Result<Compression::type> GetCompression();
201
+
202
+ /// \brief Get the buffer size for the compression.
203
+ ///
204
+ /// \return Number of bytes to buffer for the compression codec.
205
+ int64_t GetCompressionSize();
206
+
207
+ /// \brief Get the number of rows per an entry in the row index.
208
+ /// \return the number of rows per an entry in the row index or 0 if there
209
+ /// is no row index.
210
+ int64_t GetRowIndexStride();
211
+
212
+ /// \brief Get ID of writer that generated the file.
213
+ ///
214
+ /// \return UNKNOWN_WRITER if the writer ID is undefined
215
+ WriterId GetWriterId();
216
+
217
+ /// \brief Get the writer id value when getWriterId() returns an unknown writer.
218
+ ///
219
+ /// \return the integer value of the writer ID.
220
+ int32_t GetWriterIdValue();
221
+
222
+ /// \brief Get the version of the writer.
223
+ ///
224
+ /// \return the version of the writer.
225
+
226
+ WriterVersion GetWriterVersion();
227
+
228
+ /// \brief Get the number of stripe statistics in the file.
229
+ ///
230
+ /// \return the number of stripe statistics
231
+ int64_t GetNumberOfStripeStatistics();
232
+
233
+ /// \brief Get the length of the data stripes in the file.
234
+ ///
235
+ /// \return return the number of bytes in stripes
236
+ int64_t GetContentLength();
237
+
238
+ /// \brief Get the length of the file stripe statistics.
239
+ ///
240
+ /// \return the number of compressed bytes in the file stripe statistics
241
+ int64_t GetStripeStatisticsLength();
242
+
243
+ /// \brief Get the length of the file footer.
244
+ ///
245
+ /// \return the number of compressed bytes in the file footer
246
+ int64_t GetFileFooterLength();
247
+
248
+ /// \brief Get the length of the file postscript.
249
+ ///
250
+ /// \return the number of bytes in the file postscript
251
+ int64_t GetFilePostscriptLength();
252
+
253
+ /// \brief Get the total length of the file.
254
+ ///
255
+ /// \return the number of bytes in the file
256
+ int64_t GetFileLength();
257
+
258
+ /// \brief Get the serialized file tail.
259
+ /// Useful if another reader of the same file wants to avoid re-reading
260
+ /// the file tail. See ReadOptions.SetSerializedFileTail().
261
+ ///
262
+ /// \return a string of bytes with the file tail
263
+ std::string GetSerializedFileTail();
264
+
265
+ /// \brief Return the metadata read from the ORC file
266
+ ///
267
+ /// \return A KeyValueMetadata object containing the ORC metadata
268
+ Result<std::shared_ptr<const KeyValueMetadata>> ReadMetadata();
269
+
270
+ private:
271
+ class Impl;
272
+ std::unique_ptr<Impl> impl_;
273
+ ORCFileReader();
274
+ };
275
+
276
+ /// \class ORCFileWriter
277
+ /// \brief Write an Arrow Table or RecordBatch to an ORC file.
278
+ class ARROW_EXPORT ORCFileWriter {
279
+ public:
280
+ ~ORCFileWriter();
281
+ /// \brief Creates a new ORC writer.
282
+ ///
283
+ /// \param[in] output_stream a pointer to the io::OutputStream to write into
284
+ /// \param[in] write_options the ORC writer options for Arrow
285
+ /// \return the returned writer object
286
+ static Result<std::unique_ptr<ORCFileWriter>> Open(
287
+ io::OutputStream* output_stream,
288
+ const WriteOptions& write_options = WriteOptions());
289
+
290
+ /// \brief Write a table. This can be called multiple times.
291
+ ///
292
+ /// Tables passed in subsequent calls must match the schema of the table that was
293
+ /// written first.
294
+ ///
295
+ /// \param[in] table the Arrow table from which data is extracted.
296
+ /// \return Status
297
+ Status Write(const Table& table);
298
+
299
+ /// \brief Write a RecordBatch. This can be called multiple times.
300
+ ///
301
+ /// RecordBatches passed in subsequent calls must match the schema of the
302
+ /// RecordBatch that was written first.
303
+ ///
304
+ /// \param[in] record_batch the Arrow RecordBatch from which data is extracted.
305
+ /// \return Status
306
+ Status Write(const RecordBatch& record_batch);
307
+
308
+ /// \brief Close an ORC writer (orc::Writer)
309
+ ///
310
+ /// \return Status
311
+ Status Close();
312
+
313
+ private:
314
+ class Impl;
315
+ std::unique_ptr<Impl> impl_;
316
+
317
+ private:
318
+ ORCFileWriter();
319
+ };
320
+
321
+ } // namespace orc
322
+ } // namespace adapters
323
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/adapters/orc/options.h ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include <vector>
21
+
22
+ #include "arrow/io/interfaces.h"
23
+ #include "arrow/status.h"
24
+ #include "arrow/util/type_fwd.h"
25
+ #include "arrow/util/visibility.h"
26
+
27
+ namespace arrow {
28
+
29
+ namespace adapters {
30
+
31
+ namespace orc {
32
+
33
+ enum class WriterId : int32_t {
34
+ kOrcJava = 0,
35
+ kOrcCpp = 1,
36
+ kPresto = 2,
37
+ kScritchleyGo = 3,
38
+ kTrino = 4,
39
+ kUnknown = INT32_MAX
40
+ };
41
+
42
+ enum class WriterVersion : int32_t {
43
+ kOriginal = 0,
44
+ kHive8732 = 1,
45
+ kHive4243 = 2,
46
+ kHive12055 = 3,
47
+ kHive13083 = 4,
48
+ kOrc101 = 5,
49
+ kOrc135 = 6,
50
+ kOrc517 = 7,
51
+ kOrc203 = 8,
52
+ kOrc14 = 9,
53
+ kMax = INT32_MAX
54
+ };
55
+
56
+ enum class CompressionStrategy : int32_t { kSpeed = 0, kCompression };
57
+
58
+ class ARROW_EXPORT FileVersion {
59
+ private:
60
+ int32_t major_version_;
61
+ int32_t minor_version_;
62
+
63
+ public:
64
+ static const FileVersion& v_0_11();
65
+ static const FileVersion& v_0_12();
66
+
67
+ FileVersion(int32_t major, int32_t minor)
68
+ : major_version_(major), minor_version_(minor) {}
69
+
70
+ /**
71
+ * Get major version
72
+ */
73
+ int32_t major_version() const { return this->major_version_; }
74
+
75
+ /**
76
+ * Get minor version
77
+ */
78
+ int32_t minor_version() const { return this->minor_version_; }
79
+
80
+ bool operator==(const FileVersion& right) const {
81
+ return this->major_version() == right.major_version() &&
82
+ this->minor_version() == right.minor_version();
83
+ }
84
+
85
+ bool operator!=(const FileVersion& right) const { return !(*this == right); }
86
+
87
+ std::string ToString() const;
88
+ };
89
+
90
+ /// Options for the ORC Writer
91
+ struct ARROW_EXPORT WriteOptions {
92
+ /// Number of rows the ORC writer writes at a time, default 1024
93
+ int64_t batch_size = 1024;
94
+ /// Which ORC file version to use, default FileVersion(0, 12)
95
+ FileVersion file_version = FileVersion(0, 12);
96
+ /// Size of each ORC stripe in bytes, default 64 MiB
97
+ int64_t stripe_size = 64 * 1024 * 1024;
98
+ /// The compression codec of the ORC file, there is no compression by default
99
+ Compression::type compression = Compression::UNCOMPRESSED;
100
+ /// The size of each compression block in bytes, default 64 KiB
101
+ int64_t compression_block_size = 64 * 1024;
102
+ /// The compression strategy i.e. speed vs size reduction, default
103
+ /// CompressionStrategy::kSpeed
104
+ CompressionStrategy compression_strategy = CompressionStrategy::kSpeed;
105
+ /// The number of rows per an entry in the row index, default 10000
106
+ int64_t row_index_stride = 10000;
107
+ /// The padding tolerance, default 0.0
108
+ double padding_tolerance = 0.0;
109
+ /// The dictionary key size threshold. 0 to disable dictionary encoding.
110
+ /// 1 to always enable dictionary encoding, default 0.0
111
+ double dictionary_key_size_threshold = 0.0;
112
+ /// The array of columns that use the bloom filter, default empty
113
+ std::vector<int64_t> bloom_filter_columns;
114
+ /// The upper limit of the false-positive rate of the bloom filter, default 0.05
115
+ double bloom_filter_fpp = 0.05;
116
+ };
117
+
118
+ } // namespace orc
119
+ } // namespace adapters
120
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/adapters/tensorflow/convert.h ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include <memory>
21
+
22
+ #include "tensorflow/core/framework/op.h"
23
+
24
+ #include "arrow/type.h"
25
+
26
+ // These utilities are supposed to be included in TensorFlow operators
27
+ // that need to be compiled separately from Arrow because of ABI issues.
28
+ // They therefore need to be header-only.
29
+
30
+ namespace arrow {
31
+
32
+ namespace adapters {
33
+
34
+ namespace tensorflow {
35
+
36
+ Status GetArrowType(::tensorflow::DataType dtype, std::shared_ptr<DataType>* out) {
37
+ switch (dtype) {
38
+ case ::tensorflow::DT_BOOL:
39
+ *out = arrow::boolean();
40
+ break;
41
+ case ::tensorflow::DT_FLOAT:
42
+ *out = arrow::float32();
43
+ break;
44
+ case ::tensorflow::DT_DOUBLE:
45
+ *out = arrow::float64();
46
+ break;
47
+ case ::tensorflow::DT_HALF:
48
+ *out = arrow::float16();
49
+ break;
50
+ case ::tensorflow::DT_INT8:
51
+ *out = arrow::int8();
52
+ break;
53
+ case ::tensorflow::DT_INT16:
54
+ *out = arrow::int16();
55
+ break;
56
+ case ::tensorflow::DT_INT32:
57
+ *out = arrow::int32();
58
+ break;
59
+ case ::tensorflow::DT_INT64:
60
+ *out = arrow::int64();
61
+ break;
62
+ case ::tensorflow::DT_UINT8:
63
+ *out = arrow::uint8();
64
+ break;
65
+ case ::tensorflow::DT_UINT16:
66
+ *out = arrow::uint16();
67
+ break;
68
+ case ::tensorflow::DT_UINT32:
69
+ *out = arrow::uint32();
70
+ break;
71
+ case ::tensorflow::DT_UINT64:
72
+ *out = arrow::uint64();
73
+ break;
74
+ default:
75
+ return Status::TypeError("TensorFlow data type is not supported");
76
+ }
77
+ return Status::OK();
78
+ }
79
+
80
+ Status GetTensorFlowType(std::shared_ptr<DataType> dtype, ::tensorflow::DataType* out) {
81
+ switch (dtype->id()) {
82
+ case Type::BOOL:
83
+ *out = ::tensorflow::DT_BOOL;
84
+ break;
85
+ case Type::UINT8:
86
+ *out = ::tensorflow::DT_UINT8;
87
+ break;
88
+ case Type::INT8:
89
+ *out = ::tensorflow::DT_INT8;
90
+ break;
91
+ case Type::UINT16:
92
+ *out = ::tensorflow::DT_UINT16;
93
+ break;
94
+ case Type::INT16:
95
+ *out = ::tensorflow::DT_INT16;
96
+ break;
97
+ case Type::UINT32:
98
+ *out = ::tensorflow::DT_UINT32;
99
+ break;
100
+ case Type::INT32:
101
+ *out = ::tensorflow::DT_INT32;
102
+ break;
103
+ case Type::UINT64:
104
+ *out = ::tensorflow::DT_UINT64;
105
+ break;
106
+ case Type::INT64:
107
+ *out = ::tensorflow::DT_INT64;
108
+ break;
109
+ case Type::HALF_FLOAT:
110
+ *out = ::tensorflow::DT_HALF;
111
+ break;
112
+ case Type::FLOAT:
113
+ *out = ::tensorflow::DT_FLOAT;
114
+ break;
115
+ case Type::DOUBLE:
116
+ *out = ::tensorflow::DT_DOUBLE;
117
+ break;
118
+ default:
119
+ return Status::TypeError("Arrow data type is not supported");
120
+ }
121
+ return arrow::Status::OK();
122
+ }
123
+
124
+ } // namespace tensorflow
125
+
126
+ } // namespace adapters
127
+
128
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/flight/client.h ADDED
@@ -0,0 +1,436 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ /// \brief Implementation of Flight RPC client. API should be
19
+ /// considered experimental for now
20
+
21
+ #pragma once
22
+
23
+ #include <chrono>
24
+ #include <memory>
25
+ #include <string>
26
+ #include <utility>
27
+ #include <variant>
28
+ #include <vector>
29
+
30
+ #include "arrow/ipc/options.h"
31
+ #include "arrow/ipc/reader.h"
32
+ #include "arrow/ipc/writer.h"
33
+ #include "arrow/result.h"
34
+ #include "arrow/status.h"
35
+ #include "arrow/util/cancel.h"
36
+
37
+ #include "arrow/flight/type_fwd.h"
38
+ #include "arrow/flight/types.h" // IWYU pragma: keep
39
+ #include "arrow/flight/visibility.h"
40
+
41
+ namespace arrow {
42
+
43
+ class RecordBatch;
44
+ class Schema;
45
+
46
+ namespace flight {
47
+
48
+ /// \brief A duration type for Flight call timeouts.
49
+ typedef std::chrono::duration<double, std::chrono::seconds::period> TimeoutDuration;
50
+
51
+ /// \brief Hints to the underlying RPC layer for Arrow Flight calls.
52
+ class ARROW_FLIGHT_EXPORT FlightCallOptions {
53
+ public:
54
+ /// Create a default set of call options.
55
+ FlightCallOptions();
56
+
57
+ /// \brief An optional timeout for this call. Negative durations
58
+ /// mean an implementation-defined default behavior will be used
59
+ /// instead. This is the default value.
60
+ TimeoutDuration timeout;
61
+
62
+ /// \brief IPC reader options, if applicable for the call.
63
+ ipc::IpcReadOptions read_options;
64
+
65
+ /// \brief IPC writer options, if applicable for the call.
66
+ ipc::IpcWriteOptions write_options;
67
+
68
+ /// \brief Headers for client to add to context.
69
+ std::vector<std::pair<std::string, std::string>> headers;
70
+
71
+ /// \brief A token to enable interactive user cancellation of long-running requests.
72
+ StopToken stop_token;
73
+
74
+ /// \brief An optional memory manager to control where to allocate incoming data.
75
+ std::shared_ptr<MemoryManager> memory_manager;
76
+ };
77
+
78
+ /// \brief Indicate that the client attempted to write a message
79
+ /// larger than the soft limit set via write_size_limit_bytes.
80
+ class ARROW_FLIGHT_EXPORT FlightWriteSizeStatusDetail : public arrow::StatusDetail {
81
+ public:
82
+ explicit FlightWriteSizeStatusDetail(int64_t limit, int64_t actual)
83
+ : limit_(limit), actual_(actual) {}
84
+ const char* type_id() const override;
85
+ std::string ToString() const override;
86
+ int64_t limit() const { return limit_; }
87
+ int64_t actual() const { return actual_; }
88
+
89
+ /// \brief Extract this status detail from a status, or return
90
+ /// nullptr if the status doesn't contain this status detail.
91
+ static std::shared_ptr<FlightWriteSizeStatusDetail> UnwrapStatus(
92
+ const arrow::Status& status);
93
+
94
+ private:
95
+ int64_t limit_;
96
+ int64_t actual_;
97
+ };
98
+
99
+ struct ARROW_FLIGHT_EXPORT FlightClientOptions {
100
+ /// \brief Root certificates to use for validating server
101
+ /// certificates.
102
+ std::string tls_root_certs;
103
+ /// \brief Override the hostname checked by TLS. Use with caution.
104
+ std::string override_hostname;
105
+ /// \brief The client certificate to use if using Mutual TLS
106
+ std::string cert_chain;
107
+ /// \brief The private key associated with the client certificate for Mutual TLS
108
+ std::string private_key;
109
+ /// \brief A list of client middleware to apply.
110
+ std::vector<std::shared_ptr<ClientMiddlewareFactory>> middleware;
111
+ /// \brief A soft limit on the number of bytes to write in a single
112
+ /// batch when sending Arrow data to a server.
113
+ ///
114
+ /// Used to help limit server memory consumption. Only enabled if
115
+ /// positive. When enabled, FlightStreamWriter.Write* may yield a
116
+ /// IOError with error detail FlightWriteSizeStatusDetail.
117
+ int64_t write_size_limit_bytes = 0;
118
+
119
+ /// \brief Generic connection options, passed to the underlying
120
+ /// transport; interpretation is implementation-dependent.
121
+ std::vector<std::pair<std::string, std::variant<int, std::string>>> generic_options;
122
+
123
+ /// \brief Use TLS without validating the server certificate. Use with caution.
124
+ bool disable_server_verification = false;
125
+
126
+ /// \brief Get default options.
127
+ static FlightClientOptions Defaults();
128
+ };
129
+
130
+ /// \brief A RecordBatchReader exposing Flight metadata and cancel
131
+ /// operations.
132
+ class ARROW_FLIGHT_EXPORT FlightStreamReader : public MetadataRecordBatchReader {
133
+ public:
134
+ /// \brief Try to cancel the call.
135
+ virtual void Cancel() = 0;
136
+
137
+ using MetadataRecordBatchReader::ToRecordBatches;
138
+ /// \brief Consume entire stream as a vector of record batches
139
+ virtual arrow::Result<std::vector<std::shared_ptr<RecordBatch>>> ToRecordBatches(
140
+ const StopToken& stop_token) = 0;
141
+
142
+ using MetadataRecordBatchReader::ToTable;
143
+ /// \brief Consume entire stream as a Table
144
+ arrow::Result<std::shared_ptr<Table>> ToTable(const StopToken& stop_token);
145
+ };
146
+
147
+ // Silence warning
148
+ // "non dll-interface class RecordBatchReader used as base for dll-interface class"
149
+ #ifdef _MSC_VER
150
+ #pragma warning(push)
151
+ #pragma warning(disable : 4275)
152
+ #endif
153
+
154
+ /// \brief A RecordBatchWriter that also allows sending
155
+ /// application-defined metadata via the Flight protocol.
156
+ class ARROW_FLIGHT_EXPORT FlightStreamWriter : public MetadataRecordBatchWriter {
157
+ public:
158
+ /// \brief Indicate that the application is done writing to this stream.
159
+ ///
160
+ /// The application may not write to this stream after calling
161
+ /// this. This differs from closing the stream because this writer
162
+ /// may represent only one half of a readable and writable stream.
163
+ virtual Status DoneWriting() = 0;
164
+ };
165
+
166
+ #ifdef _MSC_VER
167
+ #pragma warning(pop)
168
+ #endif
169
+
170
+ /// \brief A reader for application-specific metadata sent back to the
171
+ /// client during an upload.
172
+ class ARROW_FLIGHT_EXPORT FlightMetadataReader {
173
+ public:
174
+ virtual ~FlightMetadataReader();
175
+ /// \brief Read a message from the server.
176
+ virtual Status ReadMetadata(std::shared_ptr<Buffer>* out) = 0;
177
+ };
178
+
179
+ /// \brief Client class for Arrow Flight RPC services.
180
+ /// API experimental for now
181
+ class ARROW_FLIGHT_EXPORT FlightClient {
182
+ public:
183
+ ~FlightClient();
184
+
185
+ /// \brief Connect to an unauthenticated flight service
186
+ /// \param[in] location the URI
187
+ /// \return Arrow result with the created FlightClient, OK status may not indicate that
188
+ /// the connection was successful
189
+ static arrow::Result<std::unique_ptr<FlightClient>> Connect(const Location& location);
190
+
191
+ /// \brief Connect to an unauthenticated flight service
192
+ /// \param[in] location the URI
193
+ /// \param[in] options Other options for setting up the client
194
+ /// \return Arrow result with the created FlightClient, OK status may not indicate that
195
+ /// the connection was successful
196
+ static arrow::Result<std::unique_ptr<FlightClient>> Connect(
197
+ const Location& location, const FlightClientOptions& options);
198
+
199
+ /// \brief Authenticate to the server using the given handler.
200
+ /// \param[in] options Per-RPC options
201
+ /// \param[in] auth_handler The authentication mechanism to use
202
+ /// \return Status OK if the client authenticated successfully
203
+ Status Authenticate(const FlightCallOptions& options,
204
+ std::unique_ptr<ClientAuthHandler> auth_handler);
205
+
206
+ /// \brief Authenticate to the server using basic HTTP style authentication.
207
+ /// \param[in] options Per-RPC options
208
+ /// \param[in] username Username to use
209
+ /// \param[in] password Password to use
210
+ /// \return Arrow result with bearer token and status OK if client authenticated
211
+ /// successfully
212
+ arrow::Result<std::pair<std::string, std::string>> AuthenticateBasicToken(
213
+ const FlightCallOptions& options, const std::string& username,
214
+ const std::string& password);
215
+
216
+ /// \brief Perform the indicated action, returning an iterator to the stream
217
+ /// of results, if any
218
+ /// \param[in] options Per-RPC options
219
+ /// \param[in] action the action to be performed
220
+ /// \return Arrow result with an iterator object for reading the returned results
221
+ arrow::Result<std::unique_ptr<ResultStream>> DoAction(const FlightCallOptions& options,
222
+ const Action& action);
223
+ arrow::Result<std::unique_ptr<ResultStream>> DoAction(const Action& action) {
224
+ return DoAction({}, action);
225
+ }
226
+
227
+ /// \brief Perform the CancelFlightInfo action, returning a
228
+ /// CancelFlightInfoResult
229
+ ///
230
+ /// \param[in] options Per-RPC options
231
+ /// \param[in] request The CancelFlightInfoRequest
232
+ /// \return Arrow result with a CancelFlightInfoResult
233
+ arrow::Result<CancelFlightInfoResult> CancelFlightInfo(
234
+ const FlightCallOptions& options, const CancelFlightInfoRequest& request);
235
+ arrow::Result<CancelFlightInfoResult> CancelFlightInfo(
236
+ const CancelFlightInfoRequest& request) {
237
+ return CancelFlightInfo({}, request);
238
+ }
239
+
240
+ /// \brief Perform the RenewFlightEndpoint action, returning a renewed
241
+ /// FlightEndpoint
242
+ ///
243
+ /// \param[in] options Per-RPC options
244
+ /// \param[in] request The RenewFlightEndpointRequest
245
+ /// \return Arrow result with a renewed FlightEndpoint
246
+ arrow::Result<FlightEndpoint> RenewFlightEndpoint(
247
+ const FlightCallOptions& options, const RenewFlightEndpointRequest& request);
248
+ arrow::Result<FlightEndpoint> RenewFlightEndpoint(
249
+ const RenewFlightEndpointRequest& request) {
250
+ return RenewFlightEndpoint({}, request);
251
+ }
252
+
253
+ /// \brief Retrieve a list of available Action types
254
+ /// \param[in] options Per-RPC options
255
+ /// \return Arrow result with the available actions
256
+ arrow::Result<std::vector<ActionType>> ListActions(const FlightCallOptions& options);
257
+ arrow::Result<std::vector<ActionType>> ListActions() {
258
+ return ListActions(FlightCallOptions());
259
+ }
260
+
261
+ /// \brief Request access plan for a single flight, which may be an existing
262
+ /// dataset or a command to be executed
263
+ /// \param[in] options Per-RPC options
264
+ /// \param[in] descriptor the dataset request, whether a named dataset or
265
+ /// command
266
+ /// \return Arrow result with the FlightInfo describing where to access the dataset
267
+ arrow::Result<std::unique_ptr<FlightInfo>> GetFlightInfo(
268
+ const FlightCallOptions& options, const FlightDescriptor& descriptor);
269
+ arrow::Result<std::unique_ptr<FlightInfo>> GetFlightInfo(
270
+ const FlightDescriptor& descriptor) {
271
+ return GetFlightInfo({}, descriptor);
272
+ }
273
+
274
+ /// \brief Asynchronous GetFlightInfo.
275
+ /// \param[in] options Per-RPC options
276
+ /// \param[in] descriptor the dataset request
277
+ /// \param[in] listener Callbacks for response and RPC completion
278
+ ///
279
+ /// This API is EXPERIMENTAL.
280
+ void GetFlightInfoAsync(const FlightCallOptions& options,
281
+ const FlightDescriptor& descriptor,
282
+ std::shared_ptr<AsyncListener<FlightInfo>> listener);
283
+ void GetFlightInfoAsync(const FlightDescriptor& descriptor,
284
+ std::shared_ptr<AsyncListener<FlightInfo>> listener) {
285
+ return GetFlightInfoAsync({}, descriptor, std::move(listener));
286
+ }
287
+
288
+ /// \brief Asynchronous GetFlightInfo returning a Future.
289
+ /// \param[in] options Per-RPC options
290
+ /// \param[in] descriptor the dataset request
291
+ ///
292
+ /// This API is EXPERIMENTAL.
293
+ arrow::Future<FlightInfo> GetFlightInfoAsync(const FlightCallOptions& options,
294
+ const FlightDescriptor& descriptor);
295
+ arrow::Future<FlightInfo> GetFlightInfoAsync(const FlightDescriptor& descriptor) {
296
+ return GetFlightInfoAsync({}, descriptor);
297
+ }
298
+
299
+ /// \brief Request and poll a long running query
300
+ /// \param[in] options Per-RPC options
301
+ /// \param[in] descriptor the dataset request or a descriptor returned by a
302
+ /// prior PollFlightInfo call
303
+ /// \return Arrow result with the PollInfo describing the status of
304
+ /// the requested query
305
+ arrow::Result<std::unique_ptr<PollInfo>> PollFlightInfo(
306
+ const FlightCallOptions& options, const FlightDescriptor& descriptor);
307
+ arrow::Result<std::unique_ptr<PollInfo>> PollFlightInfo(
308
+ const FlightDescriptor& descriptor) {
309
+ return PollFlightInfo({}, descriptor);
310
+ }
311
+
312
+ /// \brief Request schema for a single flight, which may be an existing
313
+ /// dataset or a command to be executed
314
+ /// \param[in] options Per-RPC options
315
+ /// \param[in] descriptor the dataset request, whether a named dataset or
316
+ /// command
317
+ /// \return Arrow result with the SchemaResult describing the dataset schema
318
+ arrow::Result<std::unique_ptr<SchemaResult>> GetSchema(
319
+ const FlightCallOptions& options, const FlightDescriptor& descriptor);
320
+
321
+ arrow::Result<std::unique_ptr<SchemaResult>> GetSchema(
322
+ const FlightDescriptor& descriptor) {
323
+ return GetSchema({}, descriptor);
324
+ }
325
+
326
+ /// \brief List all available flights known to the server
327
+ /// \return Arrow result with an iterator that returns a FlightInfo for each flight
328
+ arrow::Result<std::unique_ptr<FlightListing>> ListFlights();
329
+
330
+ /// \brief List available flights given indicated filter criteria
331
+ /// \param[in] options Per-RPC options
332
+ /// \param[in] criteria the filter criteria (opaque)
333
+ /// \return Arrow result with an iterator that returns a FlightInfo for each flight
334
+ arrow::Result<std::unique_ptr<FlightListing>> ListFlights(
335
+ const FlightCallOptions& options, const Criteria& criteria);
336
+
337
+ /// \brief Given a flight ticket and schema, request to be sent the
338
+ /// stream. Returns record batch stream reader
339
+ /// \param[in] options Per-RPC options
340
+ /// \param[in] ticket The flight ticket to use
341
+ /// \return Arrow result with the returned RecordBatchReader
342
+ arrow::Result<std::unique_ptr<FlightStreamReader>> DoGet(
343
+ const FlightCallOptions& options, const Ticket& ticket);
344
+ arrow::Result<std::unique_ptr<FlightStreamReader>> DoGet(const Ticket& ticket) {
345
+ return DoGet({}, ticket);
346
+ }
347
+
348
+ /// \brief DoPut return value
349
+ struct DoPutResult {
350
+ /// \brief a writer to write record batches to
351
+ std::unique_ptr<FlightStreamWriter> writer;
352
+ /// \brief a reader for application metadata from the server
353
+ std::unique_ptr<FlightMetadataReader> reader;
354
+ };
355
+ /// \brief Upload data to a Flight described by the given
356
+ /// descriptor. The caller must call Close() on the returned stream
357
+ /// once they are done writing.
358
+ ///
359
+ /// The reader and writer are linked; closing the writer will also
360
+ /// close the reader. Use \a DoneWriting to only close the write
361
+ /// side of the channel.
362
+ ///
363
+ /// \param[in] options Per-RPC options
364
+ /// \param[in] descriptor the descriptor of the stream
365
+ /// \param[in] schema the schema for the data to upload
366
+ /// \return Arrow result with a DoPutResult struct holding a reader and a writer
367
+ arrow::Result<DoPutResult> DoPut(const FlightCallOptions& options,
368
+ const FlightDescriptor& descriptor,
369
+ const std::shared_ptr<Schema>& schema);
370
+
371
+ arrow::Result<DoPutResult> DoPut(const FlightDescriptor& descriptor,
372
+ const std::shared_ptr<Schema>& schema) {
373
+ return DoPut({}, descriptor, schema);
374
+ }
375
+
376
+ struct DoExchangeResult {
377
+ std::unique_ptr<FlightStreamWriter> writer;
378
+ std::unique_ptr<FlightStreamReader> reader;
379
+ };
380
+ arrow::Result<DoExchangeResult> DoExchange(const FlightCallOptions& options,
381
+ const FlightDescriptor& descriptor);
382
+ arrow::Result<DoExchangeResult> DoExchange(const FlightDescriptor& descriptor) {
383
+ return DoExchange({}, descriptor);
384
+ }
385
+
386
+ /// \brief Set server session option(s) by name/value. Sessions are generally
387
+ /// persisted via HTTP cookies.
388
+ /// \param[in] options Per-RPC options
389
+ /// \param[in] request The server session options to set
390
+ ::arrow::Result<SetSessionOptionsResult> SetSessionOptions(
391
+ const FlightCallOptions& options, const SetSessionOptionsRequest& request);
392
+
393
+ /// \brief Get the current server session options. The session is generally
394
+ /// accessed via an HTTP cookie.
395
+ /// \param[in] options Per-RPC options
396
+ /// \param[in] request The (empty) GetSessionOptions request object.
397
+ ::arrow::Result<GetSessionOptionsResult> GetSessionOptions(
398
+ const FlightCallOptions& options, const GetSessionOptionsRequest& request);
399
+
400
+ /// \brief Close/invalidate the current server session. The session is generally
401
+ /// accessed via an HTTP cookie.
402
+ /// \param[in] options Per-RPC options
403
+ /// \param[in] request The (empty) CloseSession request object.
404
+ ::arrow::Result<CloseSessionResult> CloseSession(const FlightCallOptions& options,
405
+ const CloseSessionRequest& request);
406
+
407
+ /// \brief Explicitly shut down and clean up the client.
408
+ ///
409
+ /// For backwards compatibility, this will be implicitly called by
410
+ /// the destructor if not already called, but this gives the
411
+ /// application no chance to handle errors, so it is recommended to
412
+ /// explicitly close the client.
413
+ ///
414
+ /// \since 8.0.0
415
+ Status Close();
416
+
417
+ /// \brief Whether this client supports asynchronous methods.
418
+ bool supports_async() const;
419
+
420
+ /// \brief Check whether this client supports asynchronous methods.
421
+ ///
422
+ /// This is like supports_async(), except that a detailed error message
423
+ /// is returned if async support is not available. If async support is
424
+ /// available, this function returns successfully.
425
+ Status CheckAsyncSupport() const;
426
+
427
+ private:
428
+ FlightClient();
429
+ Status CheckOpen() const;
430
+ std::unique_ptr<internal::ClientTransport> transport_;
431
+ bool closed_;
432
+ int64_t write_size_limit_bytes_;
433
+ };
434
+
435
+ } // namespace flight
436
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/flight/client_auth.h ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include <string>
21
+
22
+ #include "arrow/flight/visibility.h"
23
+ #include "arrow/status.h"
24
+
25
+ namespace arrow {
26
+
27
+ namespace flight {
28
+
29
+ /// \brief A reader for messages from the server during an
30
+ /// authentication handshake.
31
+ class ARROW_FLIGHT_EXPORT ClientAuthReader {
32
+ public:
33
+ virtual ~ClientAuthReader() = default;
34
+ virtual Status Read(std::string* response) = 0;
35
+ };
36
+
37
+ /// \brief A writer for messages to the server during an
38
+ /// authentication handshake.
39
+ class ARROW_FLIGHT_EXPORT ClientAuthSender {
40
+ public:
41
+ virtual ~ClientAuthSender() = default;
42
+ virtual Status Write(const std::string& token) = 0;
43
+ };
44
+
45
+ /// \brief An authentication implementation for a Flight service.
46
+ /// Authentication includes both an initial negotiation and a per-call
47
+ /// token validation. Implementations may choose to use either or both
48
+ /// mechanisms.
49
+ class ARROW_FLIGHT_EXPORT ClientAuthHandler {
50
+ public:
51
+ virtual ~ClientAuthHandler() = default;
52
+ /// \brief Authenticate the client on initial connection. The client
53
+ /// can send messages to/read responses from the server at any time.
54
+ /// \return Status OK if authenticated successfully
55
+ virtual Status Authenticate(ClientAuthSender* outgoing, ClientAuthReader* incoming) = 0;
56
+ /// \brief Get a per-call token.
57
+ /// \param[out] token The token to send to the server.
58
+ virtual Status GetToken(std::string* token) = 0;
59
+ };
60
+
61
+ } // namespace flight
62
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/flight/client_tracing_middleware.h ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // Middleware implementation for propagating OpenTelemetry spans.
19
+
20
+ #pragma once
21
+
22
+ #include <memory>
23
+
24
+ #include "arrow/flight/client_middleware.h"
25
+
26
+ namespace arrow {
27
+ namespace flight {
28
+
29
+ /// \brief Returns a ClientMiddlewareFactory that handles sending OpenTelemetry spans.
30
+ ARROW_FLIGHT_EXPORT std::shared_ptr<ClientMiddlewareFactory>
31
+ MakeTracingClientMiddlewareFactory();
32
+
33
+ } // namespace flight
34
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/flight/pch.h ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // Often-used headers, for precompiling.
19
+ // If updating this header, please make sure you check compilation speed
20
+ // before checking in. Adding headers which are not used extremely often
21
+ // may incur a slowdown, since it makes the precompiled header heavier to load.
22
+
23
+ #include "arrow/flight/client.h"
24
+ #include "arrow/flight/server.h"
25
+ #include "arrow/flight/types.h"
26
+ #include "arrow/pch.h"
venv/lib/python3.10/site-packages/pyarrow/include/arrow/flight/platform.h ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // Internal header. Platform-specific definitions for Flight.
19
+
20
+ #pragma once
21
+
22
+ #ifdef _MSC_VER
23
+
24
+ // The protobuf documentation says that C4251 warnings when using the
25
+ // library are spurious and suppressed when the build the library and
26
+ // compiler, but must be also suppressed in downstream projects
27
+ #pragma warning(disable : 4251)
28
+
29
+ #endif // _MSC_VER
30
+
31
+ #include "arrow/util/config.h" // IWYU pragma: keep
venv/lib/python3.10/site-packages/pyarrow/include/arrow/flight/server_auth.h ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ /// \brief Server-side APIs to implement authentication for Flight.
19
+
20
+ #pragma once
21
+
22
+ #include <string>
23
+
24
+ #include "arrow/flight/type_fwd.h"
25
+ #include "arrow/flight/visibility.h"
26
+ #include "arrow/status.h"
27
+
28
+ namespace arrow {
29
+
30
+ namespace flight {
31
+
32
+ /// \brief A reader for messages from the client during an
33
+ /// authentication handshake.
34
+ class ARROW_FLIGHT_EXPORT ServerAuthReader {
35
+ public:
36
+ virtual ~ServerAuthReader() = default;
37
+ virtual Status Read(std::string* token) = 0;
38
+ };
39
+
40
+ /// \brief A writer for messages to the client during an
41
+ /// authentication handshake.
42
+ class ARROW_FLIGHT_EXPORT ServerAuthSender {
43
+ public:
44
+ virtual ~ServerAuthSender() = default;
45
+ virtual Status Write(const std::string& message) = 0;
46
+ };
47
+
48
+ /// \brief An authentication implementation for a Flight service.
49
+ /// Authentication includes both an initial negotiation and a per-call
50
+ /// token validation. Implementations may choose to use either or both
51
+ /// mechanisms.
52
+ /// An implementation may need to track some state, e.g. a mapping of
53
+ /// client tokens to authenticated identities.
54
+ class ARROW_FLIGHT_EXPORT ServerAuthHandler {
55
+ public:
56
+ virtual ~ServerAuthHandler();
57
+ /// \brief Authenticate the client on initial connection. The server
58
+ /// can send and read responses from the client at any time.
59
+ /// \param[in] context The call context.
60
+ /// \param[in] outgoing The writer for messages to the client.
61
+ /// \param[in] incoming The reader for messages from the client.
62
+ /// \return Status OK if this authentication is succeeded.
63
+ virtual Status Authenticate(const ServerCallContext& context,
64
+ ServerAuthSender* outgoing, ServerAuthReader* incoming) {
65
+ // TODO: We can make this pure virtual function when we remove
66
+ // the deprecated version.
67
+ ARROW_SUPPRESS_DEPRECATION_WARNING
68
+ return Authenticate(outgoing, incoming);
69
+ ARROW_UNSUPPRESS_DEPRECATION_WARNING
70
+ }
71
+ /// \brief Authenticate the client on initial connection. The server
72
+ /// can send and read responses from the client at any time.
73
+ /// \param[in] outgoing The writer for messages to the client.
74
+ /// \param[in] incoming The reader for messages from the client.
75
+ /// \return Status OK if this authentication is succeeded.
76
+ /// \deprecated Deprecated in 13.0.0. Implement the Authentication()
77
+ /// with ServerCallContext version instead.
78
+ ARROW_DEPRECATED("Deprecated in 13.0.0. Use ServerCallContext overload instead.")
79
+ virtual Status Authenticate(ServerAuthSender* outgoing, ServerAuthReader* incoming) {
80
+ return Status::NotImplemented(typeid(this).name(),
81
+ "::Authenticate() isn't implemented");
82
+ }
83
+ /// \brief Validate a per-call client token.
84
+ /// \param[in] context The call context.
85
+ /// \param[in] token The client token. May be the empty string if
86
+ /// the client does not provide a token.
87
+ /// \param[out] peer_identity The identity of the peer, if this
88
+ /// authentication method supports it.
89
+ /// \return Status OK if the token is valid, any other status if
90
+ /// validation failed
91
+ virtual Status IsValid(const ServerCallContext& context, const std::string& token,
92
+ std::string* peer_identity) {
93
+ // TODO: We can make this pure virtual function when we remove
94
+ // the deprecated version.
95
+ ARROW_SUPPRESS_DEPRECATION_WARNING
96
+ return IsValid(token, peer_identity);
97
+ ARROW_UNSUPPRESS_DEPRECATION_WARNING
98
+ }
99
+ /// \brief Validate a per-call client token.
100
+ /// \param[in] token The client token. May be the empty string if
101
+ /// the client does not provide a token.
102
+ /// \param[out] peer_identity The identity of the peer, if this
103
+ /// authentication method supports it.
104
+ /// \return Status OK if the token is valid, any other status if
105
+ /// validation failed
106
+ /// \deprecated Deprecated in 13.0.0. Implement the IsValid()
107
+ /// with ServerCallContext version instead.
108
+ ARROW_DEPRECATED("Deprecated in 13.0.0. Use ServerCallContext overload instead.")
109
+ virtual Status IsValid(const std::string& token, std::string* peer_identity) {
110
+ return Status::NotImplemented(typeid(this).name(), "::IsValid() isn't implemented");
111
+ }
112
+ };
113
+
114
+ /// \brief An authentication mechanism that does nothing.
115
+ class ARROW_FLIGHT_EXPORT NoOpAuthHandler : public ServerAuthHandler {
116
+ public:
117
+ ~NoOpAuthHandler() override;
118
+ Status Authenticate(const ServerCallContext& context, ServerAuthSender* outgoing,
119
+ ServerAuthReader* incoming) override;
120
+ Status IsValid(const ServerCallContext& context, const std::string& token,
121
+ std::string* peer_identity) override;
122
+ };
123
+
124
+ } // namespace flight
125
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/flight/server_middleware.h ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // Interfaces for defining middleware for Flight servers. Currently
19
+ // experimental.
20
+
21
+ #pragma once
22
+
23
+ #include <memory>
24
+ #include <string>
25
+
26
+ #include "arrow/flight/middleware.h"
27
+ #include "arrow/flight/type_fwd.h"
28
+ #include "arrow/flight/visibility.h" // IWYU pragma: keep
29
+ #include "arrow/status.h"
30
+
31
+ namespace arrow {
32
+ namespace flight {
33
+
34
+ /// \brief Server-side middleware for a call, instantiated per RPC.
35
+ ///
36
+ /// Middleware should be fast and must be infallible: there is no way
37
+ /// to reject the call or report errors from the middleware instance.
38
+ class ARROW_FLIGHT_EXPORT ServerMiddleware {
39
+ public:
40
+ virtual ~ServerMiddleware() = default;
41
+
42
+ /// \brief Unique name of middleware, used as alternative to RTTI
43
+ /// \return the string name of the middleware
44
+ virtual std::string name() const = 0;
45
+
46
+ /// \brief A callback before headers are sent. Extra headers can be
47
+ /// added, but existing ones cannot be read.
48
+ virtual void SendingHeaders(AddCallHeaders* outgoing_headers) = 0;
49
+
50
+ /// \brief A callback after the call has completed.
51
+ virtual void CallCompleted(const Status& status) = 0;
52
+ };
53
+
54
+ /// \brief A factory for new middleware instances.
55
+ ///
56
+ /// If added to a server, this will be called for each RPC (including
57
+ /// Handshake) to give the opportunity to intercept the call.
58
+ ///
59
+ /// It is guaranteed that all server middleware methods are called
60
+ /// from the same thread that calls the RPC method implementation.
61
+ class ARROW_FLIGHT_EXPORT ServerMiddlewareFactory {
62
+ public:
63
+ virtual ~ServerMiddlewareFactory() = default;
64
+
65
+ /// \brief A callback for the start of a new call.
66
+ ///
67
+ /// Return a non-OK status to reject the call with the given status.
68
+ ///
69
+ /// \param[in] info Information about the call.
70
+ /// \param[in] context The call context.
71
+ /// \param[out] middleware The middleware instance for this call. If
72
+ /// null, no middleware will be added to this call instance from
73
+ /// this factory.
74
+ /// \return Status A non-OK status will reject the call with the
75
+ /// given status. Middleware previously in the chain will have
76
+ /// their CallCompleted callback called. Other middleware
77
+ /// factories will not be called.
78
+ virtual Status StartCall(const CallInfo& info, const ServerCallContext& context,
79
+ std::shared_ptr<ServerMiddleware>* middleware);
80
+
81
+ /// \brief A callback for the start of a new call.
82
+ ///
83
+ /// Return a non-OK status to reject the call with the given status.
84
+ ///
85
+ /// \param info Information about the call.
86
+ /// \param incoming_headers Headers sent by the client for this call.
87
+ /// Do not retain a reference to this object.
88
+ /// \param[out] middleware The middleware instance for this call. If
89
+ /// null, no middleware will be added to this call instance from
90
+ /// this factory.
91
+ /// \return Status A non-OK status will reject the call with the
92
+ /// given status. Middleware previously in the chain will have
93
+ /// their CallCompleted callback called. Other middleware
94
+ /// factories will not be called.
95
+ /// \deprecated Deprecated in 13.0.0. Implement the StartCall()
96
+ /// with ServerCallContext version instead.
97
+ ARROW_DEPRECATED("Deprecated in 13.0.0. Use ServerCallContext overload instead.")
98
+ virtual Status StartCall(const CallInfo& info, const CallHeaders& incoming_headers,
99
+ std::shared_ptr<ServerMiddleware>* middleware) {
100
+ return Status::NotImplemented(typeid(this).name(), "::StartCall() isn't implemented");
101
+ }
102
+ };
103
+
104
+ } // namespace flight
105
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/flight/server_tracing_middleware.h ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // Middleware implementation for propagating OpenTelemetry spans.
19
+
20
+ #pragma once
21
+
22
+ #include <memory>
23
+ #include <string>
24
+ #include <vector>
25
+
26
+ #include "arrow/flight/server_middleware.h"
27
+ #include "arrow/flight/visibility.h"
28
+ #include "arrow/status.h"
29
+
30
+ namespace arrow {
31
+ namespace flight {
32
+
33
+ /// \brief Returns a ServerMiddlewareFactory that handles receiving OpenTelemetry spans.
34
+ ARROW_FLIGHT_EXPORT std::shared_ptr<ServerMiddlewareFactory>
35
+ MakeTracingServerMiddlewareFactory();
36
+
37
+ /// \brief A server middleware that provides access to the
38
+ /// OpenTelemetry context, if present.
39
+ ///
40
+ /// Used to make the OpenTelemetry span available in Python.
41
+ class ARROW_FLIGHT_EXPORT TracingServerMiddleware : public ServerMiddleware {
42
+ public:
43
+ ~TracingServerMiddleware();
44
+
45
+ static constexpr char const kMiddlewareName[] =
46
+ "arrow::flight::TracingServerMiddleware";
47
+
48
+ std::string name() const override { return kMiddlewareName; }
49
+ void SendingHeaders(AddCallHeaders*) override;
50
+ void CallCompleted(const Status&) override;
51
+
52
+ struct TraceKey {
53
+ std::string key;
54
+ std::string value;
55
+ };
56
+ /// \brief Get the trace context.
57
+ std::vector<TraceKey> GetTraceContext() const;
58
+
59
+ private:
60
+ class Impl;
61
+ friend class TracingServerMiddlewareFactory;
62
+
63
+ explicit TracingServerMiddleware(std::unique_ptr<Impl> impl);
64
+ std::unique_ptr<Impl> impl_;
65
+ };
66
+
67
+ } // namespace flight
68
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/flight/test_util.h ADDED
@@ -0,0 +1,264 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include <gmock/gmock.h>
21
+ #include <gtest/gtest.h>
22
+
23
+ #include <cstdint>
24
+ #include <memory>
25
+ #include <string>
26
+ #include <thread>
27
+ #include <utility>
28
+ #include <vector>
29
+
30
+ #include "arrow/status.h"
31
+ #include "arrow/testing/gtest_util.h"
32
+ #include "arrow/testing/util.h"
33
+
34
+ #include "arrow/flight/client.h"
35
+ #include "arrow/flight/client_auth.h"
36
+ #include "arrow/flight/server.h"
37
+ #include "arrow/flight/server_auth.h"
38
+ #include "arrow/flight/types.h"
39
+ #include "arrow/flight/visibility.h"
40
+
41
+ namespace boost {
42
+ namespace process {
43
+
44
+ class child;
45
+
46
+ } // namespace process
47
+ } // namespace boost
48
+
49
+ namespace arrow {
50
+ namespace flight {
51
+
52
+ // ----------------------------------------------------------------------
53
+ // Helpers to compare values for equality
54
+
55
+ inline void AssertEqual(const FlightInfo& expected, const FlightInfo& actual) {
56
+ ipc::DictionaryMemo expected_memo;
57
+ ipc::DictionaryMemo actual_memo;
58
+ ASSERT_OK_AND_ASSIGN(auto ex_schema, expected.GetSchema(&expected_memo));
59
+ ASSERT_OK_AND_ASSIGN(auto actual_schema, actual.GetSchema(&actual_memo));
60
+
61
+ AssertSchemaEqual(*ex_schema, *actual_schema);
62
+ ASSERT_EQ(expected.total_records(), actual.total_records());
63
+ ASSERT_EQ(expected.total_bytes(), actual.total_bytes());
64
+
65
+ ASSERT_EQ(expected.descriptor(), actual.descriptor());
66
+ ASSERT_THAT(actual.endpoints(), ::testing::ContainerEq(expected.endpoints()));
67
+ }
68
+
69
+ // ----------------------------------------------------------------------
70
+ // Fixture to use for running test servers
71
+
72
+ class ARROW_FLIGHT_EXPORT TestServer {
73
+ public:
74
+ explicit TestServer(const std::string& executable_name)
75
+ : executable_name_(executable_name), port_(::arrow::GetListenPort()) {}
76
+ TestServer(const std::string& executable_name, int port)
77
+ : executable_name_(executable_name), port_(port) {}
78
+ TestServer(const std::string& executable_name, const std::string& unix_sock)
79
+ : executable_name_(executable_name), unix_sock_(unix_sock) {}
80
+
81
+ void Start(const std::vector<std::string>& extra_args);
82
+ void Start() { Start({}); }
83
+
84
+ int Stop();
85
+
86
+ bool IsRunning();
87
+
88
+ int port() const;
89
+ const std::string& unix_sock() const;
90
+
91
+ private:
92
+ std::string executable_name_;
93
+ int port_;
94
+ std::string unix_sock_;
95
+ std::shared_ptr<::boost::process::child> server_process_;
96
+ };
97
+
98
+ /// \brief Create a simple Flight server for testing
99
+ ARROW_FLIGHT_EXPORT
100
+ std::unique_ptr<FlightServerBase> ExampleTestServer();
101
+
102
+ // Helper to initialize a server and matching client with callbacks to
103
+ // populate options.
104
+ template <typename T, typename... Args>
105
+ Status MakeServer(const Location& location, std::unique_ptr<FlightServerBase>* server,
106
+ std::unique_ptr<FlightClient>* client,
107
+ std::function<Status(FlightServerOptions*)> make_server_options,
108
+ std::function<Status(FlightClientOptions*)> make_client_options,
109
+ Args&&... server_args) {
110
+ *server = std::make_unique<T>(std::forward<Args>(server_args)...);
111
+ FlightServerOptions server_options(location);
112
+ RETURN_NOT_OK(make_server_options(&server_options));
113
+ RETURN_NOT_OK((*server)->Init(server_options));
114
+ std::string uri =
115
+ location.scheme() + "://127.0.0.1:" + std::to_string((*server)->port());
116
+ ARROW_ASSIGN_OR_RAISE(auto real_location, Location::Parse(uri));
117
+ FlightClientOptions client_options = FlightClientOptions::Defaults();
118
+ RETURN_NOT_OK(make_client_options(&client_options));
119
+ return FlightClient::Connect(real_location, client_options).Value(client);
120
+ }
121
+
122
+ // Helper to initialize a server and matching client with callbacks to
123
+ // populate options.
124
+ template <typename T, typename... Args>
125
+ Status MakeServer(std::unique_ptr<FlightServerBase>* server,
126
+ std::unique_ptr<FlightClient>* client,
127
+ std::function<Status(FlightServerOptions*)> make_server_options,
128
+ std::function<Status(FlightClientOptions*)> make_client_options,
129
+ Args&&... server_args) {
130
+ ARROW_ASSIGN_OR_RAISE(auto location, Location::ForGrpcTcp("localhost", 0));
131
+ return MakeServer<T>(location, server, client, std::move(make_server_options),
132
+ std::move(make_client_options),
133
+ std::forward<Args>(server_args)...);
134
+ }
135
+
136
+ // ----------------------------------------------------------------------
137
+ // A FlightDataStream that numbers the record batches
138
+ /// \brief A basic implementation of FlightDataStream that will provide
139
+ /// a sequence of FlightData messages to be written to a stream
140
+ class ARROW_FLIGHT_EXPORT NumberingStream : public FlightDataStream {
141
+ public:
142
+ explicit NumberingStream(std::unique_ptr<FlightDataStream> stream);
143
+
144
+ std::shared_ptr<Schema> schema() override;
145
+ arrow::Result<FlightPayload> GetSchemaPayload() override;
146
+ arrow::Result<FlightPayload> Next() override;
147
+
148
+ private:
149
+ int counter_;
150
+ std::shared_ptr<FlightDataStream> stream_;
151
+ };
152
+
153
+ // ----------------------------------------------------------------------
154
+ // Example data for test-server and unit tests
155
+
156
+ ARROW_FLIGHT_EXPORT
157
+ std::shared_ptr<Schema> ExampleIntSchema();
158
+
159
+ ARROW_FLIGHT_EXPORT
160
+ std::shared_ptr<Schema> ExampleStringSchema();
161
+
162
+ ARROW_FLIGHT_EXPORT
163
+ std::shared_ptr<Schema> ExampleDictSchema();
164
+
165
+ ARROW_FLIGHT_EXPORT
166
+ std::shared_ptr<Schema> ExampleLargeSchema();
167
+
168
+ ARROW_FLIGHT_EXPORT
169
+ Status ExampleIntBatches(RecordBatchVector* out);
170
+
171
+ ARROW_FLIGHT_EXPORT
172
+ Status ExampleFloatBatches(RecordBatchVector* out);
173
+
174
+ ARROW_FLIGHT_EXPORT
175
+ Status ExampleDictBatches(RecordBatchVector* out);
176
+
177
+ ARROW_FLIGHT_EXPORT
178
+ Status ExampleNestedBatches(RecordBatchVector* out);
179
+
180
+ ARROW_FLIGHT_EXPORT
181
+ Status ExampleLargeBatches(RecordBatchVector* out);
182
+
183
+ ARROW_FLIGHT_EXPORT
184
+ arrow::Result<std::shared_ptr<RecordBatch>> VeryLargeBatch();
185
+
186
+ ARROW_FLIGHT_EXPORT
187
+ std::vector<FlightInfo> ExampleFlightInfo();
188
+
189
+ ARROW_FLIGHT_EXPORT
190
+ std::vector<ActionType> ExampleActionTypes();
191
+
192
+ ARROW_FLIGHT_EXPORT
193
+ FlightInfo MakeFlightInfo(const Schema& schema, const FlightDescriptor& descriptor,
194
+ const std::vector<FlightEndpoint>& endpoints,
195
+ int64_t total_records, int64_t total_bytes, bool ordered,
196
+ std::string app_metadata);
197
+
198
+ // ----------------------------------------------------------------------
199
+ // A pair of authentication handlers that check for a predefined password
200
+ // and set the peer identity to a predefined username.
201
+
202
+ class ARROW_FLIGHT_EXPORT TestServerAuthHandler : public ServerAuthHandler {
203
+ public:
204
+ explicit TestServerAuthHandler(const std::string& username,
205
+ const std::string& password);
206
+ ~TestServerAuthHandler() override;
207
+ Status Authenticate(const ServerCallContext& context, ServerAuthSender* outgoing,
208
+ ServerAuthReader* incoming) override;
209
+ Status IsValid(const ServerCallContext& context, const std::string& token,
210
+ std::string* peer_identity) override;
211
+
212
+ private:
213
+ std::string username_;
214
+ std::string password_;
215
+ };
216
+
217
+ class ARROW_FLIGHT_EXPORT TestServerBasicAuthHandler : public ServerAuthHandler {
218
+ public:
219
+ explicit TestServerBasicAuthHandler(const std::string& username,
220
+ const std::string& password);
221
+ ~TestServerBasicAuthHandler() override;
222
+ Status Authenticate(const ServerCallContext& context, ServerAuthSender* outgoing,
223
+ ServerAuthReader* incoming) override;
224
+ Status IsValid(const ServerCallContext& context, const std::string& token,
225
+ std::string* peer_identity) override;
226
+
227
+ private:
228
+ BasicAuth basic_auth_;
229
+ };
230
+
231
+ class ARROW_FLIGHT_EXPORT TestClientAuthHandler : public ClientAuthHandler {
232
+ public:
233
+ explicit TestClientAuthHandler(const std::string& username,
234
+ const std::string& password);
235
+ ~TestClientAuthHandler() override;
236
+ Status Authenticate(ClientAuthSender* outgoing, ClientAuthReader* incoming) override;
237
+ Status GetToken(std::string* token) override;
238
+
239
+ private:
240
+ std::string username_;
241
+ std::string password_;
242
+ };
243
+
244
+ class ARROW_FLIGHT_EXPORT TestClientBasicAuthHandler : public ClientAuthHandler {
245
+ public:
246
+ explicit TestClientBasicAuthHandler(const std::string& username,
247
+ const std::string& password);
248
+ ~TestClientBasicAuthHandler() override;
249
+ Status Authenticate(ClientAuthSender* outgoing, ClientAuthReader* incoming) override;
250
+ Status GetToken(std::string* token) override;
251
+
252
+ private:
253
+ BasicAuth basic_auth_;
254
+ std::string token_;
255
+ };
256
+
257
+ ARROW_FLIGHT_EXPORT
258
+ Status ExampleTlsCertificates(std::vector<CertKeyPair>* out);
259
+
260
+ ARROW_FLIGHT_EXPORT
261
+ Status ExampleTlsCertificateRoot(CertKeyPair* out);
262
+
263
+ } // namespace flight
264
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/flight/transport_server.h ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include <chrono>
21
+ #include <memory>
22
+
23
+ #include "arrow/flight/transport.h"
24
+ #include "arrow/flight/type_fwd.h"
25
+ #include "arrow/flight/visibility.h"
26
+ #include "arrow/type_fwd.h"
27
+
28
+ namespace arrow {
29
+ namespace ipc {
30
+ class Message;
31
+ }
32
+ namespace flight {
33
+ namespace internal {
34
+
35
+ /// \brief A transport-specific interface for reading/writing Arrow
36
+ /// data for a server.
37
+ class ARROW_FLIGHT_EXPORT ServerDataStream : public TransportDataStream {
38
+ public:
39
+ /// \brief Attempt to write a non-data message.
40
+ ///
41
+ /// Only implemented for DoPut; mutually exclusive with
42
+ /// WriteData(const FlightPayload&).
43
+ virtual Status WritePutMetadata(const Buffer& payload);
44
+ };
45
+
46
+ /// \brief An implementation of a Flight server for a particular
47
+ /// transport.
48
+ ///
49
+ /// This class (the transport implementation) implements the underlying
50
+ /// server and handles connections/incoming RPC calls. It should forward RPC
51
+ /// calls to the RPC handlers defined on this class, which work in terms of
52
+ /// the generic interfaces above. The RPC handlers here then forward calls
53
+ /// to the underlying FlightServerBase instance that contains the actual
54
+ /// application RPC method handlers.
55
+ ///
56
+ /// Used by FlightServerBase to manage the server lifecycle.
57
+ class ARROW_FLIGHT_EXPORT ServerTransport {
58
+ public:
59
+ ServerTransport(FlightServerBase* base, std::shared_ptr<MemoryManager> memory_manager)
60
+ : base_(base), memory_manager_(std::move(memory_manager)) {}
61
+ virtual ~ServerTransport() = default;
62
+
63
+ /// \name Server Lifecycle Methods
64
+ /// Transports implement these methods to start/shutdown the underlying
65
+ /// server.
66
+ /// @{
67
+ /// \brief Initialize the server.
68
+ ///
69
+ /// This method should launch the server in a background thread, i.e. it
70
+ /// should not block. Once this returns, the server should be active.
71
+ virtual Status Init(const FlightServerOptions& options,
72
+ const arrow::util::Uri& uri) = 0;
73
+ /// \brief Shutdown the server.
74
+ ///
75
+ /// This should wait for active RPCs to finish. Once this returns, the
76
+ /// server is no longer listening.
77
+ virtual Status Shutdown() = 0;
78
+ /// \brief Shutdown the server with a deadline.
79
+ ///
80
+ /// This should wait for active RPCs to finish, or for the deadline to
81
+ /// expire. Once this returns, the server is no longer listening.
82
+ virtual Status Shutdown(const std::chrono::system_clock::time_point& deadline) = 0;
83
+ /// \brief Wait for the server to shutdown (but do not shut down the server).
84
+ ///
85
+ /// Once this returns, the server is no longer listening.
86
+ virtual Status Wait() = 0;
87
+ /// \brief Get the address the server is listening on, else an empty Location.
88
+ virtual Location location() const = 0;
89
+ ///@}
90
+
91
+ /// \name RPC Handlers
92
+ /// Implementations of RPC handlers for Flight methods using the common
93
+ /// interfaces here. Transports should call these methods from their
94
+ /// server implementation to handle the actual RPC calls.
95
+ ///@{
96
+ /// \brief Get the FlightServerBase.
97
+ ///
98
+ /// Intended as an escape hatch for now since not all methods have been
99
+ /// factored into a transport-agnostic interface.
100
+ FlightServerBase* base() const { return base_; }
101
+ /// \brief Implement DoGet in terms of a transport-level stream.
102
+ ///
103
+ /// \param[in] context The server context.
104
+ /// \param[in] request The request payload.
105
+ /// \param[in] stream The transport-specific data stream
106
+ /// implementation. Must implement WriteData(const
107
+ /// FlightPayload&).
108
+ Status DoGet(const ServerCallContext& context, const Ticket& request,
109
+ ServerDataStream* stream);
110
+ /// \brief Implement DoPut in terms of a transport-level stream.
111
+ ///
112
+ /// \param[in] context The server context.
113
+ /// \param[in] stream The transport-specific data stream
114
+ /// implementation. Must implement ReadData(FlightData*)
115
+ /// and WritePutMetadata(const Buffer&).
116
+ Status DoPut(const ServerCallContext& context, ServerDataStream* stream);
117
+ /// \brief Implement DoExchange in terms of a transport-level stream.
118
+ ///
119
+ /// \param[in] context The server context.
120
+ /// \param[in] stream The transport-specific data stream
121
+ /// implementation. Must implement ReadData(FlightData*)
122
+ /// and WriteData(const FlightPayload&).
123
+ Status DoExchange(const ServerCallContext& context, ServerDataStream* stream);
124
+ ///@}
125
+
126
+ protected:
127
+ FlightServerBase* base_;
128
+ std::shared_ptr<MemoryManager> memory_manager_;
129
+ };
130
+
131
+ } // namespace internal
132
+ } // namespace flight
133
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/flight/type_fwd.h ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ namespace arrow {
21
+ namespace internal {
22
+ class Uri;
23
+ }
24
+ namespace flight {
25
+ struct Action;
26
+ struct ActionType;
27
+ template <typename T>
28
+ class AsyncListener;
29
+ class AsyncListenerBase;
30
+ class AsyncRpc;
31
+ struct BasicAuth;
32
+ class ClientAuthHandler;
33
+ class ClientMiddleware;
34
+ class ClientMiddlewareFactory;
35
+ struct Criteria;
36
+ class FlightCallOptions;
37
+ struct FlightClientOptions;
38
+ struct FlightDescriptor;
39
+ struct FlightEndpoint;
40
+ class FlightInfo;
41
+ class PollInfo;
42
+ class FlightListing;
43
+ class FlightMetadataReader;
44
+ class FlightMetadataWriter;
45
+ struct FlightPayload;
46
+ class FlightServerBase;
47
+ class FlightServerOptions;
48
+ class FlightStreamReader;
49
+ class FlightStreamWriter;
50
+ struct Location;
51
+ struct Result;
52
+ class ResultStream;
53
+ struct SchemaResult;
54
+ class ServerCallContext;
55
+ class ServerMiddleware;
56
+ class ServerMiddlewareFactory;
57
+ struct Ticket;
58
+ namespace internal {
59
+ class AsyncRpc;
60
+ class ClientTransport;
61
+ struct FlightData;
62
+ class ServerTransport;
63
+ } // namespace internal
64
+ } // namespace flight
65
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/flight/visibility.h ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #if defined(_WIN32) || defined(__CYGWIN__)
21
+ #if defined(_MSC_VER)
22
+ #pragma warning(push)
23
+ #pragma warning(disable : 4251)
24
+ #else
25
+ #pragma GCC diagnostic ignored "-Wattributes"
26
+ #endif
27
+
28
+ #ifdef ARROW_FLIGHT_STATIC
29
+ #define ARROW_FLIGHT_EXPORT
30
+ #elif defined(ARROW_FLIGHT_EXPORTING)
31
+ #define ARROW_FLIGHT_EXPORT __declspec(dllexport)
32
+ #else
33
+ #define ARROW_FLIGHT_EXPORT __declspec(dllimport)
34
+ #endif
35
+
36
+ #define ARROW_FLIGHT_NO_EXPORT
37
+ #else // Not Windows
38
+ #ifndef ARROW_FLIGHT_EXPORT
39
+ #define ARROW_FLIGHT_EXPORT __attribute__((visibility("default")))
40
+ #endif
41
+ #ifndef ARROW_FLIGHT_NO_EXPORT
42
+ #define ARROW_FLIGHT_NO_EXPORT __attribute__((visibility("hidden")))
43
+ #endif
44
+ #endif // Non-Windows
45
+
46
+ #if defined(_MSC_VER)
47
+ #pragma warning(pop)
48
+ #endif
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/api.h ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include "arrow/python/arrow_to_pandas.h"
21
+ #include "arrow/python/common.h"
22
+ #include "arrow/python/datetime.h"
23
+ #include "arrow/python/deserialize.h"
24
+ #include "arrow/python/helpers.h"
25
+ #include "arrow/python/inference.h"
26
+ #include "arrow/python/io.h"
27
+ #include "arrow/python/numpy_convert.h"
28
+ #include "arrow/python/numpy_to_arrow.h"
29
+ #include "arrow/python/python_to_arrow.h"
30
+ #include "arrow/python/serialize.h"
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/arrow_to_pandas.h ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
22
+
23
+ #include "arrow/python/platform.h"
24
+
25
+ #include <memory>
26
+ #include <string>
27
+ #include <unordered_set>
28
+
29
+ #include "arrow/memory_pool.h"
30
+ #include "arrow/python/visibility.h"
31
+
32
+ namespace arrow {
33
+
34
+ class Array;
35
+ class ChunkedArray;
36
+ class Column;
37
+ class DataType;
38
+ class MemoryPool;
39
+ class Status;
40
+ class Table;
41
+
42
+ namespace py {
43
+
44
+ enum class MapConversionType {
45
+ DEFAULT, // convert arrow maps to assoc lists (list of kev-value tuples) in Pandas
46
+ LOSSY, // report warnings when lossiness is encountered due to duplicate keys
47
+ STRICT_, // raise a Python exception when lossiness is encountered due to duplicate
48
+ // keys
49
+ };
50
+
51
+ struct PandasOptions {
52
+ /// arrow::MemoryPool to use for memory allocations
53
+ MemoryPool* pool = default_memory_pool();
54
+
55
+ /// If true, we will convert all string columns to categoricals
56
+ bool strings_to_categorical = false;
57
+ bool zero_copy_only = false;
58
+ bool integer_object_nulls = false;
59
+ bool date_as_object = false;
60
+ bool timestamp_as_object = false;
61
+ bool use_threads = false;
62
+
63
+ /// Coerce all date and timestamp to datetime64[ns]
64
+ bool coerce_temporal_nanoseconds = false;
65
+
66
+ /// Used to maintain backwards compatibility for
67
+ /// timezone bugs (see ARROW-9528). Should be removed
68
+ /// after Arrow 2.0 release.
69
+ bool ignore_timezone = false;
70
+
71
+ /// \brief If true, do not create duplicate PyObject versions of equal
72
+ /// objects. This only applies to immutable objects like strings or datetime
73
+ /// objects
74
+ bool deduplicate_objects = false;
75
+
76
+ /// \brief For certain data types, a cast is needed in order to store the
77
+ /// data in a pandas DataFrame or Series (e.g. timestamps are always stored
78
+ /// as nanoseconds in pandas). This option controls whether it is a safe
79
+ /// cast or not.
80
+ bool safe_cast = true;
81
+
82
+ /// \brief If true, create one block per column rather than consolidated
83
+ /// blocks (1 per data type). Do zero-copy wrapping when there are no
84
+ /// nulls. pandas currently will consolidate the blocks on its own, causing
85
+ /// increased memory use, so keep this in mind if you are working on a
86
+ /// memory-constrained situation.
87
+ bool split_blocks = false;
88
+
89
+ /// \brief If true, allow non-writable zero-copy views to be created for
90
+ /// single column blocks. This option is also used to provide zero copy for
91
+ /// Series data
92
+ bool allow_zero_copy_blocks = false;
93
+
94
+ /// \brief If true, attempt to deallocate buffers in passed Arrow object if
95
+ /// it is the only remaining shared_ptr copy of it. See ARROW-3789 for
96
+ /// original context for this feature. Only currently implemented for Table
97
+ /// conversions
98
+ bool self_destruct = false;
99
+
100
+ /// \brief The default behavior (DEFAULT), is to convert Arrow Map arrays to
101
+ /// Python association lists (list-of-tuples) in the same order as the Arrow
102
+ /// Map, as in [(key1, value1), (key2, value2), ...]
103
+ /// If LOSSY or STRICT, convert Arrow Map arrays to native Python dicts.
104
+ /// This can change the ordering of (key, value) pairs, and will deduplicate
105
+ /// multiple keys, resulting in a possible loss of data.
106
+ /// If 'lossy', this key deduplication results in a warning printed
107
+ /// when detected. If 'strict', this instead results in an exception
108
+ /// being raised when detected.
109
+ MapConversionType maps_as_pydicts = MapConversionType::DEFAULT;
110
+
111
+ // Used internally for nested arrays.
112
+ bool decode_dictionaries = false;
113
+
114
+ // Columns that should be casted to categorical
115
+ std::unordered_set<std::string> categorical_columns;
116
+
117
+ // Columns that should be passed through to be converted to
118
+ // ExtensionArray/Block
119
+ std::unordered_set<std::string> extension_columns;
120
+
121
+ // Used internally to decipher between to_numpy() and to_pandas() when
122
+ // the expected output differs
123
+ bool to_numpy = false;
124
+ };
125
+
126
+ ARROW_PYTHON_EXPORT
127
+ Status ConvertArrayToPandas(const PandasOptions& options, std::shared_ptr<Array> arr,
128
+ PyObject* py_ref, PyObject** out);
129
+
130
+ ARROW_PYTHON_EXPORT
131
+ Status ConvertChunkedArrayToPandas(const PandasOptions& options,
132
+ std::shared_ptr<ChunkedArray> col, PyObject* py_ref,
133
+ PyObject** out);
134
+
135
+ // Convert a whole table as efficiently as possible to a pandas.DataFrame.
136
+ //
137
+ // The returned Python object is a list of tuples consisting of the exact 2D
138
+ // BlockManager structure of the pandas.DataFrame used as of pandas 0.19.x.
139
+ //
140
+ // tuple item: (indices: ndarray[int32], block: ndarray[TYPE, ndim=2])
141
+ ARROW_PYTHON_EXPORT
142
+ Status ConvertTableToPandas(const PandasOptions& options, std::shared_ptr<Table> table,
143
+ PyObject** out);
144
+
145
+ } // namespace py
146
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/async.h ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include <utility>
21
+
22
+ #include "arrow/python/common.h"
23
+ #include "arrow/status.h"
24
+ #include "arrow/util/future.h"
25
+
26
+ namespace arrow::py {
27
+
28
+ /// \brief Bind a Python callback to an arrow::Future.
29
+ ///
30
+ /// If the Future finishes successfully, py_wrapper is called with its
31
+ /// result value and should return a PyObject*. If py_wrapper is successful,
32
+ /// py_cb is called with its return value.
33
+ ///
34
+ /// If either the Future or py_wrapper fails, py_cb is called with the
35
+ /// associated Python exception.
36
+ ///
37
+ /// \param future The future to bind to.
38
+ /// \param py_cb The Python callback function. Will be passed the result of
39
+ /// py_wrapper, or a Python exception if the future failed or one was
40
+ /// raised by py_wrapper.
41
+ /// \param py_wrapper A function (likely defined in Cython) to convert the C++
42
+ /// result of the future to a Python object.
43
+ template <typename T, typename PyWrapper = PyObject* (*)(T)>
44
+ void BindFuture(Future<T> future, PyObject* py_cb, PyWrapper py_wrapper) {
45
+ Py_INCREF(py_cb);
46
+ OwnedRefNoGIL cb_ref(py_cb);
47
+
48
+ auto future_cb = [cb_ref = std::move(cb_ref),
49
+ py_wrapper = std::move(py_wrapper)](Result<T> result) {
50
+ SafeCallIntoPythonVoid([&]() {
51
+ OwnedRef py_value_or_exc{WrapResult(std::move(result), std::move(py_wrapper))};
52
+ Py_XDECREF(
53
+ PyObject_CallFunctionObjArgs(cb_ref.obj(), py_value_or_exc.obj(), NULLPTR));
54
+ ARROW_WARN_NOT_OK(CheckPyError(), "Internal error in async call");
55
+ });
56
+ };
57
+ future.AddCallback(std::move(future_cb));
58
+ }
59
+
60
+ } // namespace arrow::py
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/benchmark.h ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include "arrow/python/platform.h"
21
+
22
+ #include "arrow/python/visibility.h"
23
+
24
+ namespace arrow {
25
+ namespace py {
26
+ namespace benchmark {
27
+
28
+ // Micro-benchmark routines for use from ASV
29
+
30
+ // Run PandasObjectIsNull() once over every object in *list*
31
+ ARROW_PYTHON_EXPORT
32
+ void Benchmark_PandasObjectIsNull(PyObject* list);
33
+
34
+ } // namespace benchmark
35
+ } // namespace py
36
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/common.h ADDED
@@ -0,0 +1,458 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include <functional>
21
+ #include <memory>
22
+ #include <optional>
23
+ #include <utility>
24
+
25
+ #include "arrow/buffer.h"
26
+ #include "arrow/python/pyarrow.h"
27
+ #include "arrow/python/visibility.h"
28
+ #include "arrow/result.h"
29
+ #include "arrow/util/macros.h"
30
+
31
+ namespace arrow {
32
+
33
+ class MemoryPool;
34
+ template <class T>
35
+ class Result;
36
+
37
+ namespace py {
38
+
39
+ // Convert current Python error to a Status. The Python error state is cleared
40
+ // and can be restored with RestorePyError().
41
+ ARROW_PYTHON_EXPORT Status ConvertPyError(StatusCode code = StatusCode::UnknownError);
42
+ // Query whether the given Status is a Python error (as wrapped by ConvertPyError()).
43
+ ARROW_PYTHON_EXPORT bool IsPyError(const Status& status);
44
+ // Restore a Python error wrapped in a Status.
45
+ ARROW_PYTHON_EXPORT void RestorePyError(const Status& status);
46
+
47
+ // Catch a pending Python exception and return the corresponding Status.
48
+ // If no exception is pending, Status::OK() is returned.
49
+ inline Status CheckPyError(StatusCode code = StatusCode::UnknownError) {
50
+ if (ARROW_PREDICT_TRUE(!PyErr_Occurred())) {
51
+ return Status::OK();
52
+ } else {
53
+ return ConvertPyError(code);
54
+ }
55
+ }
56
+
57
+ #define RETURN_IF_PYERROR() ARROW_RETURN_NOT_OK(CheckPyError())
58
+
59
+ #define PY_RETURN_IF_ERROR(CODE) ARROW_RETURN_NOT_OK(CheckPyError(CODE))
60
+
61
+ // For Cython, as you can't define template C++ functions in Cython, only use them.
62
+ // This function can set a Python exception. It assumes that T has a (cheap)
63
+ // default constructor.
64
+ template <class T>
65
+ T GetResultValue(Result<T> result) {
66
+ if (ARROW_PREDICT_TRUE(result.ok())) {
67
+ return *std::move(result);
68
+ } else {
69
+ int r = internal::check_status(result.status()); // takes the GIL
70
+ assert(r == -1); // should have errored out
71
+ ARROW_UNUSED(r);
72
+ return {};
73
+ }
74
+ }
75
+
76
+ /// \brief Wrap a Result and return the corresponding Python object.
77
+ ///
78
+ /// If the Result is successful, py_wrapper is called with its result value
79
+ /// and should return a PyObject*. If py_wrapper is successful (returns
80
+ /// a non-NULL value), its return value is returned.
81
+ ///
82
+ /// If either the Result or py_wrapper fails, the associated Python exception
83
+ /// is raised and NULL is returned.
84
+ //
85
+ /// \param result The Result whose value to wrap in a Python object.
86
+ /// \param py_wrapper A function (likely defined in Cython) to convert the C++
87
+ /// value of the Result to a Python object.
88
+ /// \return A new Python reference, or NULL if an exception occurred
89
+ template <typename T, typename PyWrapper = PyObject* (*)(T)>
90
+ PyObject* WrapResult(Result<T> result, PyWrapper&& py_wrapper) {
91
+ static_assert(std::is_same_v<PyObject*, decltype(py_wrapper(std::declval<T>()))>,
92
+ "PyWrapper argument to WrapResult should return a PyObject* "
93
+ "when called with a T*");
94
+ Status st = result.status();
95
+ if (st.ok()) {
96
+ PyObject* py_value = py_wrapper(result.MoveValueUnsafe());
97
+ st = CheckPyError();
98
+ if (st.ok()) {
99
+ return py_value;
100
+ }
101
+ Py_XDECREF(py_value); // should be null, but who knows
102
+ }
103
+ // Status is an error, convert it to an exception.
104
+ return internal::convert_status(st);
105
+ }
106
+
107
+ // A RAII-style helper that ensures the GIL is acquired inside a lexical block.
108
+ class ARROW_PYTHON_EXPORT PyAcquireGIL {
109
+ public:
110
+ PyAcquireGIL() : acquired_gil_(false) { acquire(); }
111
+
112
+ ~PyAcquireGIL() { release(); }
113
+
114
+ void acquire() {
115
+ if (!acquired_gil_) {
116
+ state_ = PyGILState_Ensure();
117
+ acquired_gil_ = true;
118
+ }
119
+ }
120
+
121
+ // idempotent
122
+ void release() {
123
+ if (acquired_gil_) {
124
+ PyGILState_Release(state_);
125
+ acquired_gil_ = false;
126
+ }
127
+ }
128
+
129
+ private:
130
+ bool acquired_gil_;
131
+ PyGILState_STATE state_;
132
+ ARROW_DISALLOW_COPY_AND_ASSIGN(PyAcquireGIL);
133
+ };
134
+
135
+ // A RAII-style helper that releases the GIL until the end of a lexical block
136
+ class ARROW_PYTHON_EXPORT PyReleaseGIL {
137
+ public:
138
+ PyReleaseGIL() : ptr_(PyEval_SaveThread(), &unique_ptr_deleter) {}
139
+
140
+ private:
141
+ static void unique_ptr_deleter(PyThreadState* state) {
142
+ if (state) {
143
+ PyEval_RestoreThread(state);
144
+ }
145
+ }
146
+ std::unique_ptr<PyThreadState, decltype(&unique_ptr_deleter)> ptr_;
147
+ };
148
+
149
+ // A helper to call safely into the Python interpreter from arbitrary C++ code.
150
+ // The GIL is acquired, and the current thread's error status is preserved.
151
+ template <typename Function>
152
+ auto SafeCallIntoPython(Function&& func) -> decltype(func()) {
153
+ PyAcquireGIL lock;
154
+ PyObject* exc_type;
155
+ PyObject* exc_value;
156
+ PyObject* exc_traceback;
157
+ PyErr_Fetch(&exc_type, &exc_value, &exc_traceback);
158
+ auto maybe_status = std::forward<Function>(func)();
159
+ // If the return Status is a "Python error", the current Python error status
160
+ // describes the error and shouldn't be clobbered.
161
+ if (!IsPyError(::arrow::internal::GenericToStatus(maybe_status)) &&
162
+ exc_type != NULLPTR) {
163
+ PyErr_Restore(exc_type, exc_value, exc_traceback);
164
+ }
165
+ return maybe_status;
166
+ }
167
+
168
+ template <typename Function>
169
+ auto SafeCallIntoPythonVoid(Function&& func) -> decltype(func()) {
170
+ PyAcquireGIL lock;
171
+ PyObject* exc_type;
172
+ PyObject* exc_value;
173
+ PyObject* exc_traceback;
174
+ PyErr_Fetch(&exc_type, &exc_value, &exc_traceback);
175
+ func();
176
+ if (exc_type != NULLPTR) {
177
+ PyErr_Restore(exc_type, exc_value, exc_traceback);
178
+ }
179
+ }
180
+
181
+ // A RAII primitive that DECREFs the underlying PyObject* when it
182
+ // goes out of scope.
183
+ class ARROW_PYTHON_EXPORT OwnedRef {
184
+ public:
185
+ OwnedRef() : obj_(NULLPTR) {}
186
+ OwnedRef(OwnedRef&& other) : OwnedRef(other.detach()) {}
187
+ explicit OwnedRef(PyObject* obj) : obj_(obj) {}
188
+
189
+ OwnedRef& operator=(OwnedRef&& other) {
190
+ obj_ = other.detach();
191
+ return *this;
192
+ }
193
+
194
+ ~OwnedRef() {
195
+ // GH-38626: destructor may be called after the Python interpreter is finalized.
196
+ if (Py_IsInitialized()) {
197
+ reset();
198
+ }
199
+ }
200
+
201
+ void reset(PyObject* obj) {
202
+ Py_XDECREF(obj_);
203
+ obj_ = obj;
204
+ }
205
+
206
+ void reset() { reset(NULLPTR); }
207
+
208
+ PyObject* detach() {
209
+ PyObject* result = obj_;
210
+ obj_ = NULLPTR;
211
+ return result;
212
+ }
213
+
214
+ PyObject* obj() const { return obj_; }
215
+
216
+ PyObject** ref() { return &obj_; }
217
+
218
+ operator bool() const { return obj_ != NULLPTR; }
219
+
220
+ private:
221
+ ARROW_DISALLOW_COPY_AND_ASSIGN(OwnedRef);
222
+
223
+ PyObject* obj_;
224
+ };
225
+
226
+ // Same as OwnedRef, but ensures the GIL is taken when it goes out of scope.
227
+ // This is for situations where the GIL is not always known to be held
228
+ // (e.g. if it is released in the middle of a function for performance reasons)
229
+ class ARROW_PYTHON_EXPORT OwnedRefNoGIL : public OwnedRef {
230
+ public:
231
+ OwnedRefNoGIL() : OwnedRef() {}
232
+ OwnedRefNoGIL(OwnedRefNoGIL&& other) : OwnedRef(other.detach()) {}
233
+ explicit OwnedRefNoGIL(PyObject* obj) : OwnedRef(obj) {}
234
+
235
+ ~OwnedRefNoGIL() {
236
+ // GH-38626: destructor may be called after the Python interpreter is finalized.
237
+ if (Py_IsInitialized() && obj() != NULLPTR) {
238
+ PyAcquireGIL lock;
239
+ reset();
240
+ }
241
+ }
242
+ };
243
+
244
+ template <template <typename...> typename SmartPtr, typename... Ts>
245
+ class SmartPtrNoGIL : public SmartPtr<Ts...> {
246
+ using Base = SmartPtr<Ts...>;
247
+
248
+ public:
249
+ template <typename... Args>
250
+ SmartPtrNoGIL(Args&&... args) : Base(std::forward<Args>(args)...) {}
251
+
252
+ ~SmartPtrNoGIL() { reset(); }
253
+
254
+ template <typename... Args>
255
+ void reset(Args&&... args) {
256
+ auto release_guard = optional_gil_release();
257
+ Base::reset(std::forward<Args>(args)...);
258
+ }
259
+
260
+ template <typename V>
261
+ SmartPtrNoGIL& operator=(V&& v) {
262
+ auto release_guard = optional_gil_release();
263
+ Base::operator=(std::forward<V>(v));
264
+ return *this;
265
+ }
266
+
267
+ private:
268
+ // Only release the GIL if we own an object *and* the Python runtime is
269
+ // valid *and* the GIL is held.
270
+ std::optional<PyReleaseGIL> optional_gil_release() const {
271
+ if (this->get() != nullptr && Py_IsInitialized() && PyGILState_Check()) {
272
+ return PyReleaseGIL();
273
+ }
274
+ return {};
275
+ }
276
+ };
277
+
278
+ /// \brief A std::shared_ptr<T, ...> subclass that releases the GIL when destroying T
279
+ template <typename... Ts>
280
+ using SharedPtrNoGIL = SmartPtrNoGIL<std::shared_ptr, Ts...>;
281
+
282
+ /// \brief A std::unique_ptr<T, ...> subclass that releases the GIL when destroying T
283
+ template <typename... Ts>
284
+ using UniquePtrNoGIL = SmartPtrNoGIL<std::unique_ptr, Ts...>;
285
+
286
+ template <typename Fn>
287
+ struct BoundFunction;
288
+
289
+ template <typename... Args>
290
+ struct BoundFunction<void(PyObject*, Args...)> {
291
+ // We bind `cdef void fn(object, ...)` to get a `Status(...)`
292
+ // where the Status contains any Python error raised by `fn`
293
+ using Unbound = void(PyObject*, Args...);
294
+ using Bound = Status(Args...);
295
+
296
+ BoundFunction(Unbound* unbound, PyObject* bound_arg)
297
+ : unbound_(unbound), bound_arg_(bound_arg) {}
298
+
299
+ Status Invoke(Args... args) const {
300
+ PyAcquireGIL lock;
301
+ unbound_(bound_arg_.obj(), std::forward<Args>(args)...);
302
+ RETURN_IF_PYERROR();
303
+ return Status::OK();
304
+ }
305
+
306
+ Unbound* unbound_;
307
+ OwnedRefNoGIL bound_arg_;
308
+ };
309
+
310
+ template <typename Return, typename... Args>
311
+ struct BoundFunction<Return(PyObject*, Args...)> {
312
+ // We bind `cdef Return fn(object, ...)` to get a `Result<Return>(...)`
313
+ // where the Result contains any Python error raised by `fn` or the
314
+ // return value from `fn`.
315
+ using Unbound = Return(PyObject*, Args...);
316
+ using Bound = Result<Return>(Args...);
317
+
318
+ BoundFunction(Unbound* unbound, PyObject* bound_arg)
319
+ : unbound_(unbound), bound_arg_(bound_arg) {}
320
+
321
+ Result<Return> Invoke(Args... args) const {
322
+ PyAcquireGIL lock;
323
+ Return ret = unbound_(bound_arg_.obj(), std::forward<Args>(args)...);
324
+ RETURN_IF_PYERROR();
325
+ return ret;
326
+ }
327
+
328
+ Unbound* unbound_;
329
+ OwnedRefNoGIL bound_arg_;
330
+ };
331
+
332
+ template <typename OutFn, typename Return, typename... Args>
333
+ std::function<OutFn> BindFunction(Return (*unbound)(PyObject*, Args...),
334
+ PyObject* bound_arg) {
335
+ using Fn = BoundFunction<Return(PyObject*, Args...)>;
336
+
337
+ static_assert(std::is_same<typename Fn::Bound, OutFn>::value,
338
+ "requested bound function of unsupported type");
339
+
340
+ Py_XINCREF(bound_arg);
341
+ auto bound_fn = std::make_shared<Fn>(unbound, bound_arg);
342
+ return
343
+ [bound_fn](Args... args) { return bound_fn->Invoke(std::forward<Args>(args)...); };
344
+ }
345
+
346
+ // A temporary conversion of a Python object to a bytes area.
347
+ struct PyBytesView {
348
+ const char* bytes;
349
+ Py_ssize_t size;
350
+ bool is_utf8;
351
+
352
+ static Result<PyBytesView> FromString(PyObject* obj, bool check_utf8 = false) {
353
+ PyBytesView self;
354
+ ARROW_RETURN_NOT_OK(self.ParseString(obj, check_utf8));
355
+ return std::move(self);
356
+ }
357
+
358
+ static Result<PyBytesView> FromUnicode(PyObject* obj) {
359
+ PyBytesView self;
360
+ ARROW_RETURN_NOT_OK(self.ParseUnicode(obj));
361
+ return std::move(self);
362
+ }
363
+
364
+ static Result<PyBytesView> FromBinary(PyObject* obj) {
365
+ PyBytesView self;
366
+ ARROW_RETURN_NOT_OK(self.ParseBinary(obj));
367
+ return std::move(self);
368
+ }
369
+
370
+ // View the given Python object as string-like, i.e. str or (utf8) bytes
371
+ Status ParseString(PyObject* obj, bool check_utf8 = false) {
372
+ if (PyUnicode_Check(obj)) {
373
+ return ParseUnicode(obj);
374
+ } else {
375
+ ARROW_RETURN_NOT_OK(ParseBinary(obj));
376
+ if (check_utf8) {
377
+ // Check the bytes are utf8 utf-8
378
+ OwnedRef decoded(PyUnicode_FromStringAndSize(bytes, size));
379
+ if (ARROW_PREDICT_TRUE(!PyErr_Occurred())) {
380
+ is_utf8 = true;
381
+ } else {
382
+ PyErr_Clear();
383
+ is_utf8 = false;
384
+ }
385
+ }
386
+ return Status::OK();
387
+ }
388
+ }
389
+
390
+ // View the given Python object as unicode string
391
+ Status ParseUnicode(PyObject* obj) {
392
+ // The utf-8 representation is cached on the unicode object
393
+ bytes = PyUnicode_AsUTF8AndSize(obj, &size);
394
+ RETURN_IF_PYERROR();
395
+ is_utf8 = true;
396
+ return Status::OK();
397
+ }
398
+
399
+ // View the given Python object as binary-like, i.e. bytes
400
+ Status ParseBinary(PyObject* obj) {
401
+ if (PyBytes_Check(obj)) {
402
+ bytes = PyBytes_AS_STRING(obj);
403
+ size = PyBytes_GET_SIZE(obj);
404
+ is_utf8 = false;
405
+ } else if (PyByteArray_Check(obj)) {
406
+ bytes = PyByteArray_AS_STRING(obj);
407
+ size = PyByteArray_GET_SIZE(obj);
408
+ is_utf8 = false;
409
+ } else if (PyMemoryView_Check(obj)) {
410
+ PyObject* ref = PyMemoryView_GetContiguous(obj, PyBUF_READ, 'C');
411
+ RETURN_IF_PYERROR();
412
+ Py_buffer* buffer = PyMemoryView_GET_BUFFER(ref);
413
+ bytes = reinterpret_cast<const char*>(buffer->buf);
414
+ size = buffer->len;
415
+ is_utf8 = false;
416
+ } else {
417
+ return Status::TypeError("Expected bytes, got a '", Py_TYPE(obj)->tp_name,
418
+ "' object");
419
+ }
420
+ return Status::OK();
421
+ }
422
+
423
+ protected:
424
+ OwnedRef ref;
425
+ };
426
+
427
+ class ARROW_PYTHON_EXPORT PyBuffer : public Buffer {
428
+ public:
429
+ /// While memoryview objects support multi-dimensional buffers, PyBuffer only supports
430
+ /// one-dimensional byte buffers.
431
+ ~PyBuffer();
432
+
433
+ static Result<std::shared_ptr<Buffer>> FromPyObject(PyObject* obj);
434
+
435
+ private:
436
+ PyBuffer();
437
+ Status Init(PyObject*);
438
+
439
+ Py_buffer py_buf_;
440
+ };
441
+
442
+ // Return the common PyArrow memory pool
443
+ ARROW_PYTHON_EXPORT void set_default_memory_pool(MemoryPool* pool);
444
+ ARROW_PYTHON_EXPORT MemoryPool* get_memory_pool();
445
+
446
+ // This is annoying: because C++11 does not allow implicit conversion of string
447
+ // literals to non-const char*, we need to go through some gymnastics to use
448
+ // PyObject_CallMethod without a lot of pain (its arguments are non-const
449
+ // char*)
450
+ template <typename... ArgTypes>
451
+ static inline PyObject* cpp_PyObject_CallMethod(PyObject* obj, const char* method_name,
452
+ const char* argspec, ArgTypes... args) {
453
+ return PyObject_CallMethod(obj, const_cast<char*>(method_name),
454
+ const_cast<char*>(argspec), args...);
455
+ }
456
+
457
+ } // namespace py
458
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/csv.h ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include <functional>
21
+ #include <memory>
22
+ #include <string>
23
+ #include <vector>
24
+
25
+ #include "arrow/csv/options.h"
26
+ #include "arrow/python/common.h"
27
+ #include "arrow/util/macros.h"
28
+
29
+ namespace arrow {
30
+ namespace py {
31
+ namespace csv {
32
+
33
+ using PyInvalidRowCallback = std::function<::arrow::csv::InvalidRowResult(
34
+ PyObject*, const ::arrow::csv::InvalidRow&)>;
35
+
36
+ ARROW_PYTHON_EXPORT
37
+ ::arrow::csv::InvalidRowHandler MakeInvalidRowHandler(PyInvalidRowCallback,
38
+ PyObject* handler);
39
+
40
+ } // namespace csv
41
+ } // namespace py
42
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/datetime.h ADDED
@@ -0,0 +1,231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include <algorithm>
21
+ #include <chrono>
22
+
23
+ #include "arrow/python/platform.h"
24
+ #include "arrow/python/visibility.h"
25
+ #include "arrow/result.h"
26
+ #include "arrow/status.h"
27
+ #include "arrow/type.h"
28
+ #include "arrow/type_fwd.h"
29
+ #include "arrow/util/int_util_overflow.h"
30
+ #include "arrow/util/logging.h"
31
+
32
+ // By default, PyDateTimeAPI is a *static* variable. This forces
33
+ // PyDateTime_IMPORT to be called in every C/C++ module using the
34
+ // C datetime API. This is error-prone and potentially costly.
35
+ // Instead, we redefine PyDateTimeAPI to point to a global variable,
36
+ // which is initialized once by calling InitDatetime().
37
+ #ifdef PYPY_VERSION
38
+ #include "datetime.h"
39
+ #else
40
+ #define PyDateTimeAPI ::arrow::py::internal::datetime_api
41
+ #endif
42
+
43
+ namespace arrow {
44
+ using internal::AddWithOverflow;
45
+ using internal::MultiplyWithOverflow;
46
+ namespace py {
47
+ namespace internal {
48
+
49
+ #ifndef PYPY_VERSION
50
+ extern PyDateTime_CAPI* datetime_api;
51
+
52
+ ARROW_PYTHON_EXPORT
53
+ void InitDatetime();
54
+ #endif
55
+
56
+ // Returns the MonthDayNano namedtuple type (increments the reference count).
57
+ ARROW_PYTHON_EXPORT
58
+ PyObject* NewMonthDayNanoTupleType();
59
+
60
+ ARROW_PYTHON_EXPORT
61
+ inline int64_t PyTime_to_us(PyObject* pytime) {
62
+ return (PyDateTime_TIME_GET_HOUR(pytime) * 3600000000LL +
63
+ PyDateTime_TIME_GET_MINUTE(pytime) * 60000000LL +
64
+ PyDateTime_TIME_GET_SECOND(pytime) * 1000000LL +
65
+ PyDateTime_TIME_GET_MICROSECOND(pytime));
66
+ }
67
+
68
+ ARROW_PYTHON_EXPORT
69
+ inline int64_t PyTime_to_s(PyObject* pytime) { return PyTime_to_us(pytime) / 1000000; }
70
+
71
+ ARROW_PYTHON_EXPORT
72
+ inline int64_t PyTime_to_ms(PyObject* pytime) { return PyTime_to_us(pytime) / 1000; }
73
+
74
+ ARROW_PYTHON_EXPORT
75
+ inline int64_t PyTime_to_ns(PyObject* pytime) { return PyTime_to_us(pytime) * 1000; }
76
+
77
+ ARROW_PYTHON_EXPORT
78
+ Status PyTime_from_int(int64_t val, const TimeUnit::type unit, PyObject** out);
79
+
80
+ ARROW_PYTHON_EXPORT
81
+ Status PyDate_from_int(int64_t val, const DateUnit unit, PyObject** out);
82
+
83
+ // WARNING: This function returns a naive datetime.
84
+ ARROW_PYTHON_EXPORT
85
+ Status PyDateTime_from_int(int64_t val, const TimeUnit::type unit, PyObject** out);
86
+
87
+ // This declaration must be the same as in filesystem/filesystem.h
88
+ using TimePoint =
89
+ std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>;
90
+
91
+ ARROW_PYTHON_EXPORT
92
+ int64_t PyDate_to_days(PyDateTime_Date* pydate);
93
+
94
+ ARROW_PYTHON_EXPORT
95
+ inline int64_t PyDate_to_s(PyDateTime_Date* pydate) {
96
+ return PyDate_to_days(pydate) * 86400LL;
97
+ }
98
+
99
+ ARROW_PYTHON_EXPORT
100
+ inline int64_t PyDate_to_ms(PyDateTime_Date* pydate) {
101
+ return PyDate_to_days(pydate) * 86400000LL;
102
+ }
103
+
104
+ ARROW_PYTHON_EXPORT
105
+ inline int64_t PyDateTime_to_s(PyDateTime_DateTime* pydatetime) {
106
+ return (PyDate_to_s(reinterpret_cast<PyDateTime_Date*>(pydatetime)) +
107
+ PyDateTime_DATE_GET_HOUR(pydatetime) * 3600LL +
108
+ PyDateTime_DATE_GET_MINUTE(pydatetime) * 60LL +
109
+ PyDateTime_DATE_GET_SECOND(pydatetime));
110
+ }
111
+
112
+ ARROW_PYTHON_EXPORT
113
+ inline int64_t PyDateTime_to_ms(PyDateTime_DateTime* pydatetime) {
114
+ return (PyDateTime_to_s(pydatetime) * 1000LL +
115
+ PyDateTime_DATE_GET_MICROSECOND(pydatetime) / 1000);
116
+ }
117
+
118
+ ARROW_PYTHON_EXPORT
119
+ inline int64_t PyDateTime_to_us(PyDateTime_DateTime* pydatetime) {
120
+ return (PyDateTime_to_s(pydatetime) * 1000000LL +
121
+ PyDateTime_DATE_GET_MICROSECOND(pydatetime));
122
+ }
123
+
124
+ ARROW_PYTHON_EXPORT
125
+ inline int64_t PyDateTime_to_ns(PyDateTime_DateTime* pydatetime) {
126
+ return PyDateTime_to_us(pydatetime) * 1000LL;
127
+ }
128
+
129
+ ARROW_PYTHON_EXPORT
130
+ inline TimePoint PyDateTime_to_TimePoint(PyDateTime_DateTime* pydatetime) {
131
+ return TimePoint(TimePoint::duration(PyDateTime_to_ns(pydatetime)));
132
+ }
133
+
134
+ ARROW_PYTHON_EXPORT
135
+ inline int64_t TimePoint_to_ns(TimePoint val) { return val.time_since_epoch().count(); }
136
+
137
+ ARROW_PYTHON_EXPORT
138
+ inline TimePoint TimePoint_from_s(double val) {
139
+ return TimePoint(TimePoint::duration(static_cast<int64_t>(1e9 * val)));
140
+ }
141
+
142
+ ARROW_PYTHON_EXPORT
143
+ inline TimePoint TimePoint_from_ns(int64_t val) {
144
+ return TimePoint(TimePoint::duration(val));
145
+ }
146
+
147
+ ARROW_PYTHON_EXPORT
148
+ inline int64_t PyDelta_to_s(PyDateTime_Delta* pytimedelta) {
149
+ return (PyDateTime_DELTA_GET_DAYS(pytimedelta) * 86400LL +
150
+ PyDateTime_DELTA_GET_SECONDS(pytimedelta));
151
+ }
152
+
153
+ ARROW_PYTHON_EXPORT
154
+ inline int64_t PyDelta_to_ms(PyDateTime_Delta* pytimedelta) {
155
+ return (PyDelta_to_s(pytimedelta) * 1000LL +
156
+ PyDateTime_DELTA_GET_MICROSECONDS(pytimedelta) / 1000);
157
+ }
158
+
159
+ ARROW_PYTHON_EXPORT
160
+ inline Result<int64_t> PyDelta_to_us(PyDateTime_Delta* pytimedelta) {
161
+ int64_t result = PyDelta_to_s(pytimedelta);
162
+ if (MultiplyWithOverflow(result, 1000000LL, &result)) {
163
+ return Status::Invalid("Timedelta too large to fit in 64-bit integer");
164
+ }
165
+ if (AddWithOverflow(result, PyDateTime_DELTA_GET_MICROSECONDS(pytimedelta), &result)) {
166
+ return Status::Invalid("Timedelta too large to fit in 64-bit integer");
167
+ }
168
+ return result;
169
+ }
170
+
171
+ ARROW_PYTHON_EXPORT
172
+ inline Result<int64_t> PyDelta_to_ns(PyDateTime_Delta* pytimedelta) {
173
+ ARROW_ASSIGN_OR_RAISE(int64_t result, PyDelta_to_us(pytimedelta));
174
+ if (MultiplyWithOverflow(result, 1000LL, &result)) {
175
+ return Status::Invalid("Timedelta too large to fit in 64-bit integer");
176
+ }
177
+ return result;
178
+ }
179
+
180
+ ARROW_PYTHON_EXPORT
181
+ Result<int64_t> PyDateTime_utcoffset_s(PyObject* pydatetime);
182
+
183
+ /// \brief Convert a time zone name into a time zone object.
184
+ ///
185
+ /// Supported input strings are:
186
+ /// * As used in the Olson time zone database (the "tz database" or
187
+ /// "tzdata"), such as "America/New_York"
188
+ /// * An absolute time zone offset of the form +XX:XX or -XX:XX, such as +07:30
189
+ /// GIL must be held when calling this method.
190
+ ARROW_PYTHON_EXPORT
191
+ Result<PyObject*> StringToTzinfo(const std::string& tz);
192
+
193
+ /// \brief Convert a time zone object to a string representation.
194
+ ///
195
+ /// The output strings are:
196
+ /// * An absolute time zone offset of the form +XX:XX or -XX:XX, such as +07:30
197
+ /// if the input object is either an instance of pytz._FixedOffset or
198
+ /// datetime.timedelta
199
+ /// * The timezone's name if the input object's tzname() method returns with a
200
+ /// non-empty timezone name such as "UTC" or "America/New_York"
201
+ ///
202
+ /// GIL must be held when calling this method.
203
+ ARROW_PYTHON_EXPORT
204
+ Result<std::string> TzinfoToString(PyObject* pytzinfo);
205
+
206
+ /// \brief Convert MonthDayNano to a python namedtuple.
207
+ ///
208
+ /// Return a named tuple (pyarrow.MonthDayNano) containing attributes
209
+ /// "months", "days", "nanoseconds" in the given order
210
+ /// with values extracted from the fields on interval.
211
+ ///
212
+ /// GIL must be held when calling this method.
213
+ ARROW_PYTHON_EXPORT
214
+ PyObject* MonthDayNanoIntervalToNamedTuple(
215
+ const MonthDayNanoIntervalType::MonthDayNanos& interval);
216
+
217
+ /// \brief Convert the given Array to a PyList object containing
218
+ /// pyarrow.MonthDayNano objects.
219
+ ARROW_PYTHON_EXPORT
220
+ Result<PyObject*> MonthDayNanoIntervalArrayToPyList(
221
+ const MonthDayNanoIntervalArray& array);
222
+
223
+ /// \brief Convert the Scalar object to a pyarrow.MonthDayNano (or None if
224
+ /// is isn't valid).
225
+ ARROW_PYTHON_EXPORT
226
+ Result<PyObject*> MonthDayNanoIntervalScalarToPyObject(
227
+ const MonthDayNanoIntervalScalar& scalar);
228
+
229
+ } // namespace internal
230
+ } // namespace py
231
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/decimal.h ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include <string>
21
+
22
+ #include "arrow/python/visibility.h"
23
+ #include "arrow/type.h"
24
+
25
+ namespace arrow {
26
+
27
+ class Decimal128;
28
+ class Decimal256;
29
+
30
+ namespace py {
31
+
32
+ class OwnedRef;
33
+
34
+ //
35
+ // Python Decimal support
36
+ //
37
+
38
+ namespace internal {
39
+
40
+ // \brief Import the Python Decimal type
41
+ ARROW_PYTHON_EXPORT
42
+ Status ImportDecimalType(OwnedRef* decimal_type);
43
+
44
+ // \brief Convert a Python Decimal object to a C++ string
45
+ // \param[in] python_decimal A Python decimal.Decimal instance
46
+ // \param[out] The string representation of the Python Decimal instance
47
+ // \return The status of the operation
48
+ ARROW_PYTHON_EXPORT
49
+ Status PythonDecimalToString(PyObject* python_decimal, std::string* out);
50
+
51
+ // \brief Convert a C++ std::string to a Python Decimal instance
52
+ // \param[in] decimal_constructor The decimal type object
53
+ // \param[in] decimal_string A decimal string
54
+ // \return An instance of decimal.Decimal
55
+ ARROW_PYTHON_EXPORT
56
+ PyObject* DecimalFromString(PyObject* decimal_constructor,
57
+ const std::string& decimal_string);
58
+
59
+ // \brief Convert a Python decimal to an Arrow Decimal128 object
60
+ // \param[in] python_decimal A Python decimal.Decimal instance
61
+ // \param[in] arrow_type An instance of arrow::DecimalType
62
+ // \param[out] out A pointer to a Decimal128
63
+ // \return The status of the operation
64
+ ARROW_PYTHON_EXPORT
65
+ Status DecimalFromPythonDecimal(PyObject* python_decimal, const DecimalType& arrow_type,
66
+ Decimal128* out);
67
+
68
+ // \brief Convert a Python object to an Arrow Decimal128 object
69
+ // \param[in] python_decimal A Python int or decimal.Decimal instance
70
+ // \param[in] arrow_type An instance of arrow::DecimalType
71
+ // \param[out] out A pointer to a Decimal128
72
+ // \return The status of the operation
73
+ ARROW_PYTHON_EXPORT
74
+ Status DecimalFromPyObject(PyObject* obj, const DecimalType& arrow_type, Decimal128* out);
75
+
76
+ // \brief Convert a Python decimal to an Arrow Decimal256 object
77
+ // \param[in] python_decimal A Python decimal.Decimal instance
78
+ // \param[in] arrow_type An instance of arrow::DecimalType
79
+ // \param[out] out A pointer to a Decimal256
80
+ // \return The status of the operation
81
+ ARROW_PYTHON_EXPORT
82
+ Status DecimalFromPythonDecimal(PyObject* python_decimal, const DecimalType& arrow_type,
83
+ Decimal256* out);
84
+
85
+ // \brief Convert a Python object to an Arrow Decimal256 object
86
+ // \param[in] python_decimal A Python int or decimal.Decimal instance
87
+ // \param[in] arrow_type An instance of arrow::DecimalType
88
+ // \param[out] out A pointer to a Decimal256
89
+ // \return The status of the operation
90
+ ARROW_PYTHON_EXPORT
91
+ Status DecimalFromPyObject(PyObject* obj, const DecimalType& arrow_type, Decimal256* out);
92
+
93
+ // \brief Check whether obj is an instance of Decimal
94
+ ARROW_PYTHON_EXPORT
95
+ bool PyDecimal_Check(PyObject* obj);
96
+
97
+ // \brief Check whether obj is nan. This function will abort the program if the argument
98
+ // is not a Decimal instance
99
+ ARROW_PYTHON_EXPORT
100
+ bool PyDecimal_ISNAN(PyObject* obj);
101
+
102
+ // \brief Helper class to track and update the precision and scale of a decimal
103
+ class ARROW_PYTHON_EXPORT DecimalMetadata {
104
+ public:
105
+ DecimalMetadata();
106
+ DecimalMetadata(int32_t precision, int32_t scale);
107
+
108
+ // \brief Adjust the precision and scale of a decimal type given a new precision and a
109
+ // new scale \param[in] suggested_precision A candidate precision \param[in]
110
+ // suggested_scale A candidate scale \return The status of the operation
111
+ Status Update(int32_t suggested_precision, int32_t suggested_scale);
112
+
113
+ // \brief A convenient interface for updating the precision and scale based on a Python
114
+ // Decimal object \param object A Python Decimal object \return The status of the
115
+ // operation
116
+ Status Update(PyObject* object);
117
+
118
+ int32_t precision() const { return precision_; }
119
+ int32_t scale() const { return scale_; }
120
+
121
+ private:
122
+ int32_t precision_;
123
+ int32_t scale_;
124
+ };
125
+
126
+ } // namespace internal
127
+ } // namespace py
128
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/deserialize.h ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include <cstdint>
21
+ #include <memory>
22
+ #include <vector>
23
+
24
+ #include "arrow/python/serialize.h"
25
+ #include "arrow/python/visibility.h"
26
+ #include "arrow/status.h"
27
+
28
+ namespace arrow {
29
+
30
+ class RecordBatch;
31
+ class Tensor;
32
+
33
+ namespace io {
34
+
35
+ class RandomAccessFile;
36
+
37
+ } // namespace io
38
+
39
+ namespace py {
40
+
41
+ struct ARROW_PYTHON_EXPORT SparseTensorCounts {
42
+ int coo;
43
+ int csr;
44
+ int csc;
45
+ int csf;
46
+ int ndim_csf;
47
+
48
+ int num_total_tensors() const { return coo + csr + csc + csf; }
49
+ int num_total_buffers() const {
50
+ return coo * 3 + csr * 4 + csc * 4 + 2 * ndim_csf + csf;
51
+ }
52
+ };
53
+
54
+ /// \brief Read serialized Python sequence from file interface using Arrow IPC
55
+ /// \param[in] src a RandomAccessFile
56
+ /// \param[out] out the reconstructed data
57
+ /// \return Status
58
+ ARROW_PYTHON_EXPORT
59
+ Status ReadSerializedObject(io::RandomAccessFile* src, SerializedPyObject* out);
60
+
61
+ /// \brief Reconstruct SerializedPyObject from representation produced by
62
+ /// SerializedPyObject::GetComponents.
63
+ ///
64
+ /// \param[in] num_tensors number of tensors in the object
65
+ /// \param[in] num_sparse_tensors number of sparse tensors in the object
66
+ /// \param[in] num_ndarrays number of numpy Ndarrays in the object
67
+ /// \param[in] num_buffers number of buffers in the object
68
+ /// \param[in] data a list containing pyarrow.Buffer instances. It must be 1 +
69
+ /// num_tensors * 2 + num_coo_tensors * 3 + num_csr_tensors * 4 + num_csc_tensors * 4 +
70
+ /// num_csf_tensors * (2 * ndim_csf + 3) + num_buffers in length
71
+ /// \param[out] out the reconstructed object
72
+ /// \return Status
73
+ ARROW_PYTHON_EXPORT
74
+ Status GetSerializedFromComponents(int num_tensors,
75
+ const SparseTensorCounts& num_sparse_tensors,
76
+ int num_ndarrays, int num_buffers, PyObject* data,
77
+ SerializedPyObject* out);
78
+
79
+ /// \brief Reconstruct Python object from Arrow-serialized representation
80
+ /// \param[in] context Serialization context which contains custom serialization
81
+ /// and deserialization callbacks. Can be any Python object with a
82
+ /// _serialize_callback method for serialization and a _deserialize_callback
83
+ /// method for deserialization. If context is None, no custom serialization
84
+ /// will be attempted.
85
+ /// \param[in] object Object to deserialize
86
+ /// \param[in] base a Python object holding the underlying data that any NumPy
87
+ /// arrays will reference, to avoid premature deallocation
88
+ /// \param[out] out The returned object
89
+ /// \return Status
90
+ /// This acquires the GIL
91
+ ARROW_PYTHON_EXPORT
92
+ Status DeserializeObject(PyObject* context, const SerializedPyObject& object,
93
+ PyObject* base, PyObject** out);
94
+
95
+ /// \brief Reconstruct Ndarray from Arrow-serialized representation
96
+ /// \param[in] object Object to deserialize
97
+ /// \param[out] out The deserialized tensor
98
+ /// \return Status
99
+ ARROW_PYTHON_EXPORT
100
+ Status DeserializeNdarray(const SerializedPyObject& object, std::shared_ptr<Tensor>* out);
101
+
102
+ ARROW_PYTHON_EXPORT
103
+ Status NdarrayFromBuffer(std::shared_ptr<Buffer> src, std::shared_ptr<Tensor>* out);
104
+
105
+ } // namespace py
106
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/extension_type.h ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include <memory>
21
+ #include <string>
22
+
23
+ #include "arrow/extension_type.h"
24
+ #include "arrow/python/common.h"
25
+ #include "arrow/python/visibility.h"
26
+ #include "arrow/util/macros.h"
27
+
28
+ namespace arrow {
29
+ namespace py {
30
+
31
+ class ARROW_PYTHON_EXPORT PyExtensionType : public ExtensionType {
32
+ public:
33
+ // Implement extensionType API
34
+ std::string extension_name() const override { return extension_name_; }
35
+
36
+ std::string ToString(bool show_metadata = false) const override;
37
+
38
+ bool ExtensionEquals(const ExtensionType& other) const override;
39
+
40
+ std::shared_ptr<Array> MakeArray(std::shared_ptr<ArrayData> data) const override;
41
+
42
+ Result<std::shared_ptr<DataType>> Deserialize(
43
+ std::shared_ptr<DataType> storage_type,
44
+ const std::string& serialized) const override;
45
+
46
+ std::string Serialize() const override;
47
+
48
+ // For use from Cython
49
+ // Assumes that `typ` is borrowed
50
+ static Status FromClass(const std::shared_ptr<DataType> storage_type,
51
+ const std::string extension_name, PyObject* typ,
52
+ std::shared_ptr<ExtensionType>* out);
53
+
54
+ // Return new ref
55
+ PyObject* GetInstance() const;
56
+ Status SetInstance(PyObject*) const;
57
+
58
+ protected:
59
+ PyExtensionType(std::shared_ptr<DataType> storage_type, PyObject* typ,
60
+ PyObject* inst = NULLPTR);
61
+ PyExtensionType(std::shared_ptr<DataType> storage_type, std::string extension_name,
62
+ PyObject* typ, PyObject* inst = NULLPTR);
63
+
64
+ std::string extension_name_;
65
+
66
+ // These fields are mutable because of two-step initialization.
67
+ mutable OwnedRefNoGIL type_class_;
68
+ // A weakref or null. Storing a strong reference to the Python extension type
69
+ // instance would create an unreclaimable reference cycle between Python and C++
70
+ // (the Python instance has to keep a strong reference to the C++ ExtensionType
71
+ // in other direction). Instead, we store a weakref to the instance.
72
+ // If the weakref is dead, we reconstruct the instance from its serialized form.
73
+ mutable OwnedRefNoGIL type_instance_;
74
+ // Empty if type_instance_ is null
75
+ mutable std::string serialized_;
76
+ };
77
+
78
+ ARROW_PYTHON_EXPORT std::string PyExtensionName();
79
+
80
+ ARROW_PYTHON_EXPORT Status RegisterPyExtensionType(const std::shared_ptr<DataType>&);
81
+
82
+ ARROW_PYTHON_EXPORT Status UnregisterPyExtensionType(const std::string& type_name);
83
+
84
+ } // namespace py
85
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/filesystem.h ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include <memory>
21
+ #include <string>
22
+ #include <vector>
23
+
24
+ #include "arrow/filesystem/filesystem.h"
25
+ #include "arrow/python/common.h"
26
+ #include "arrow/python/visibility.h"
27
+ #include "arrow/util/macros.h"
28
+
29
+ namespace arrow::py::fs {
30
+
31
+ class ARROW_PYTHON_EXPORT PyFileSystemVtable {
32
+ public:
33
+ std::function<void(PyObject*, std::string* out)> get_type_name;
34
+ std::function<bool(PyObject*, const arrow::fs::FileSystem& other)> equals;
35
+
36
+ std::function<void(PyObject*, const std::string& path, arrow::fs::FileInfo* out)>
37
+ get_file_info;
38
+ std::function<void(PyObject*, const std::vector<std::string>& paths,
39
+ std::vector<arrow::fs::FileInfo>* out)>
40
+ get_file_info_vector;
41
+ std::function<void(PyObject*, const arrow::fs::FileSelector&,
42
+ std::vector<arrow::fs::FileInfo>* out)>
43
+ get_file_info_selector;
44
+
45
+ std::function<void(PyObject*, const std::string& path, bool)> create_dir;
46
+ std::function<void(PyObject*, const std::string& path)> delete_dir;
47
+ std::function<void(PyObject*, const std::string& path, bool)> delete_dir_contents;
48
+ std::function<void(PyObject*)> delete_root_dir_contents;
49
+ std::function<void(PyObject*, const std::string& path)> delete_file;
50
+ std::function<void(PyObject*, const std::string& src, const std::string& dest)> move;
51
+ std::function<void(PyObject*, const std::string& src, const std::string& dest)>
52
+ copy_file;
53
+
54
+ std::function<void(PyObject*, const std::string& path,
55
+ std::shared_ptr<io::InputStream>* out)>
56
+ open_input_stream;
57
+ std::function<void(PyObject*, const std::string& path,
58
+ std::shared_ptr<io::RandomAccessFile>* out)>
59
+ open_input_file;
60
+ std::function<void(PyObject*, const std::string& path,
61
+ const std::shared_ptr<const KeyValueMetadata>&,
62
+ std::shared_ptr<io::OutputStream>* out)>
63
+ open_output_stream;
64
+ std::function<void(PyObject*, const std::string& path,
65
+ const std::shared_ptr<const KeyValueMetadata>&,
66
+ std::shared_ptr<io::OutputStream>* out)>
67
+ open_append_stream;
68
+
69
+ std::function<void(PyObject*, const std::string& path, std::string* out)>
70
+ normalize_path;
71
+ };
72
+
73
+ class ARROW_PYTHON_EXPORT PyFileSystem : public arrow::fs::FileSystem {
74
+ public:
75
+ PyFileSystem(PyObject* handler, PyFileSystemVtable vtable);
76
+ ~PyFileSystem() override;
77
+
78
+ static std::shared_ptr<PyFileSystem> Make(PyObject* handler, PyFileSystemVtable vtable);
79
+
80
+ std::string type_name() const override;
81
+
82
+ bool Equals(const FileSystem& other) const override;
83
+
84
+ /// \cond FALSE
85
+ using FileSystem::CreateDir;
86
+ using FileSystem::DeleteDirContents;
87
+ using FileSystem::GetFileInfo;
88
+ using FileSystem::OpenAppendStream;
89
+ using FileSystem::OpenOutputStream;
90
+ /// \endcond
91
+
92
+ Result<arrow::fs::FileInfo> GetFileInfo(const std::string& path) override;
93
+ Result<std::vector<arrow::fs::FileInfo>> GetFileInfo(
94
+ const std::vector<std::string>& paths) override;
95
+ Result<std::vector<arrow::fs::FileInfo>> GetFileInfo(
96
+ const arrow::fs::FileSelector& select) override;
97
+
98
+ Status CreateDir(const std::string& path, bool recursive) override;
99
+
100
+ Status DeleteDir(const std::string& path) override;
101
+ Status DeleteDirContents(const std::string& path, bool missing_dir_ok) override;
102
+ Status DeleteRootDirContents() override;
103
+
104
+ Status DeleteFile(const std::string& path) override;
105
+
106
+ Status Move(const std::string& src, const std::string& dest) override;
107
+
108
+ Status CopyFile(const std::string& src, const std::string& dest) override;
109
+
110
+ Result<std::shared_ptr<io::InputStream>> OpenInputStream(
111
+ const std::string& path) override;
112
+ Result<std::shared_ptr<io::RandomAccessFile>> OpenInputFile(
113
+ const std::string& path) override;
114
+ Result<std::shared_ptr<io::OutputStream>> OpenOutputStream(
115
+ const std::string& path,
116
+ const std::shared_ptr<const KeyValueMetadata>& metadata) override;
117
+ Result<std::shared_ptr<io::OutputStream>> OpenAppendStream(
118
+ const std::string& path,
119
+ const std::shared_ptr<const KeyValueMetadata>& metadata) override;
120
+
121
+ Result<std::string> NormalizePath(std::string path) override;
122
+
123
+ PyObject* handler() const { return handler_.obj(); }
124
+
125
+ private:
126
+ OwnedRefNoGIL handler_;
127
+ PyFileSystemVtable vtable_;
128
+ };
129
+
130
+ } // namespace arrow::py::fs
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/flight.h ADDED
@@ -0,0 +1,350 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include <memory>
21
+ #include <string>
22
+ #include <vector>
23
+
24
+ #include "arrow/flight/api.h"
25
+ #include "arrow/ipc/dictionary.h"
26
+ #include "arrow/python/common.h"
27
+
28
+ #if defined(_WIN32) || defined(__CYGWIN__) // Windows
29
+ #if defined(_MSC_VER)
30
+ #pragma warning(disable : 4251)
31
+ #else
32
+ #pragma GCC diagnostic ignored "-Wattributes"
33
+ #endif
34
+
35
+ #ifdef ARROW_PYTHON_STATIC
36
+ #define ARROW_PYFLIGHT_EXPORT
37
+ #elif defined(ARROW_PYFLIGHT_EXPORTING)
38
+ #define ARROW_PYFLIGHT_EXPORT __declspec(dllexport)
39
+ #else
40
+ #define ARROW_PYFLIGHT_EXPORT __declspec(dllimport)
41
+ #endif
42
+
43
+ #else // Not Windows
44
+ #ifndef ARROW_PYFLIGHT_EXPORT
45
+ #define ARROW_PYFLIGHT_EXPORT __attribute__((visibility("default")))
46
+ #endif
47
+ #endif // Non-Windows
48
+
49
+ namespace arrow {
50
+
51
+ namespace py {
52
+
53
+ namespace flight {
54
+
55
+ ARROW_PYFLIGHT_EXPORT
56
+ extern const char* kPyServerMiddlewareName;
57
+
58
+ /// \brief A table of function pointers for calling from C++ into
59
+ /// Python.
60
+ class ARROW_PYFLIGHT_EXPORT PyFlightServerVtable {
61
+ public:
62
+ std::function<Status(PyObject*, const arrow::flight::ServerCallContext&,
63
+ const arrow::flight::Criteria*,
64
+ std::unique_ptr<arrow::flight::FlightListing>*)>
65
+ list_flights;
66
+ std::function<Status(PyObject*, const arrow::flight::ServerCallContext&,
67
+ const arrow::flight::FlightDescriptor&,
68
+ std::unique_ptr<arrow::flight::FlightInfo>*)>
69
+ get_flight_info;
70
+ std::function<Status(PyObject*, const arrow::flight::ServerCallContext&,
71
+ const arrow::flight::FlightDescriptor&,
72
+ std::unique_ptr<arrow::flight::SchemaResult>*)>
73
+ get_schema;
74
+ std::function<Status(PyObject*, const arrow::flight::ServerCallContext&,
75
+ const arrow::flight::Ticket&,
76
+ std::unique_ptr<arrow::flight::FlightDataStream>*)>
77
+ do_get;
78
+ std::function<Status(PyObject*, const arrow::flight::ServerCallContext&,
79
+ std::unique_ptr<arrow::flight::FlightMessageReader>,
80
+ std::unique_ptr<arrow::flight::FlightMetadataWriter>)>
81
+ do_put;
82
+ std::function<Status(PyObject*, const arrow::flight::ServerCallContext&,
83
+ std::unique_ptr<arrow::flight::FlightMessageReader>,
84
+ std::unique_ptr<arrow::flight::FlightMessageWriter>)>
85
+ do_exchange;
86
+ std::function<Status(PyObject*, const arrow::flight::ServerCallContext&,
87
+ const arrow::flight::Action&,
88
+ std::unique_ptr<arrow::flight::ResultStream>*)>
89
+ do_action;
90
+ std::function<Status(PyObject*, const arrow::flight::ServerCallContext&,
91
+ std::vector<arrow::flight::ActionType>*)>
92
+ list_actions;
93
+ };
94
+
95
+ class ARROW_PYFLIGHT_EXPORT PyServerAuthHandlerVtable {
96
+ public:
97
+ std::function<Status(PyObject*, arrow::flight::ServerAuthSender*,
98
+ arrow::flight::ServerAuthReader*)>
99
+ authenticate;
100
+ std::function<Status(PyObject*, const std::string&, std::string*)> is_valid;
101
+ };
102
+
103
+ class ARROW_PYFLIGHT_EXPORT PyClientAuthHandlerVtable {
104
+ public:
105
+ std::function<Status(PyObject*, arrow::flight::ClientAuthSender*,
106
+ arrow::flight::ClientAuthReader*)>
107
+ authenticate;
108
+ std::function<Status(PyObject*, std::string*)> get_token;
109
+ };
110
+
111
+ /// \brief A helper to implement an auth mechanism in Python.
112
+ class ARROW_PYFLIGHT_EXPORT PyServerAuthHandler
113
+ : public arrow::flight::ServerAuthHandler {
114
+ public:
115
+ explicit PyServerAuthHandler(PyObject* handler,
116
+ const PyServerAuthHandlerVtable& vtable);
117
+ Status Authenticate(arrow::flight::ServerAuthSender* outgoing,
118
+ arrow::flight::ServerAuthReader* incoming) override;
119
+ Status IsValid(const std::string& token, std::string* peer_identity) override;
120
+
121
+ private:
122
+ OwnedRefNoGIL handler_;
123
+ PyServerAuthHandlerVtable vtable_;
124
+ };
125
+
126
+ /// \brief A helper to implement an auth mechanism in Python.
127
+ class ARROW_PYFLIGHT_EXPORT PyClientAuthHandler
128
+ : public arrow::flight::ClientAuthHandler {
129
+ public:
130
+ explicit PyClientAuthHandler(PyObject* handler,
131
+ const PyClientAuthHandlerVtable& vtable);
132
+ Status Authenticate(arrow::flight::ClientAuthSender* outgoing,
133
+ arrow::flight::ClientAuthReader* incoming) override;
134
+ Status GetToken(std::string* token) override;
135
+
136
+ private:
137
+ OwnedRefNoGIL handler_;
138
+ PyClientAuthHandlerVtable vtable_;
139
+ };
140
+
141
+ class ARROW_PYFLIGHT_EXPORT PyFlightServer : public arrow::flight::FlightServerBase {
142
+ public:
143
+ explicit PyFlightServer(PyObject* server, const PyFlightServerVtable& vtable);
144
+
145
+ // Like Serve(), but set up signals and invoke Python signal handlers
146
+ // if necessary. This function may return with a Python exception set.
147
+ Status ServeWithSignals();
148
+
149
+ Status ListFlights(const arrow::flight::ServerCallContext& context,
150
+ const arrow::flight::Criteria* criteria,
151
+ std::unique_ptr<arrow::flight::FlightListing>* listings) override;
152
+ Status GetFlightInfo(const arrow::flight::ServerCallContext& context,
153
+ const arrow::flight::FlightDescriptor& request,
154
+ std::unique_ptr<arrow::flight::FlightInfo>* info) override;
155
+ Status GetSchema(const arrow::flight::ServerCallContext& context,
156
+ const arrow::flight::FlightDescriptor& request,
157
+ std::unique_ptr<arrow::flight::SchemaResult>* result) override;
158
+ Status DoGet(const arrow::flight::ServerCallContext& context,
159
+ const arrow::flight::Ticket& request,
160
+ std::unique_ptr<arrow::flight::FlightDataStream>* stream) override;
161
+ Status DoPut(const arrow::flight::ServerCallContext& context,
162
+ std::unique_ptr<arrow::flight::FlightMessageReader> reader,
163
+ std::unique_ptr<arrow::flight::FlightMetadataWriter> writer) override;
164
+ Status DoExchange(const arrow::flight::ServerCallContext& context,
165
+ std::unique_ptr<arrow::flight::FlightMessageReader> reader,
166
+ std::unique_ptr<arrow::flight::FlightMessageWriter> writer) override;
167
+ Status DoAction(const arrow::flight::ServerCallContext& context,
168
+ const arrow::flight::Action& action,
169
+ std::unique_ptr<arrow::flight::ResultStream>* result) override;
170
+ Status ListActions(const arrow::flight::ServerCallContext& context,
171
+ std::vector<arrow::flight::ActionType>* actions) override;
172
+
173
+ private:
174
+ OwnedRefNoGIL server_;
175
+ PyFlightServerVtable vtable_;
176
+ };
177
+
178
+ /// \brief A callback that obtains the next result from a Flight action.
179
+ typedef std::function<Status(PyObject*, std::unique_ptr<arrow::flight::Result>*)>
180
+ PyFlightResultStreamCallback;
181
+
182
+ /// \brief A ResultStream built around a Python callback.
183
+ class ARROW_PYFLIGHT_EXPORT PyFlightResultStream : public arrow::flight::ResultStream {
184
+ public:
185
+ /// \brief Construct a FlightResultStream from a Python object and callback.
186
+ /// Must only be called while holding the GIL.
187
+ explicit PyFlightResultStream(PyObject* generator,
188
+ PyFlightResultStreamCallback callback);
189
+ arrow::Result<std::unique_ptr<arrow::flight::Result>> Next() override;
190
+
191
+ private:
192
+ OwnedRefNoGIL generator_;
193
+ PyFlightResultStreamCallback callback_;
194
+ };
195
+
196
+ /// \brief A wrapper around a FlightDataStream that keeps alive a
197
+ /// Python object backing it.
198
+ class ARROW_PYFLIGHT_EXPORT PyFlightDataStream : public arrow::flight::FlightDataStream {
199
+ public:
200
+ /// \brief Construct a FlightDataStream from a Python object and underlying stream.
201
+ /// Must only be called while holding the GIL.
202
+ explicit PyFlightDataStream(PyObject* data_source,
203
+ std::unique_ptr<arrow::flight::FlightDataStream> stream);
204
+
205
+ std::shared_ptr<Schema> schema() override;
206
+ arrow::Result<arrow::flight::FlightPayload> GetSchemaPayload() override;
207
+ arrow::Result<arrow::flight::FlightPayload> Next() override;
208
+
209
+ private:
210
+ OwnedRefNoGIL data_source_;
211
+ std::unique_ptr<arrow::flight::FlightDataStream> stream_;
212
+ };
213
+
214
+ class ARROW_PYFLIGHT_EXPORT PyServerMiddlewareFactory
215
+ : public arrow::flight::ServerMiddlewareFactory {
216
+ public:
217
+ /// \brief A callback to create the middleware instance in Python
218
+ typedef std::function<Status(
219
+ PyObject*, const arrow::flight::CallInfo& info,
220
+ const arrow::flight::CallHeaders& incoming_headers,
221
+ std::shared_ptr<arrow::flight::ServerMiddleware>* middleware)>
222
+ StartCallCallback;
223
+
224
+ /// \brief Must only be called while holding the GIL.
225
+ explicit PyServerMiddlewareFactory(PyObject* factory, StartCallCallback start_call);
226
+
227
+ Status StartCall(const arrow::flight::CallInfo& info,
228
+ const arrow::flight::CallHeaders& incoming_headers,
229
+ std::shared_ptr<arrow::flight::ServerMiddleware>* middleware) override;
230
+
231
+ private:
232
+ OwnedRefNoGIL factory_;
233
+ StartCallCallback start_call_;
234
+ };
235
+
236
+ class ARROW_PYFLIGHT_EXPORT PyServerMiddleware : public arrow::flight::ServerMiddleware {
237
+ public:
238
+ typedef std::function<Status(PyObject*,
239
+ arrow::flight::AddCallHeaders* outgoing_headers)>
240
+ SendingHeadersCallback;
241
+ typedef std::function<Status(PyObject*, const Status& status)> CallCompletedCallback;
242
+
243
+ struct Vtable {
244
+ SendingHeadersCallback sending_headers;
245
+ CallCompletedCallback call_completed;
246
+ };
247
+
248
+ /// \brief Must only be called while holding the GIL.
249
+ explicit PyServerMiddleware(PyObject* middleware, Vtable vtable);
250
+
251
+ void SendingHeaders(arrow::flight::AddCallHeaders* outgoing_headers) override;
252
+ void CallCompleted(const Status& status) override;
253
+ std::string name() const override;
254
+ /// \brief Get the underlying Python object.
255
+ PyObject* py_object() const;
256
+
257
+ private:
258
+ OwnedRefNoGIL middleware_;
259
+ Vtable vtable_;
260
+ };
261
+
262
+ class ARROW_PYFLIGHT_EXPORT PyClientMiddlewareFactory
263
+ : public arrow::flight::ClientMiddlewareFactory {
264
+ public:
265
+ /// \brief A callback to create the middleware instance in Python
266
+ typedef std::function<Status(
267
+ PyObject*, const arrow::flight::CallInfo& info,
268
+ std::unique_ptr<arrow::flight::ClientMiddleware>* middleware)>
269
+ StartCallCallback;
270
+
271
+ /// \brief Must only be called while holding the GIL.
272
+ explicit PyClientMiddlewareFactory(PyObject* factory, StartCallCallback start_call);
273
+
274
+ void StartCall(const arrow::flight::CallInfo& info,
275
+ std::unique_ptr<arrow::flight::ClientMiddleware>* middleware) override;
276
+
277
+ private:
278
+ OwnedRefNoGIL factory_;
279
+ StartCallCallback start_call_;
280
+ };
281
+
282
+ class ARROW_PYFLIGHT_EXPORT PyClientMiddleware : public arrow::flight::ClientMiddleware {
283
+ public:
284
+ typedef std::function<Status(PyObject*,
285
+ arrow::flight::AddCallHeaders* outgoing_headers)>
286
+ SendingHeadersCallback;
287
+ typedef std::function<Status(PyObject*,
288
+ const arrow::flight::CallHeaders& incoming_headers)>
289
+ ReceivedHeadersCallback;
290
+ typedef std::function<Status(PyObject*, const Status& status)> CallCompletedCallback;
291
+
292
+ struct Vtable {
293
+ SendingHeadersCallback sending_headers;
294
+ ReceivedHeadersCallback received_headers;
295
+ CallCompletedCallback call_completed;
296
+ };
297
+
298
+ /// \brief Must only be called while holding the GIL.
299
+ explicit PyClientMiddleware(PyObject* factory, Vtable vtable);
300
+
301
+ void SendingHeaders(arrow::flight::AddCallHeaders* outgoing_headers) override;
302
+ void ReceivedHeaders(const arrow::flight::CallHeaders& incoming_headers) override;
303
+ void CallCompleted(const Status& status) override;
304
+
305
+ private:
306
+ OwnedRefNoGIL middleware_;
307
+ Vtable vtable_;
308
+ };
309
+
310
+ /// \brief A callback that obtains the next payload from a Flight result stream.
311
+ typedef std::function<Status(PyObject*, arrow::flight::FlightPayload*)>
312
+ PyGeneratorFlightDataStreamCallback;
313
+
314
+ /// \brief A FlightDataStream built around a Python callback.
315
+ class ARROW_PYFLIGHT_EXPORT PyGeneratorFlightDataStream
316
+ : public arrow::flight::FlightDataStream {
317
+ public:
318
+ /// \brief Construct a FlightDataStream from a Python object and underlying stream.
319
+ /// Must only be called while holding the GIL.
320
+ explicit PyGeneratorFlightDataStream(PyObject* generator,
321
+ std::shared_ptr<arrow::Schema> schema,
322
+ PyGeneratorFlightDataStreamCallback callback,
323
+ const ipc::IpcWriteOptions& options);
324
+ std::shared_ptr<Schema> schema() override;
325
+ arrow::Result<arrow::flight::FlightPayload> GetSchemaPayload() override;
326
+ arrow::Result<arrow::flight::FlightPayload> Next() override;
327
+
328
+ private:
329
+ OwnedRefNoGIL generator_;
330
+ std::shared_ptr<arrow::Schema> schema_;
331
+ ipc::DictionaryFieldMapper mapper_;
332
+ ipc::IpcWriteOptions options_;
333
+ PyGeneratorFlightDataStreamCallback callback_;
334
+ };
335
+
336
+ ARROW_PYFLIGHT_EXPORT
337
+ Status CreateFlightInfo(const std::shared_ptr<arrow::Schema>& schema,
338
+ const arrow::flight::FlightDescriptor& descriptor,
339
+ const std::vector<arrow::flight::FlightEndpoint>& endpoints,
340
+ int64_t total_records, int64_t total_bytes,
341
+ std::unique_ptr<arrow::flight::FlightInfo>* out);
342
+
343
+ /// \brief Create a SchemaResult from schema.
344
+ ARROW_PYFLIGHT_EXPORT
345
+ Status CreateSchemaResult(const std::shared_ptr<arrow::Schema>& schema,
346
+ std::unique_ptr<arrow::flight::SchemaResult>* out);
347
+
348
+ } // namespace flight
349
+ } // namespace py
350
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/gdb.h ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include "arrow/python/visibility.h"
21
+
22
+ namespace arrow {
23
+ namespace gdb {
24
+
25
+ ARROW_PYTHON_EXPORT
26
+ void TestSession();
27
+
28
+ } // namespace gdb
29
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/helpers.h ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include "arrow/python/platform.h"
21
+
22
+ #include <limits>
23
+ #include <memory>
24
+ #include <string>
25
+ #include <utility>
26
+
27
+ #include "arrow/python/numpy_interop.h"
28
+
29
+ #include <numpy/halffloat.h>
30
+
31
+ #include "arrow/python/visibility.h"
32
+ #include "arrow/type.h"
33
+ #include "arrow/util/macros.h"
34
+
35
+ namespace arrow {
36
+
37
+ namespace py {
38
+
39
+ class OwnedRef;
40
+
41
+ // \brief Get an arrow DataType instance from Arrow's Type::type enum
42
+ // \param[in] type One of the values of Arrow's Type::type enum
43
+ // \return A shared pointer to DataType
44
+ ARROW_PYTHON_EXPORT std::shared_ptr<DataType> GetPrimitiveType(Type::type type);
45
+
46
+ // \brief Construct a np.float16 object from a npy_half value.
47
+ ARROW_PYTHON_EXPORT PyObject* PyHalf_FromHalf(npy_half value);
48
+
49
+ // \brief Convert a Python object to a npy_half value.
50
+ ARROW_PYTHON_EXPORT Status PyFloat_AsHalf(PyObject* obj, npy_half* out);
51
+
52
+ namespace internal {
53
+
54
+ // \brief Check that a Python module has been already imported
55
+ // \param[in] module_name The name of the module
56
+ Result<bool> IsModuleImported(const std::string& module_name);
57
+
58
+ // \brief Import a Python module
59
+ // \param[in] module_name The name of the module
60
+ // \param[out] ref The OwnedRef containing the module PyObject*
61
+ ARROW_PYTHON_EXPORT
62
+ Status ImportModule(const std::string& module_name, OwnedRef* ref);
63
+
64
+ // \brief Import an object from a Python module
65
+ // \param[in] module A Python module
66
+ // \param[in] name The name of the object to import
67
+ // \param[out] ref The OwnedRef containing the \c name attribute of the Python module \c
68
+ // module
69
+ ARROW_PYTHON_EXPORT
70
+ Status ImportFromModule(PyObject* module, const std::string& name, OwnedRef* ref);
71
+
72
+ // \brief Check whether obj is an integer, independent of Python versions.
73
+ inline bool IsPyInteger(PyObject* obj) { return PyLong_Check(obj); }
74
+
75
+ // \brief Import symbols from pandas that we need for various type-checking,
76
+ // like pandas.NaT or pandas.NA
77
+ void InitPandasStaticData();
78
+
79
+ // \brief Use pandas missing value semantics to check if a value is null
80
+ ARROW_PYTHON_EXPORT
81
+ bool PandasObjectIsNull(PyObject* obj);
82
+
83
+ // \brief Check that obj is a pandas.Timedelta instance
84
+ ARROW_PYTHON_EXPORT
85
+ bool IsPandasTimedelta(PyObject* obj);
86
+
87
+ // \brief Check that obj is a pandas.Timestamp instance
88
+ bool IsPandasTimestamp(PyObject* obj);
89
+
90
+ // \brief Returned a borrowed reference to the pandas.tseries.offsets.DateOffset
91
+ PyObject* BorrowPandasDataOffsetType();
92
+
93
+ // \brief Check whether obj is a floating-point NaN
94
+ ARROW_PYTHON_EXPORT
95
+ bool PyFloat_IsNaN(PyObject* obj);
96
+
97
+ inline bool IsPyBinary(PyObject* obj) {
98
+ return PyBytes_Check(obj) || PyByteArray_Check(obj) || PyMemoryView_Check(obj);
99
+ }
100
+
101
+ // \brief Convert a Python integer into a C integer
102
+ // \param[in] obj A Python integer
103
+ // \param[out] out A pointer to a C integer to hold the result of the conversion
104
+ // \return The status of the operation
105
+ template <typename Int>
106
+ Status CIntFromPython(PyObject* obj, Int* out, const std::string& overflow_message = "");
107
+
108
+ // \brief Convert a Python unicode string to a std::string
109
+ ARROW_PYTHON_EXPORT
110
+ Status PyUnicode_AsStdString(PyObject* obj, std::string* out);
111
+
112
+ // \brief Convert a Python bytes object to a std::string
113
+ ARROW_PYTHON_EXPORT
114
+ std::string PyBytes_AsStdString(PyObject* obj);
115
+
116
+ // \brief Call str() on the given object and return the result as a std::string
117
+ ARROW_PYTHON_EXPORT
118
+ Status PyObject_StdStringStr(PyObject* obj, std::string* out);
119
+
120
+ // \brief Return the repr() of the given object (always succeeds)
121
+ ARROW_PYTHON_EXPORT
122
+ std::string PyObject_StdStringRepr(PyObject* obj);
123
+
124
+ // \brief Cast the given size to int32_t, with error checking
125
+ inline Status CastSize(Py_ssize_t size, int32_t* out,
126
+ const char* error_msg = "Maximum size exceeded (2GB)") {
127
+ // size is assumed to be positive
128
+ if (size > std::numeric_limits<int32_t>::max()) {
129
+ return Status::Invalid(error_msg);
130
+ }
131
+ *out = static_cast<int32_t>(size);
132
+ return Status::OK();
133
+ }
134
+
135
+ inline Status CastSize(Py_ssize_t size, int64_t* out, const char* error_msg = NULLPTR) {
136
+ // size is assumed to be positive
137
+ *out = static_cast<int64_t>(size);
138
+ return Status::OK();
139
+ }
140
+
141
+ // \brief Print the Python object's __str__ form along with the passed error
142
+ // message
143
+ ARROW_PYTHON_EXPORT
144
+ Status InvalidValue(PyObject* obj, const std::string& why);
145
+
146
+ ARROW_PYTHON_EXPORT
147
+ Status InvalidType(PyObject* obj, const std::string& why);
148
+
149
+ ARROW_PYTHON_EXPORT
150
+ Status IntegerScalarToDoubleSafe(PyObject* obj, double* result);
151
+ ARROW_PYTHON_EXPORT
152
+ Status IntegerScalarToFloat32Safe(PyObject* obj, float* result);
153
+
154
+ // \brief Print Python object __repr__
155
+ void DebugPrint(PyObject* obj);
156
+
157
+ } // namespace internal
158
+ } // namespace py
159
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/inference.h ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 CPython built-in data structures and Arrow
19
+ // data structures
20
+
21
+ #pragma once
22
+
23
+ #include "arrow/python/platform.h"
24
+
25
+ #include <memory>
26
+
27
+ #include "arrow/python/visibility.h"
28
+ #include "arrow/type.h"
29
+ #include "arrow/util/macros.h"
30
+
31
+ #include "common.h"
32
+
33
+ namespace arrow {
34
+
35
+ class Array;
36
+ class Status;
37
+
38
+ namespace py {
39
+
40
+ // These functions take a sequence input, not arbitrary iterables
41
+
42
+ /// \brief Infer Arrow type from a Python sequence
43
+ /// \param[in] obj the sequence of values
44
+ /// \param[in] mask an optional mask where True values are null. May
45
+ /// be nullptr
46
+ /// \param[in] pandas_null_sentinels use pandas's null value markers
47
+ ARROW_PYTHON_EXPORT
48
+ Result<std::shared_ptr<arrow::DataType>> InferArrowType(PyObject* obj, PyObject* mask,
49
+ bool pandas_null_sentinels);
50
+
51
+ /// Checks whether the passed Python object is a boolean scalar
52
+ ARROW_PYTHON_EXPORT
53
+ bool IsPyBool(PyObject* obj);
54
+
55
+ /// Checks whether the passed Python object is an integer scalar
56
+ ARROW_PYTHON_EXPORT
57
+ bool IsPyInt(PyObject* obj);
58
+
59
+ /// Checks whether the passed Python object is a float scalar
60
+ ARROW_PYTHON_EXPORT
61
+ bool IsPyFloat(PyObject* obj);
62
+
63
+ } // namespace py
64
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/init.h ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include "arrow/python/platform.h"
21
+ #include "arrow/python/visibility.h"
22
+
23
+ extern "C" {
24
+ ARROW_PYTHON_EXPORT
25
+ int arrow_init_numpy();
26
+ }
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/io.h ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include <memory>
21
+
22
+ #include "arrow/io/interfaces.h"
23
+ #include "arrow/io/transform.h"
24
+
25
+ #include "arrow/python/common.h"
26
+ #include "arrow/python/visibility.h"
27
+
28
+ namespace arrow {
29
+ namespace py {
30
+
31
+ class ARROW_NO_EXPORT PythonFile;
32
+
33
+ class ARROW_PYTHON_EXPORT PyReadableFile : public io::RandomAccessFile {
34
+ public:
35
+ explicit PyReadableFile(PyObject* file);
36
+ ~PyReadableFile() override;
37
+
38
+ Status Close() override;
39
+ Status Abort() override;
40
+ bool closed() const override;
41
+
42
+ Result<int64_t> Read(int64_t nbytes, void* out) override;
43
+ Result<std::shared_ptr<Buffer>> Read(int64_t nbytes) override;
44
+
45
+ // Thread-safe version
46
+ Result<int64_t> ReadAt(int64_t position, int64_t nbytes, void* out) override;
47
+
48
+ // Thread-safe version
49
+ Result<std::shared_ptr<Buffer>> ReadAt(int64_t position, int64_t nbytes) override;
50
+
51
+ Result<int64_t> GetSize() override;
52
+
53
+ Status Seek(int64_t position) override;
54
+
55
+ Result<int64_t> Tell() const override;
56
+
57
+ private:
58
+ std::unique_ptr<PythonFile> file_;
59
+ };
60
+
61
+ class ARROW_PYTHON_EXPORT PyOutputStream : public io::OutputStream {
62
+ public:
63
+ explicit PyOutputStream(PyObject* file);
64
+ ~PyOutputStream() override;
65
+
66
+ Status Close() override;
67
+ Status Abort() override;
68
+ bool closed() const override;
69
+ Result<int64_t> Tell() const override;
70
+ Status Write(const void* data, int64_t nbytes) override;
71
+ Status Write(const std::shared_ptr<Buffer>& buffer) override;
72
+
73
+ private:
74
+ std::unique_ptr<PythonFile> file_;
75
+ int64_t position_;
76
+ };
77
+
78
+ // TODO(wesm): seekable output files
79
+
80
+ // A Buffer subclass that keeps a PyObject reference throughout its
81
+ // lifetime, such that the Python object is kept alive as long as the
82
+ // C++ buffer is still needed.
83
+ // Keeping the reference in a Python wrapper would be incorrect as
84
+ // the Python wrapper can get destroyed even though the wrapped C++
85
+ // buffer is still alive (ARROW-2270).
86
+ class ARROW_PYTHON_EXPORT PyForeignBuffer : public Buffer {
87
+ public:
88
+ static Status Make(const uint8_t* data, int64_t size, PyObject* base,
89
+ std::shared_ptr<Buffer>* out);
90
+
91
+ private:
92
+ PyForeignBuffer(const uint8_t* data, int64_t size, PyObject* base)
93
+ : Buffer(data, size) {
94
+ Py_INCREF(base);
95
+ base_.reset(base);
96
+ }
97
+
98
+ OwnedRefNoGIL base_;
99
+ };
100
+
101
+ // All this rigamarole because Cython is really poor with std::function<>
102
+
103
+ using TransformCallback = std::function<void(
104
+ PyObject*, const std::shared_ptr<Buffer>& src, std::shared_ptr<Buffer>* out)>;
105
+
106
+ struct TransformInputStreamVTable {
107
+ TransformCallback transform;
108
+ };
109
+
110
+ ARROW_PYTHON_EXPORT
111
+ std::shared_ptr<::arrow::io::InputStream> MakeTransformInputStream(
112
+ std::shared_ptr<::arrow::io::InputStream> wrapped, TransformInputStreamVTable vtable,
113
+ PyObject* arg);
114
+
115
+ using StreamWrapFunc = std::function<Result<std::shared_ptr<io::InputStream>>(
116
+ std::shared_ptr<io::InputStream>)>;
117
+ ARROW_PYTHON_EXPORT
118
+ std::shared_ptr<StreamWrapFunc> MakeStreamTransformFunc(TransformInputStreamVTable vtable,
119
+ PyObject* handler);
120
+ } // namespace py
121
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/ipc.h ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include <memory>
21
+
22
+ #include "arrow/python/common.h"
23
+ #include "arrow/python/visibility.h"
24
+ #include "arrow/record_batch.h"
25
+ #include "arrow/result.h"
26
+ #include "arrow/util/macros.h"
27
+
28
+ namespace arrow {
29
+ namespace py {
30
+
31
+ class ARROW_PYTHON_EXPORT PyRecordBatchReader : public RecordBatchReader {
32
+ public:
33
+ std::shared_ptr<Schema> schema() const override;
34
+
35
+ Status ReadNext(std::shared_ptr<RecordBatch>* batch) override;
36
+
37
+ // For use from Cython
38
+ // Assumes that `iterable` is borrowed
39
+ static Result<std::shared_ptr<RecordBatchReader>> Make(std::shared_ptr<Schema>,
40
+ PyObject* iterable);
41
+
42
+ protected:
43
+ PyRecordBatchReader();
44
+
45
+ Status Init(std::shared_ptr<Schema>, PyObject* iterable);
46
+
47
+ std::shared_ptr<Schema> schema_;
48
+ OwnedRefNoGIL iterator_;
49
+ };
50
+
51
+ class ARROW_PYTHON_EXPORT CastingRecordBatchReader : public RecordBatchReader {
52
+ public:
53
+ std::shared_ptr<Schema> schema() const override;
54
+
55
+ Status ReadNext(std::shared_ptr<RecordBatch>* batch) override;
56
+
57
+ static Result<std::shared_ptr<RecordBatchReader>> Make(
58
+ std::shared_ptr<RecordBatchReader> parent, std::shared_ptr<Schema> schema);
59
+
60
+ Status Close() override;
61
+
62
+ protected:
63
+ CastingRecordBatchReader();
64
+
65
+ Status Init(std::shared_ptr<RecordBatchReader> parent, std::shared_ptr<Schema> schema);
66
+
67
+ std::shared_ptr<RecordBatchReader> parent_;
68
+ std::shared_ptr<Schema> schema_;
69
+ };
70
+
71
+ } // namespace py
72
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/iterators.h ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include <utility>
21
+
22
+ #include "arrow/array/array_primitive.h"
23
+
24
+ #include "arrow/python/common.h"
25
+ #include "arrow/python/numpy_internal.h"
26
+
27
+ namespace arrow {
28
+ namespace py {
29
+ namespace internal {
30
+
31
+ using arrow::internal::checked_cast;
32
+
33
+ // Visit the Python sequence, calling the given callable on each element. If
34
+ // the callable returns a non-OK status, iteration stops and the status is
35
+ // returned.
36
+ //
37
+ // The call signature for Visitor must be
38
+ //
39
+ // Visit(PyObject* obj, int64_t index, bool* keep_going)
40
+ //
41
+ // If keep_going is set to false, the iteration terminates
42
+ template <class VisitorFunc>
43
+ inline Status VisitSequenceGeneric(PyObject* obj, int64_t offset, VisitorFunc&& func) {
44
+ // VisitorFunc may set to false to terminate iteration
45
+ bool keep_going = true;
46
+
47
+ if (PyArray_Check(obj)) {
48
+ PyArrayObject* arr_obj = reinterpret_cast<PyArrayObject*>(obj);
49
+ if (PyArray_NDIM(arr_obj) != 1) {
50
+ return Status::Invalid("Only 1D arrays accepted");
51
+ }
52
+
53
+ if (PyArray_DESCR(arr_obj)->type_num == NPY_OBJECT) {
54
+ // It's an array object, we can fetch object pointers directly
55
+ const Ndarray1DIndexer<PyObject*> objects(arr_obj);
56
+ for (int64_t i = offset; keep_going && i < objects.size(); ++i) {
57
+ RETURN_NOT_OK(func(objects[i], i, &keep_going));
58
+ }
59
+ return Status::OK();
60
+ }
61
+ // It's a non-object array, fall back on regular sequence access.
62
+ // (note PyArray_GETITEM() is slightly different: it returns standard
63
+ // Python types, not Numpy scalar types)
64
+ // This code path is inefficient: callers should implement dedicated
65
+ // logic for non-object arrays.
66
+ }
67
+ if (PySequence_Check(obj)) {
68
+ if (PyList_Check(obj) || PyTuple_Check(obj)) {
69
+ // Use fast item access
70
+ const Py_ssize_t size = PySequence_Fast_GET_SIZE(obj);
71
+ for (Py_ssize_t i = offset; keep_going && i < size; ++i) {
72
+ PyObject* value = PySequence_Fast_GET_ITEM(obj, i);
73
+ RETURN_NOT_OK(func(value, static_cast<int64_t>(i), &keep_going));
74
+ }
75
+ } else {
76
+ // Regular sequence: avoid making a potentially large copy
77
+ const Py_ssize_t size = PySequence_Size(obj);
78
+ RETURN_IF_PYERROR();
79
+ for (Py_ssize_t i = offset; keep_going && i < size; ++i) {
80
+ OwnedRef value_ref(PySequence_ITEM(obj, i));
81
+ RETURN_IF_PYERROR();
82
+ RETURN_NOT_OK(func(value_ref.obj(), static_cast<int64_t>(i), &keep_going));
83
+ }
84
+ }
85
+ } else {
86
+ return Status::TypeError("Object is not a sequence");
87
+ }
88
+ return Status::OK();
89
+ }
90
+
91
+ // Visit sequence with no null mask
92
+ template <class VisitorFunc>
93
+ inline Status VisitSequence(PyObject* obj, int64_t offset, VisitorFunc&& func) {
94
+ return VisitSequenceGeneric(
95
+ obj, offset, [&func](PyObject* value, int64_t i /* unused */, bool* keep_going) {
96
+ return func(value, keep_going);
97
+ });
98
+ }
99
+
100
+ /// Visit sequence with null mask
101
+ template <class VisitorFunc>
102
+ inline Status VisitSequenceMasked(PyObject* obj, PyObject* mo, int64_t offset,
103
+ VisitorFunc&& func) {
104
+ if (PyArray_Check(mo)) {
105
+ PyArrayObject* mask = reinterpret_cast<PyArrayObject*>(mo);
106
+ if (PyArray_NDIM(mask) != 1) {
107
+ return Status::Invalid("Mask must be 1D array");
108
+ }
109
+ if (PyArray_SIZE(mask) != static_cast<int64_t>(PySequence_Size(obj))) {
110
+ return Status::Invalid("Mask was a different length from sequence being converted");
111
+ }
112
+
113
+ const int dtype = fix_numpy_type_num(PyArray_DESCR(mask)->type_num);
114
+ if (dtype == NPY_BOOL) {
115
+ Ndarray1DIndexer<uint8_t> mask_values(mask);
116
+
117
+ return VisitSequenceGeneric(
118
+ obj, offset,
119
+ [&func, &mask_values](PyObject* value, int64_t i, bool* keep_going) {
120
+ return func(value, mask_values[i], keep_going);
121
+ });
122
+ } else {
123
+ return Status::TypeError("Mask must be boolean dtype");
124
+ }
125
+ } else if (py::is_array(mo)) {
126
+ auto unwrap_mask_result = unwrap_array(mo);
127
+ ARROW_RETURN_NOT_OK(unwrap_mask_result);
128
+ std::shared_ptr<Array> mask_ = unwrap_mask_result.ValueOrDie();
129
+ if (mask_->type_id() != Type::type::BOOL) {
130
+ return Status::TypeError("Mask must be an array of booleans");
131
+ }
132
+
133
+ if (mask_->length() != PySequence_Size(obj)) {
134
+ return Status::Invalid("Mask was a different length from sequence being converted");
135
+ }
136
+
137
+ if (mask_->null_count() != 0) {
138
+ return Status::TypeError("Mask must be an array of booleans");
139
+ }
140
+
141
+ BooleanArray* boolmask = checked_cast<BooleanArray*>(mask_.get());
142
+ return VisitSequenceGeneric(
143
+ obj, offset, [&func, &boolmask](PyObject* value, int64_t i, bool* keep_going) {
144
+ return func(value, boolmask->Value(i), keep_going);
145
+ });
146
+ } else if (PySequence_Check(mo)) {
147
+ if (PySequence_Size(mo) != PySequence_Size(obj)) {
148
+ return Status::Invalid("Mask was a different length from sequence being converted");
149
+ }
150
+ RETURN_IF_PYERROR();
151
+
152
+ return VisitSequenceGeneric(
153
+ obj, offset, [&func, &mo](PyObject* value, int64_t i, bool* keep_going) {
154
+ OwnedRef value_ref(PySequence_ITEM(mo, i));
155
+ if (!PyBool_Check(value_ref.obj()))
156
+ return Status::TypeError("Mask must be a sequence of booleans");
157
+ return func(value, value_ref.obj() == Py_True, keep_going);
158
+ });
159
+ } else {
160
+ return Status::Invalid("Null mask must be a NumPy array, Arrow array or a Sequence");
161
+ }
162
+
163
+ return Status::OK();
164
+ }
165
+
166
+ // Like IterateSequence, but accepts any generic iterable (including
167
+ // non-restartable iterators, e.g. generators).
168
+ //
169
+ // The call signature for VisitorFunc must be Visit(PyObject*, bool*
170
+ // keep_going). If keep_going is set to false, the iteration terminates
171
+ template <class VisitorFunc>
172
+ inline Status VisitIterable(PyObject* obj, VisitorFunc&& func) {
173
+ if (PySequence_Check(obj)) {
174
+ // Numpy arrays fall here as well
175
+ return VisitSequence(obj, /*offset=*/0, std::forward<VisitorFunc>(func));
176
+ }
177
+ // Fall back on the iterator protocol
178
+ OwnedRef iter_ref(PyObject_GetIter(obj));
179
+ PyObject* iter = iter_ref.obj();
180
+ RETURN_IF_PYERROR();
181
+ PyObject* value;
182
+
183
+ bool keep_going = true;
184
+ while (keep_going && (value = PyIter_Next(iter))) {
185
+ OwnedRef value_ref(value);
186
+ RETURN_NOT_OK(func(value_ref.obj(), &keep_going));
187
+ }
188
+ RETURN_IF_PYERROR(); // __next__() might have raised
189
+ return Status::OK();
190
+ }
191
+
192
+ } // namespace internal
193
+ } // namespace py
194
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/lib.h ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Generated by Cython 3.0.10 */
2
+
3
+ #ifndef __PYX_HAVE__pyarrow__lib
4
+ #define __PYX_HAVE__pyarrow__lib
5
+
6
+ #include "Python.h"
7
+
8
+ #ifndef __PYX_HAVE_API__pyarrow__lib
9
+
10
+ #ifdef CYTHON_EXTERN_C
11
+ #undef __PYX_EXTERN_C
12
+ #define __PYX_EXTERN_C CYTHON_EXTERN_C
13
+ #elif defined(__PYX_EXTERN_C)
14
+ #ifdef _MSC_VER
15
+ #pragma message ("Please do not define the '__PYX_EXTERN_C' macro externally. Use 'CYTHON_EXTERN_C' instead.")
16
+ #else
17
+ #warning Please do not define the '__PYX_EXTERN_C' macro externally. Use 'CYTHON_EXTERN_C' instead.
18
+ #endif
19
+ #else
20
+ #define __PYX_EXTERN_C extern "C++"
21
+ #endif
22
+
23
+ #ifndef DL_IMPORT
24
+ #define DL_IMPORT(_T) _T
25
+ #endif
26
+
27
+ __PYX_EXTERN_C PyObject *pyarrow_wrap_buffer(std::shared_ptr< arrow::Buffer> const &);
28
+ __PYX_EXTERN_C PyObject *pyarrow_wrap_resizable_buffer(std::shared_ptr< arrow::ResizableBuffer> const &);
29
+ __PYX_EXTERN_C PyObject *pyarrow_wrap_data_type(std::shared_ptr< arrow::DataType> const &);
30
+ __PYX_EXTERN_C PyObject *pyarrow_wrap_field(std::shared_ptr< arrow::Field> const &);
31
+ __PYX_EXTERN_C PyObject *pyarrow_wrap_schema(std::shared_ptr< arrow::Schema> const &);
32
+ __PYX_EXTERN_C PyObject *pyarrow_wrap_scalar(std::shared_ptr< arrow::Scalar> const &);
33
+ __PYX_EXTERN_C PyObject *pyarrow_wrap_array(std::shared_ptr< arrow::Array> const &);
34
+ __PYX_EXTERN_C PyObject *pyarrow_wrap_chunked_array(std::shared_ptr< arrow::ChunkedArray> const &);
35
+ __PYX_EXTERN_C PyObject *pyarrow_wrap_sparse_coo_tensor(std::shared_ptr< arrow::SparseCOOTensor> const &);
36
+ __PYX_EXTERN_C PyObject *pyarrow_wrap_sparse_csc_matrix(std::shared_ptr< arrow::SparseCSCMatrix> const &);
37
+ __PYX_EXTERN_C PyObject *pyarrow_wrap_sparse_csf_tensor(std::shared_ptr< arrow::SparseCSFTensor> const &);
38
+ __PYX_EXTERN_C PyObject *pyarrow_wrap_sparse_csr_matrix(std::shared_ptr< arrow::SparseCSRMatrix> const &);
39
+ __PYX_EXTERN_C PyObject *pyarrow_wrap_tensor(std::shared_ptr< arrow::Tensor> const &);
40
+ __PYX_EXTERN_C PyObject *pyarrow_wrap_batch(std::shared_ptr< arrow::RecordBatch> const &);
41
+ __PYX_EXTERN_C PyObject *pyarrow_wrap_table(std::shared_ptr< arrow::Table> const &);
42
+ __PYX_EXTERN_C std::shared_ptr< arrow::Buffer> pyarrow_unwrap_buffer(PyObject *);
43
+ __PYX_EXTERN_C std::shared_ptr< arrow::DataType> pyarrow_unwrap_data_type(PyObject *);
44
+ __PYX_EXTERN_C std::shared_ptr< arrow::Field> pyarrow_unwrap_field(PyObject *);
45
+ __PYX_EXTERN_C std::shared_ptr< arrow::Schema> pyarrow_unwrap_schema(PyObject *);
46
+ __PYX_EXTERN_C std::shared_ptr< arrow::Scalar> pyarrow_unwrap_scalar(PyObject *);
47
+ __PYX_EXTERN_C std::shared_ptr< arrow::Array> pyarrow_unwrap_array(PyObject *);
48
+ __PYX_EXTERN_C std::shared_ptr< arrow::ChunkedArray> pyarrow_unwrap_chunked_array(PyObject *);
49
+ __PYX_EXTERN_C std::shared_ptr< arrow::SparseCOOTensor> pyarrow_unwrap_sparse_coo_tensor(PyObject *);
50
+ __PYX_EXTERN_C std::shared_ptr< arrow::SparseCSCMatrix> pyarrow_unwrap_sparse_csc_matrix(PyObject *);
51
+ __PYX_EXTERN_C std::shared_ptr< arrow::SparseCSFTensor> pyarrow_unwrap_sparse_csf_tensor(PyObject *);
52
+ __PYX_EXTERN_C std::shared_ptr< arrow::SparseCSRMatrix> pyarrow_unwrap_sparse_csr_matrix(PyObject *);
53
+ __PYX_EXTERN_C std::shared_ptr< arrow::Tensor> pyarrow_unwrap_tensor(PyObject *);
54
+ __PYX_EXTERN_C std::shared_ptr< arrow::RecordBatch> pyarrow_unwrap_batch(PyObject *);
55
+ __PYX_EXTERN_C std::shared_ptr< arrow::Table> pyarrow_unwrap_table(PyObject *);
56
+
57
+ #endif /* !__PYX_HAVE_API__pyarrow__lib */
58
+
59
+ /* WARNING: the interface of the module init function changed in CPython 3.5. */
60
+ /* It now returns a PyModuleDef instance instead of a PyModule instance. */
61
+
62
+ #if PY_MAJOR_VERSION < 3
63
+ PyMODINIT_FUNC initlib(void);
64
+ #else
65
+ /* WARNING: Use PyImport_AppendInittab("lib", PyInit_lib) instead of calling PyInit_lib directly from Python 3.5 */
66
+ PyMODINIT_FUNC PyInit_lib(void);
67
+
68
+ #if PY_VERSION_HEX >= 0x03050000 && (defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) || (defined(__cplusplus) && __cplusplus >= 201402L))
69
+ #if defined(__cplusplus) && __cplusplus >= 201402L
70
+ [[deprecated("Use PyImport_AppendInittab(\"lib\", PyInit_lib) instead of calling PyInit_lib directly.")]] inline
71
+ #elif defined(__GNUC__) || defined(__clang__)
72
+ __attribute__ ((__deprecated__("Use PyImport_AppendInittab(\"lib\", PyInit_lib) instead of calling PyInit_lib directly."), __unused__)) __inline__
73
+ #elif defined(_MSC_VER)
74
+ __declspec(deprecated("Use PyImport_AppendInittab(\"lib\", PyInit_lib) instead of calling PyInit_lib directly.")) __inline
75
+ #endif
76
+ static PyObject* __PYX_WARN_IF_PyInit_lib_INIT_CALLED(PyObject* res) {
77
+ return res;
78
+ }
79
+ #define PyInit_lib() __PYX_WARN_IF_PyInit_lib_INIT_CALLED(PyInit_lib())
80
+ #endif
81
+ #endif
82
+
83
+ #endif /* !__PYX_HAVE__pyarrow__lib */
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/lib_api.h ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Generated by Cython 3.0.10 */
2
+
3
+ #ifndef __PYX_HAVE_API__pyarrow__lib
4
+ #define __PYX_HAVE_API__pyarrow__lib
5
+ #ifdef __MINGW64__
6
+ #define MS_WIN64
7
+ #endif
8
+ #include "Python.h"
9
+ #include "lib.h"
10
+
11
+ static PyObject *(*__pyx_api_f_7pyarrow_3lib_box_memory_pool)( arrow::MemoryPool *) = 0;
12
+ #define box_memory_pool __pyx_api_f_7pyarrow_3lib_box_memory_pool
13
+ static PyObject *(*__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_buffer)(std::shared_ptr< arrow::Buffer> const &) = 0;
14
+ #define pyarrow_wrap_buffer __pyx_api_f_7pyarrow_3lib_pyarrow_wrap_buffer
15
+ static PyObject *(*__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_resizable_buffer)(std::shared_ptr< arrow::ResizableBuffer> const &) = 0;
16
+ #define pyarrow_wrap_resizable_buffer __pyx_api_f_7pyarrow_3lib_pyarrow_wrap_resizable_buffer
17
+ static PyObject *(*__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_data_type)(std::shared_ptr< arrow::DataType> const &) = 0;
18
+ #define pyarrow_wrap_data_type __pyx_api_f_7pyarrow_3lib_pyarrow_wrap_data_type
19
+ static PyObject *(*__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_field)(std::shared_ptr< arrow::Field> const &) = 0;
20
+ #define pyarrow_wrap_field __pyx_api_f_7pyarrow_3lib_pyarrow_wrap_field
21
+ static PyObject *(*__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_schema)(std::shared_ptr< arrow::Schema> const &) = 0;
22
+ #define pyarrow_wrap_schema __pyx_api_f_7pyarrow_3lib_pyarrow_wrap_schema
23
+ static PyObject *(*__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_scalar)(std::shared_ptr< arrow::Scalar> const &) = 0;
24
+ #define pyarrow_wrap_scalar __pyx_api_f_7pyarrow_3lib_pyarrow_wrap_scalar
25
+ static PyObject *(*__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_array)(std::shared_ptr< arrow::Array> const &) = 0;
26
+ #define pyarrow_wrap_array __pyx_api_f_7pyarrow_3lib_pyarrow_wrap_array
27
+ static PyObject *(*__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_chunked_array)(std::shared_ptr< arrow::ChunkedArray> const &) = 0;
28
+ #define pyarrow_wrap_chunked_array __pyx_api_f_7pyarrow_3lib_pyarrow_wrap_chunked_array
29
+ static PyObject *(*__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_sparse_coo_tensor)(std::shared_ptr< arrow::SparseCOOTensor> const &) = 0;
30
+ #define pyarrow_wrap_sparse_coo_tensor __pyx_api_f_7pyarrow_3lib_pyarrow_wrap_sparse_coo_tensor
31
+ static PyObject *(*__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_sparse_csc_matrix)(std::shared_ptr< arrow::SparseCSCMatrix> const &) = 0;
32
+ #define pyarrow_wrap_sparse_csc_matrix __pyx_api_f_7pyarrow_3lib_pyarrow_wrap_sparse_csc_matrix
33
+ static PyObject *(*__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_sparse_csf_tensor)(std::shared_ptr< arrow::SparseCSFTensor> const &) = 0;
34
+ #define pyarrow_wrap_sparse_csf_tensor __pyx_api_f_7pyarrow_3lib_pyarrow_wrap_sparse_csf_tensor
35
+ static PyObject *(*__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_sparse_csr_matrix)(std::shared_ptr< arrow::SparseCSRMatrix> const &) = 0;
36
+ #define pyarrow_wrap_sparse_csr_matrix __pyx_api_f_7pyarrow_3lib_pyarrow_wrap_sparse_csr_matrix
37
+ static PyObject *(*__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_tensor)(std::shared_ptr< arrow::Tensor> const &) = 0;
38
+ #define pyarrow_wrap_tensor __pyx_api_f_7pyarrow_3lib_pyarrow_wrap_tensor
39
+ static PyObject *(*__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_batch)(std::shared_ptr< arrow::RecordBatch> const &) = 0;
40
+ #define pyarrow_wrap_batch __pyx_api_f_7pyarrow_3lib_pyarrow_wrap_batch
41
+ static PyObject *(*__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_table)(std::shared_ptr< arrow::Table> const &) = 0;
42
+ #define pyarrow_wrap_table __pyx_api_f_7pyarrow_3lib_pyarrow_wrap_table
43
+ static std::shared_ptr< arrow::Buffer> (*__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_buffer)(PyObject *) = 0;
44
+ #define pyarrow_unwrap_buffer __pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_buffer
45
+ static std::shared_ptr< arrow::DataType> (*__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_data_type)(PyObject *) = 0;
46
+ #define pyarrow_unwrap_data_type __pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_data_type
47
+ static std::shared_ptr< arrow::Field> (*__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_field)(PyObject *) = 0;
48
+ #define pyarrow_unwrap_field __pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_field
49
+ static std::shared_ptr< arrow::Schema> (*__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_schema)(PyObject *) = 0;
50
+ #define pyarrow_unwrap_schema __pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_schema
51
+ static std::shared_ptr< arrow::Scalar> (*__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_scalar)(PyObject *) = 0;
52
+ #define pyarrow_unwrap_scalar __pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_scalar
53
+ static std::shared_ptr< arrow::Array> (*__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_array)(PyObject *) = 0;
54
+ #define pyarrow_unwrap_array __pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_array
55
+ static std::shared_ptr< arrow::ChunkedArray> (*__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_chunked_array)(PyObject *) = 0;
56
+ #define pyarrow_unwrap_chunked_array __pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_chunked_array
57
+ static std::shared_ptr< arrow::SparseCOOTensor> (*__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_sparse_coo_tensor)(PyObject *) = 0;
58
+ #define pyarrow_unwrap_sparse_coo_tensor __pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_sparse_coo_tensor
59
+ static std::shared_ptr< arrow::SparseCSCMatrix> (*__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_sparse_csc_matrix)(PyObject *) = 0;
60
+ #define pyarrow_unwrap_sparse_csc_matrix __pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_sparse_csc_matrix
61
+ static std::shared_ptr< arrow::SparseCSFTensor> (*__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_sparse_csf_tensor)(PyObject *) = 0;
62
+ #define pyarrow_unwrap_sparse_csf_tensor __pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_sparse_csf_tensor
63
+ static std::shared_ptr< arrow::SparseCSRMatrix> (*__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_sparse_csr_matrix)(PyObject *) = 0;
64
+ #define pyarrow_unwrap_sparse_csr_matrix __pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_sparse_csr_matrix
65
+ static std::shared_ptr< arrow::Tensor> (*__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_tensor)(PyObject *) = 0;
66
+ #define pyarrow_unwrap_tensor __pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_tensor
67
+ static std::shared_ptr< arrow::RecordBatch> (*__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_batch)(PyObject *) = 0;
68
+ #define pyarrow_unwrap_batch __pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_batch
69
+ static std::shared_ptr< arrow::Table> (*__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_table)(PyObject *) = 0;
70
+ #define pyarrow_unwrap_table __pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_table
71
+ static int (*__pyx_api_f_7pyarrow_3lib_pyarrow_internal_check_status)(arrow::Status const &) = 0;
72
+ #define pyarrow_internal_check_status __pyx_api_f_7pyarrow_3lib_pyarrow_internal_check_status
73
+ static PyObject *(*__pyx_api_f_7pyarrow_3lib_pyarrow_internal_convert_status)(arrow::Status const &) = 0;
74
+ #define pyarrow_internal_convert_status __pyx_api_f_7pyarrow_3lib_pyarrow_internal_convert_status
75
+ static int (*__pyx_api_f_7pyarrow_3lib_pyarrow_is_buffer)(PyObject *) = 0;
76
+ #define pyarrow_is_buffer __pyx_api_f_7pyarrow_3lib_pyarrow_is_buffer
77
+ static int (*__pyx_api_f_7pyarrow_3lib_pyarrow_is_data_type)(PyObject *) = 0;
78
+ #define pyarrow_is_data_type __pyx_api_f_7pyarrow_3lib_pyarrow_is_data_type
79
+ static int (*__pyx_api_f_7pyarrow_3lib_pyarrow_is_metadata)(PyObject *) = 0;
80
+ #define pyarrow_is_metadata __pyx_api_f_7pyarrow_3lib_pyarrow_is_metadata
81
+ static int (*__pyx_api_f_7pyarrow_3lib_pyarrow_is_field)(PyObject *) = 0;
82
+ #define pyarrow_is_field __pyx_api_f_7pyarrow_3lib_pyarrow_is_field
83
+ static int (*__pyx_api_f_7pyarrow_3lib_pyarrow_is_schema)(PyObject *) = 0;
84
+ #define pyarrow_is_schema __pyx_api_f_7pyarrow_3lib_pyarrow_is_schema
85
+ static int (*__pyx_api_f_7pyarrow_3lib_pyarrow_is_array)(PyObject *) = 0;
86
+ #define pyarrow_is_array __pyx_api_f_7pyarrow_3lib_pyarrow_is_array
87
+ static int (*__pyx_api_f_7pyarrow_3lib_pyarrow_is_chunked_array)(PyObject *) = 0;
88
+ #define pyarrow_is_chunked_array __pyx_api_f_7pyarrow_3lib_pyarrow_is_chunked_array
89
+ static int (*__pyx_api_f_7pyarrow_3lib_pyarrow_is_scalar)(PyObject *) = 0;
90
+ #define pyarrow_is_scalar __pyx_api_f_7pyarrow_3lib_pyarrow_is_scalar
91
+ static int (*__pyx_api_f_7pyarrow_3lib_pyarrow_is_tensor)(PyObject *) = 0;
92
+ #define pyarrow_is_tensor __pyx_api_f_7pyarrow_3lib_pyarrow_is_tensor
93
+ static int (*__pyx_api_f_7pyarrow_3lib_pyarrow_is_sparse_coo_tensor)(PyObject *) = 0;
94
+ #define pyarrow_is_sparse_coo_tensor __pyx_api_f_7pyarrow_3lib_pyarrow_is_sparse_coo_tensor
95
+ static int (*__pyx_api_f_7pyarrow_3lib_pyarrow_is_sparse_csr_matrix)(PyObject *) = 0;
96
+ #define pyarrow_is_sparse_csr_matrix __pyx_api_f_7pyarrow_3lib_pyarrow_is_sparse_csr_matrix
97
+ static int (*__pyx_api_f_7pyarrow_3lib_pyarrow_is_sparse_csc_matrix)(PyObject *) = 0;
98
+ #define pyarrow_is_sparse_csc_matrix __pyx_api_f_7pyarrow_3lib_pyarrow_is_sparse_csc_matrix
99
+ static int (*__pyx_api_f_7pyarrow_3lib_pyarrow_is_sparse_csf_tensor)(PyObject *) = 0;
100
+ #define pyarrow_is_sparse_csf_tensor __pyx_api_f_7pyarrow_3lib_pyarrow_is_sparse_csf_tensor
101
+ static int (*__pyx_api_f_7pyarrow_3lib_pyarrow_is_table)(PyObject *) = 0;
102
+ #define pyarrow_is_table __pyx_api_f_7pyarrow_3lib_pyarrow_is_table
103
+ static int (*__pyx_api_f_7pyarrow_3lib_pyarrow_is_batch)(PyObject *) = 0;
104
+ #define pyarrow_is_batch __pyx_api_f_7pyarrow_3lib_pyarrow_is_batch
105
+ #ifndef __PYX_HAVE_RT_ImportFunction_3_0_10
106
+ #define __PYX_HAVE_RT_ImportFunction_3_0_10
107
+ static int __Pyx_ImportFunction_3_0_10(PyObject *module, const char *funcname, void (**f)(void), const char *sig) {
108
+ PyObject *d = 0;
109
+ PyObject *cobj = 0;
110
+ union {
111
+ void (*fp)(void);
112
+ void *p;
113
+ } tmp;
114
+ d = PyObject_GetAttrString(module, (char *)"__pyx_capi__");
115
+ if (!d)
116
+ goto bad;
117
+ cobj = PyDict_GetItemString(d, funcname);
118
+ if (!cobj) {
119
+ PyErr_Format(PyExc_ImportError,
120
+ "%.200s does not export expected C function %.200s",
121
+ PyModule_GetName(module), funcname);
122
+ goto bad;
123
+ }
124
+ if (!PyCapsule_IsValid(cobj, sig)) {
125
+ PyErr_Format(PyExc_TypeError,
126
+ "C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
127
+ PyModule_GetName(module), funcname, sig, PyCapsule_GetName(cobj));
128
+ goto bad;
129
+ }
130
+ tmp.p = PyCapsule_GetPointer(cobj, sig);
131
+ *f = tmp.fp;
132
+ if (!(*f))
133
+ goto bad;
134
+ Py_DECREF(d);
135
+ return 0;
136
+ bad:
137
+ Py_XDECREF(d);
138
+ return -1;
139
+ }
140
+ #endif
141
+
142
+
143
+ static int import_pyarrow__lib(void) {
144
+ PyObject *module = 0;
145
+ module = PyImport_ImportModule("pyarrow.lib");
146
+ if (!module) goto bad;
147
+ if (__Pyx_ImportFunction_3_0_10(module, "box_memory_pool", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_box_memory_pool, "PyObject *( arrow::MemoryPool *)") < 0) goto bad;
148
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_wrap_buffer", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_buffer, "PyObject *(std::shared_ptr< arrow::Buffer> const &)") < 0) goto bad;
149
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_wrap_resizable_buffer", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_resizable_buffer, "PyObject *(std::shared_ptr< arrow::ResizableBuffer> const &)") < 0) goto bad;
150
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_wrap_data_type", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_data_type, "PyObject *(std::shared_ptr< arrow::DataType> const &)") < 0) goto bad;
151
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_wrap_field", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_field, "PyObject *(std::shared_ptr< arrow::Field> const &)") < 0) goto bad;
152
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_wrap_schema", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_schema, "PyObject *(std::shared_ptr< arrow::Schema> const &)") < 0) goto bad;
153
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_wrap_scalar", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_scalar, "PyObject *(std::shared_ptr< arrow::Scalar> const &)") < 0) goto bad;
154
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_wrap_array", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_array, "PyObject *(std::shared_ptr< arrow::Array> const &)") < 0) goto bad;
155
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_wrap_chunked_array", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_chunked_array, "PyObject *(std::shared_ptr< arrow::ChunkedArray> const &)") < 0) goto bad;
156
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_wrap_sparse_coo_tensor", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_sparse_coo_tensor, "PyObject *(std::shared_ptr< arrow::SparseCOOTensor> const &)") < 0) goto bad;
157
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_wrap_sparse_csc_matrix", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_sparse_csc_matrix, "PyObject *(std::shared_ptr< arrow::SparseCSCMatrix> const &)") < 0) goto bad;
158
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_wrap_sparse_csf_tensor", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_sparse_csf_tensor, "PyObject *(std::shared_ptr< arrow::SparseCSFTensor> const &)") < 0) goto bad;
159
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_wrap_sparse_csr_matrix", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_sparse_csr_matrix, "PyObject *(std::shared_ptr< arrow::SparseCSRMatrix> const &)") < 0) goto bad;
160
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_wrap_tensor", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_tensor, "PyObject *(std::shared_ptr< arrow::Tensor> const &)") < 0) goto bad;
161
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_wrap_batch", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_batch, "PyObject *(std::shared_ptr< arrow::RecordBatch> const &)") < 0) goto bad;
162
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_wrap_table", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_wrap_table, "PyObject *(std::shared_ptr< arrow::Table> const &)") < 0) goto bad;
163
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_unwrap_buffer", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_buffer, "std::shared_ptr< arrow::Buffer> (PyObject *)") < 0) goto bad;
164
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_unwrap_data_type", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_data_type, "std::shared_ptr< arrow::DataType> (PyObject *)") < 0) goto bad;
165
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_unwrap_field", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_field, "std::shared_ptr< arrow::Field> (PyObject *)") < 0) goto bad;
166
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_unwrap_schema", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_schema, "std::shared_ptr< arrow::Schema> (PyObject *)") < 0) goto bad;
167
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_unwrap_scalar", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_scalar, "std::shared_ptr< arrow::Scalar> (PyObject *)") < 0) goto bad;
168
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_unwrap_array", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_array, "std::shared_ptr< arrow::Array> (PyObject *)") < 0) goto bad;
169
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_unwrap_chunked_array", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_chunked_array, "std::shared_ptr< arrow::ChunkedArray> (PyObject *)") < 0) goto bad;
170
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_unwrap_sparse_coo_tensor", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_sparse_coo_tensor, "std::shared_ptr< arrow::SparseCOOTensor> (PyObject *)") < 0) goto bad;
171
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_unwrap_sparse_csc_matrix", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_sparse_csc_matrix, "std::shared_ptr< arrow::SparseCSCMatrix> (PyObject *)") < 0) goto bad;
172
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_unwrap_sparse_csf_tensor", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_sparse_csf_tensor, "std::shared_ptr< arrow::SparseCSFTensor> (PyObject *)") < 0) goto bad;
173
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_unwrap_sparse_csr_matrix", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_sparse_csr_matrix, "std::shared_ptr< arrow::SparseCSRMatrix> (PyObject *)") < 0) goto bad;
174
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_unwrap_tensor", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_tensor, "std::shared_ptr< arrow::Tensor> (PyObject *)") < 0) goto bad;
175
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_unwrap_batch", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_batch, "std::shared_ptr< arrow::RecordBatch> (PyObject *)") < 0) goto bad;
176
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_unwrap_table", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_unwrap_table, "std::shared_ptr< arrow::Table> (PyObject *)") < 0) goto bad;
177
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_internal_check_status", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_internal_check_status, "int (arrow::Status const &)") < 0) goto bad;
178
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_internal_convert_status", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_internal_convert_status, "PyObject *(arrow::Status const &)") < 0) goto bad;
179
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_is_buffer", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_is_buffer, "int (PyObject *)") < 0) goto bad;
180
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_is_data_type", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_is_data_type, "int (PyObject *)") < 0) goto bad;
181
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_is_metadata", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_is_metadata, "int (PyObject *)") < 0) goto bad;
182
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_is_field", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_is_field, "int (PyObject *)") < 0) goto bad;
183
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_is_schema", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_is_schema, "int (PyObject *)") < 0) goto bad;
184
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_is_array", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_is_array, "int (PyObject *)") < 0) goto bad;
185
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_is_chunked_array", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_is_chunked_array, "int (PyObject *)") < 0) goto bad;
186
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_is_scalar", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_is_scalar, "int (PyObject *)") < 0) goto bad;
187
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_is_tensor", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_is_tensor, "int (PyObject *)") < 0) goto bad;
188
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_is_sparse_coo_tensor", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_is_sparse_coo_tensor, "int (PyObject *)") < 0) goto bad;
189
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_is_sparse_csr_matrix", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_is_sparse_csr_matrix, "int (PyObject *)") < 0) goto bad;
190
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_is_sparse_csc_matrix", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_is_sparse_csc_matrix, "int (PyObject *)") < 0) goto bad;
191
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_is_sparse_csf_tensor", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_is_sparse_csf_tensor, "int (PyObject *)") < 0) goto bad;
192
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_is_table", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_is_table, "int (PyObject *)") < 0) goto bad;
193
+ if (__Pyx_ImportFunction_3_0_10(module, "pyarrow_is_batch", (void (**)(void))&__pyx_api_f_7pyarrow_3lib_pyarrow_is_batch, "int (PyObject *)") < 0) goto bad;
194
+ Py_DECREF(module); module = 0;
195
+ return 0;
196
+ bad:
197
+ Py_XDECREF(module);
198
+ return -1;
199
+ }
200
+
201
+ #endif /* !__PYX_HAVE_API__pyarrow__lib */
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/numpy_convert.h ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
22
+
23
+ #include "arrow/python/platform.h"
24
+
25
+ #include <memory>
26
+ #include <string>
27
+ #include <vector>
28
+
29
+ #include "arrow/buffer.h"
30
+ #include "arrow/python/visibility.h"
31
+ #include "arrow/sparse_tensor.h"
32
+
33
+ namespace arrow {
34
+
35
+ class DataType;
36
+ class MemoryPool;
37
+ class Status;
38
+ class Tensor;
39
+
40
+ namespace py {
41
+
42
+ class ARROW_PYTHON_EXPORT NumPyBuffer : public Buffer {
43
+ public:
44
+ explicit NumPyBuffer(PyObject* arr);
45
+ virtual ~NumPyBuffer();
46
+
47
+ private:
48
+ PyObject* arr_;
49
+ };
50
+
51
+ ARROW_PYTHON_EXPORT
52
+ Result<std::shared_ptr<DataType>> NumPyDtypeToArrow(PyObject* dtype);
53
+ ARROW_PYTHON_EXPORT
54
+ Result<std::shared_ptr<DataType>> NumPyDtypeToArrow(PyArray_Descr* descr);
55
+ ARROW_PYTHON_EXPORT
56
+ Result<std::shared_ptr<DataType>> NumPyScalarToArrowDataType(PyObject* scalar);
57
+
58
+ ARROW_PYTHON_EXPORT Status NdarrayToTensor(MemoryPool* pool, PyObject* ao,
59
+ const std::vector<std::string>& dim_names,
60
+ std::shared_ptr<Tensor>* out);
61
+
62
+ ARROW_PYTHON_EXPORT Status TensorToNdarray(const std::shared_ptr<Tensor>& tensor,
63
+ PyObject* base, PyObject** out);
64
+
65
+ ARROW_PYTHON_EXPORT Status
66
+ SparseCOOTensorToNdarray(const std::shared_ptr<SparseCOOTensor>& sparse_tensor,
67
+ PyObject* base, PyObject** out_data, PyObject** out_coords);
68
+
69
+ Status SparseCSXMatrixToNdarray(const std::shared_ptr<SparseTensor>& sparse_tensor,
70
+ PyObject* base, PyObject** out_data,
71
+ PyObject** out_indptr, PyObject** out_indices);
72
+
73
+ ARROW_PYTHON_EXPORT Status SparseCSRMatrixToNdarray(
74
+ const std::shared_ptr<SparseCSRMatrix>& sparse_tensor, PyObject* base,
75
+ PyObject** out_data, PyObject** out_indptr, PyObject** out_indices);
76
+
77
+ ARROW_PYTHON_EXPORT Status SparseCSCMatrixToNdarray(
78
+ const std::shared_ptr<SparseCSCMatrix>& sparse_tensor, PyObject* base,
79
+ PyObject** out_data, PyObject** out_indptr, PyObject** out_indices);
80
+
81
+ ARROW_PYTHON_EXPORT Status SparseCSFTensorToNdarray(
82
+ const std::shared_ptr<SparseCSFTensor>& sparse_tensor, PyObject* base,
83
+ PyObject** out_data, PyObject** out_indptr, PyObject** out_indices);
84
+
85
+ ARROW_PYTHON_EXPORT Status NdarraysToSparseCOOTensor(
86
+ MemoryPool* pool, PyObject* data_ao, PyObject* coords_ao,
87
+ const std::vector<int64_t>& shape, const std::vector<std::string>& dim_names,
88
+ std::shared_ptr<SparseCOOTensor>* out);
89
+
90
+ ARROW_PYTHON_EXPORT Status NdarraysToSparseCSRMatrix(
91
+ MemoryPool* pool, PyObject* data_ao, PyObject* indptr_ao, PyObject* indices_ao,
92
+ const std::vector<int64_t>& shape, const std::vector<std::string>& dim_names,
93
+ std::shared_ptr<SparseCSRMatrix>* out);
94
+
95
+ ARROW_PYTHON_EXPORT Status NdarraysToSparseCSCMatrix(
96
+ MemoryPool* pool, PyObject* data_ao, PyObject* indptr_ao, PyObject* indices_ao,
97
+ const std::vector<int64_t>& shape, const std::vector<std::string>& dim_names,
98
+ std::shared_ptr<SparseCSCMatrix>* out);
99
+
100
+ ARROW_PYTHON_EXPORT Status NdarraysToSparseCSFTensor(
101
+ MemoryPool* pool, PyObject* data_ao, PyObject* indptr_ao, PyObject* indices_ao,
102
+ const std::vector<int64_t>& shape, const std::vector<int64_t>& axis_order,
103
+ const std::vector<std::string>& dim_names, std::shared_ptr<SparseCSFTensor>* out);
104
+
105
+ ARROW_PYTHON_EXPORT Status
106
+ TensorToSparseCOOTensor(const std::shared_ptr<Tensor>& tensor,
107
+ std::shared_ptr<SparseCOOTensor>* csparse_tensor);
108
+
109
+ ARROW_PYTHON_EXPORT Status
110
+ TensorToSparseCSRMatrix(const std::shared_ptr<Tensor>& tensor,
111
+ std::shared_ptr<SparseCSRMatrix>* csparse_tensor);
112
+
113
+ ARROW_PYTHON_EXPORT Status
114
+ TensorToSparseCSCMatrix(const std::shared_ptr<Tensor>& tensor,
115
+ std::shared_ptr<SparseCSCMatrix>* csparse_tensor);
116
+
117
+ ARROW_PYTHON_EXPORT Status
118
+ TensorToSparseCSFTensor(const std::shared_ptr<Tensor>& tensor,
119
+ std::shared_ptr<SparseCSFTensor>* csparse_tensor);
120
+
121
+ } // namespace py
122
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/numpy_interop.h ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include "arrow/python/platform.h" // IWYU pragma: export
21
+
22
+ #include <numpy/numpyconfig.h> // IWYU pragma: export
23
+
24
+ // Don't use the deprecated Numpy functions
25
+ #ifdef NPY_1_7_API_VERSION
26
+ #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
27
+ #else
28
+ #define NPY_ARRAY_NOTSWAPPED NPY_NOTSWAPPED
29
+ #define NPY_ARRAY_ALIGNED NPY_ALIGNED
30
+ #define NPY_ARRAY_WRITEABLE NPY_WRITEABLE
31
+ #define NPY_ARRAY_UPDATEIFCOPY NPY_UPDATEIFCOPY
32
+ #endif
33
+
34
+ // This is required to be able to access the NumPy C API properly in C++ files
35
+ // other than init.cc.
36
+ #define PY_ARRAY_UNIQUE_SYMBOL arrow_ARRAY_API
37
+ #ifndef NUMPY_IMPORT_ARRAY
38
+ #define NO_IMPORT_ARRAY
39
+ #endif
40
+
41
+ #include <numpy/arrayobject.h> // IWYU pragma: export
42
+ #include <numpy/arrayscalars.h> // IWYU pragma: export
43
+ #include <numpy/ufuncobject.h> // IWYU pragma: export
44
+
45
+ // A bit subtle. Numpy has 5 canonical integer types:
46
+ // (or, rather, type pairs: signed and unsigned)
47
+ // NPY_BYTE, NPY_SHORT, NPY_INT, NPY_LONG, NPY_LONGLONG
48
+ // It also has 4 fixed-width integer aliases.
49
+ // When mapping Arrow integer types to these 4 fixed-width aliases,
50
+ // we always miss one of the canonical types (even though it may
51
+ // have the same width as one of the aliases).
52
+ // Which one depends on the platform...
53
+ // On a LP64 system, NPY_INT64 maps to NPY_LONG and
54
+ // NPY_LONGLONG needs to be handled separately.
55
+ // On a LLP64 system, NPY_INT32 maps to NPY_LONG and
56
+ // NPY_INT needs to be handled separately.
57
+
58
+ #if NPY_BITSOF_LONG == 32 && NPY_BITSOF_LONGLONG == 64
59
+ #define NPY_INT64_IS_LONG_LONG 1
60
+ #else
61
+ #define NPY_INT64_IS_LONG_LONG 0
62
+ #endif
63
+
64
+ #if NPY_BITSOF_INT == 32 && NPY_BITSOF_LONG == 64
65
+ #define NPY_INT32_IS_INT 1
66
+ #else
67
+ #define NPY_INT32_IS_INT 0
68
+ #endif
69
+
70
+ // Backported NumPy 2 API (can be removed if numpy 2 is required)
71
+ #if NPY_ABI_VERSION < 0x02000000
72
+ #define PyDataType_ELSIZE(descr) ((descr)->elsize)
73
+ #define PyDataType_C_METADATA(descr) ((descr)->c_metadata)
74
+ #define PyDataType_FIELDS(descr) ((descr)->fields)
75
+ #endif
76
+
77
+ namespace arrow {
78
+ namespace py {
79
+
80
+ inline int import_numpy() {
81
+ #ifdef NUMPY_IMPORT_ARRAY
82
+ import_array1(-1);
83
+ import_umath1(-1);
84
+ #endif
85
+
86
+ return 0;
87
+ }
88
+
89
+ // See above about the missing Numpy integer type numbers
90
+ inline int fix_numpy_type_num(int type_num) {
91
+ #if !NPY_INT32_IS_INT && NPY_BITSOF_INT == 32
92
+ if (type_num == NPY_INT) return NPY_INT32;
93
+ if (type_num == NPY_UINT) return NPY_UINT32;
94
+ #endif
95
+ #if !NPY_INT64_IS_LONG_LONG && NPY_BITSOF_LONGLONG == 64
96
+ if (type_num == NPY_LONGLONG) return NPY_INT64;
97
+ if (type_num == NPY_ULONGLONG) return NPY_UINT64;
98
+ #endif
99
+ return type_num;
100
+ }
101
+
102
+ } // namespace py
103
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/numpy_to_arrow.h ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // Converting from pandas memory representation to Arrow data structures
19
+
20
+ #pragma once
21
+
22
+ #include "arrow/python/platform.h"
23
+
24
+ #include <memory>
25
+
26
+ #include "arrow/compute/api.h"
27
+ #include "arrow/python/visibility.h"
28
+
29
+ namespace arrow {
30
+
31
+ class Array;
32
+ class ChunkedArray;
33
+ class DataType;
34
+ class MemoryPool;
35
+ class Status;
36
+
37
+ namespace py {
38
+
39
+ /// Convert NumPy arrays to Arrow. If target data type is not known, pass a
40
+ /// type with null
41
+ ///
42
+ /// \param[in] pool Memory pool for any memory allocations
43
+ /// \param[in] ao an ndarray with the array data
44
+ /// \param[in] mo an ndarray with a null mask (True is null), optional
45
+ /// \param[in] from_pandas If true, use pandas's null sentinels to determine
46
+ /// whether values are null
47
+ /// \param[in] type a specific type to cast to, may be null
48
+ /// \param[in] cast_options casting options
49
+ /// \param[out] out a ChunkedArray, to accommodate chunked output
50
+ ARROW_PYTHON_EXPORT
51
+ Status NdarrayToArrow(MemoryPool* pool, PyObject* ao, PyObject* mo, bool from_pandas,
52
+ const std::shared_ptr<DataType>& type,
53
+ const compute::CastOptions& cast_options,
54
+ std::shared_ptr<ChunkedArray>* out);
55
+
56
+ /// Safely convert NumPy arrays to Arrow. If target data type is not known,
57
+ /// pass a type with null.
58
+ ///
59
+ /// \param[in] pool Memory pool for any memory allocations
60
+ /// \param[in] ao an ndarray with the array data
61
+ /// \param[in] mo an ndarray with a null mask (True is null), optional
62
+ /// \param[in] from_pandas If true, use pandas's null sentinels to determine
63
+ /// whether values are null
64
+ /// \param[in] type a specific type to cast to, may be null
65
+ /// \param[out] out a ChunkedArray, to accommodate chunked output
66
+ ARROW_PYTHON_EXPORT
67
+ Status NdarrayToArrow(MemoryPool* pool, PyObject* ao, PyObject* mo, bool from_pandas,
68
+ const std::shared_ptr<DataType>& type,
69
+ std::shared_ptr<ChunkedArray>* out);
70
+
71
+ } // namespace py
72
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/parquet_encryption.h ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include <string>
21
+
22
+ #include "arrow/python/common.h"
23
+ #include "arrow/python/visibility.h"
24
+ #include "arrow/util/macros.h"
25
+ #include "parquet/encryption/crypto_factory.h"
26
+ #include "parquet/encryption/kms_client.h"
27
+ #include "parquet/encryption/kms_client_factory.h"
28
+
29
+ #if defined(_WIN32) || defined(__CYGWIN__) // Windows
30
+ #if defined(_MSC_VER)
31
+ #pragma warning(disable : 4251)
32
+ #else
33
+ #pragma GCC diagnostic ignored "-Wattributes"
34
+ #endif
35
+
36
+ #ifdef ARROW_PYTHON_STATIC
37
+ #define ARROW_PYTHON_PARQUET_ENCRYPTION_EXPORT
38
+ #elif defined(ARROW_PYTHON_PARQUET_ENCRYPTION_EXPORTING)
39
+ #define ARROW_PYTHON_PARQUET_ENCRYPTION_EXPORT __declspec(dllexport)
40
+ #else
41
+ #define ARROW_PYTHON_PARQUET_ENCRYPTION_EXPORT __declspec(dllimport)
42
+ #endif
43
+
44
+ #else // Not Windows
45
+ #ifndef ARROW_PYTHON_PARQUET_ENCRYPTION_EXPORT
46
+ #define ARROW_PYTHON_PARQUET_ENCRYPTION_EXPORT __attribute__((visibility("default")))
47
+ #endif
48
+ #endif // Non-Windows
49
+
50
+ namespace arrow {
51
+ namespace py {
52
+ namespace parquet {
53
+ namespace encryption {
54
+
55
+ /// \brief A table of function pointers for calling from C++ into
56
+ /// Python.
57
+ class ARROW_PYTHON_PARQUET_ENCRYPTION_EXPORT PyKmsClientVtable {
58
+ public:
59
+ std::function<void(PyObject*, const std::string& key_bytes,
60
+ const std::string& master_key_identifier, std::string* out)>
61
+ wrap_key;
62
+ std::function<void(PyObject*, const std::string& wrapped_key,
63
+ const std::string& master_key_identifier, std::string* out)>
64
+ unwrap_key;
65
+ };
66
+
67
+ /// \brief A helper for KmsClient implementation in Python.
68
+ class ARROW_PYTHON_PARQUET_ENCRYPTION_EXPORT PyKmsClient
69
+ : public ::parquet::encryption::KmsClient {
70
+ public:
71
+ PyKmsClient(PyObject* handler, PyKmsClientVtable vtable);
72
+ ~PyKmsClient() override;
73
+
74
+ std::string WrapKey(const std::string& key_bytes,
75
+ const std::string& master_key_identifier) override;
76
+
77
+ std::string UnwrapKey(const std::string& wrapped_key,
78
+ const std::string& master_key_identifier) override;
79
+
80
+ private:
81
+ OwnedRefNoGIL handler_;
82
+ PyKmsClientVtable vtable_;
83
+ };
84
+
85
+ /// \brief A table of function pointers for calling from C++ into
86
+ /// Python.
87
+ class ARROW_PYTHON_PARQUET_ENCRYPTION_EXPORT PyKmsClientFactoryVtable {
88
+ public:
89
+ std::function<void(
90
+ PyObject*, const ::parquet::encryption::KmsConnectionConfig& kms_connection_config,
91
+ std::shared_ptr<::parquet::encryption::KmsClient>* out)>
92
+ create_kms_client;
93
+ };
94
+
95
+ /// \brief A helper for KmsClientFactory implementation in Python.
96
+ class ARROW_PYTHON_PARQUET_ENCRYPTION_EXPORT PyKmsClientFactory
97
+ : public ::parquet::encryption::KmsClientFactory {
98
+ public:
99
+ PyKmsClientFactory(PyObject* handler, PyKmsClientFactoryVtable vtable);
100
+ ~PyKmsClientFactory() override;
101
+
102
+ std::shared_ptr<::parquet::encryption::KmsClient> CreateKmsClient(
103
+ const ::parquet::encryption::KmsConnectionConfig& kms_connection_config) override;
104
+
105
+ private:
106
+ OwnedRefNoGIL handler_;
107
+ PyKmsClientFactoryVtable vtable_;
108
+ };
109
+
110
+ /// \brief A CryptoFactory that returns Results instead of throwing exceptions.
111
+ class ARROW_PYTHON_PARQUET_ENCRYPTION_EXPORT PyCryptoFactory
112
+ : public ::parquet::encryption::CryptoFactory {
113
+ public:
114
+ arrow::Result<std::shared_ptr<::parquet::FileEncryptionProperties>>
115
+ SafeGetFileEncryptionProperties(
116
+ const ::parquet::encryption::KmsConnectionConfig& kms_connection_config,
117
+ const ::parquet::encryption::EncryptionConfiguration& encryption_config);
118
+
119
+ /// The returned FileDecryptionProperties object will use the cache inside this
120
+ /// CryptoFactory object, so please keep this
121
+ /// CryptoFactory object alive along with the returned
122
+ /// FileDecryptionProperties object.
123
+ arrow::Result<std::shared_ptr<::parquet::FileDecryptionProperties>>
124
+ SafeGetFileDecryptionProperties(
125
+ const ::parquet::encryption::KmsConnectionConfig& kms_connection_config,
126
+ const ::parquet::encryption::DecryptionConfiguration& decryption_config);
127
+ };
128
+
129
+ } // namespace encryption
130
+ } // namespace parquet
131
+ } // namespace py
132
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/pch.h ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // Often-used headers, for precompiling.
19
+ // If updating this header, please make sure you check compilation speed
20
+ // before checking in. Adding headers which are not used extremely often
21
+ // may incur a slowdown, since it makes the precompiled header heavier to load.
22
+
23
+ #include "arrow/pch.h"
24
+ #include "arrow/python/platform.h"
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/platform.h ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
22
+
23
+ // If PY_SSIZE_T_CLEAN is defined, argument parsing functions treat #-specifier
24
+ // to mean Py_ssize_t (defining this to suppress deprecation warning)
25
+ #define PY_SSIZE_T_CLEAN
26
+
27
+ #include <Python.h> // IWYU pragma: export
28
+ #include <datetime.h>
29
+
30
+ // Work around C2528 error
31
+ #ifdef _MSC_VER
32
+ #if _MSC_VER >= 1900
33
+ #undef timezone
34
+ #endif
35
+
36
+ // https://bugs.python.org/issue36020
37
+ // TODO(wjones127): Can remove once we drop support for CPython 3.9
38
+ #ifdef snprintf
39
+ #undef snprintf
40
+ #endif
41
+ #endif
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/pyarrow.h ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include "arrow/python/platform.h"
21
+
22
+ #include <memory>
23
+
24
+ #include "arrow/python/visibility.h"
25
+
26
+ #include "arrow/sparse_tensor.h"
27
+
28
+ // Work around ARROW-2317 (C linkage warning from Cython)
29
+ extern "C++" {
30
+
31
+ namespace arrow {
32
+
33
+ class Array;
34
+ class Buffer;
35
+ class DataType;
36
+ class Field;
37
+ class RecordBatch;
38
+ class Schema;
39
+ class Status;
40
+ class Table;
41
+ class Tensor;
42
+
43
+ namespace py {
44
+
45
+ // Returns 0 on success, -1 on error.
46
+ ARROW_PYTHON_EXPORT int import_pyarrow();
47
+
48
+ #define DECLARE_WRAP_FUNCTIONS(FUNC_SUFFIX, TYPE_NAME) \
49
+ ARROW_PYTHON_EXPORT bool is_##FUNC_SUFFIX(PyObject*); \
50
+ ARROW_PYTHON_EXPORT Result<std::shared_ptr<TYPE_NAME>> unwrap_##FUNC_SUFFIX( \
51
+ PyObject*); \
52
+ ARROW_PYTHON_EXPORT PyObject* wrap_##FUNC_SUFFIX(const std::shared_ptr<TYPE_NAME>&);
53
+
54
+ DECLARE_WRAP_FUNCTIONS(buffer, Buffer)
55
+
56
+ DECLARE_WRAP_FUNCTIONS(data_type, DataType)
57
+ DECLARE_WRAP_FUNCTIONS(field, Field)
58
+ DECLARE_WRAP_FUNCTIONS(schema, Schema)
59
+
60
+ DECLARE_WRAP_FUNCTIONS(scalar, Scalar)
61
+
62
+ DECLARE_WRAP_FUNCTIONS(array, Array)
63
+ DECLARE_WRAP_FUNCTIONS(chunked_array, ChunkedArray)
64
+
65
+ DECLARE_WRAP_FUNCTIONS(sparse_coo_tensor, SparseCOOTensor)
66
+ DECLARE_WRAP_FUNCTIONS(sparse_csc_matrix, SparseCSCMatrix)
67
+ DECLARE_WRAP_FUNCTIONS(sparse_csf_tensor, SparseCSFTensor)
68
+ DECLARE_WRAP_FUNCTIONS(sparse_csr_matrix, SparseCSRMatrix)
69
+ DECLARE_WRAP_FUNCTIONS(tensor, Tensor)
70
+
71
+ DECLARE_WRAP_FUNCTIONS(batch, RecordBatch)
72
+ DECLARE_WRAP_FUNCTIONS(table, Table)
73
+
74
+ #undef DECLARE_WRAP_FUNCTIONS
75
+
76
+ namespace internal {
77
+
78
+ // If status is ok, return 0.
79
+ // If status is not ok, set Python error indicator and return -1.
80
+ ARROW_PYTHON_EXPORT int check_status(const Status& status);
81
+
82
+ // Convert status to a Python exception object. Status must not be ok.
83
+ ARROW_PYTHON_EXPORT PyObject* convert_status(const Status& status);
84
+
85
+ } // namespace internal
86
+ } // namespace py
87
+ } // namespace arrow
88
+
89
+ } // extern "C++"
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/pyarrow_api.h ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // For backward compatibility.
19
+ #include "arrow/python/lib_api.h"
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/pyarrow_lib.h ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // For backward compatibility.
19
+ #include "arrow/python/lib.h"
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/python_test.h ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include <functional>
21
+ #include <string>
22
+ #include <vector>
23
+
24
+ #include "arrow/status.h"
25
+
26
+ #include "arrow/python/visibility.h"
27
+
28
+ namespace arrow {
29
+ namespace py {
30
+ namespace testing {
31
+
32
+ struct TestCase {
33
+ std::string name;
34
+ std::function<Status()> func;
35
+ };
36
+
37
+ ARROW_PYTHON_EXPORT
38
+ std::vector<TestCase> GetCppTestCases();
39
+
40
+ } // namespace testing
41
+ } // namespace py
42
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/python_to_arrow.h ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 CPython built-in data structures and Arrow
19
+ // data structures
20
+
21
+ #pragma once
22
+
23
+ #include "arrow/python/platform.h"
24
+
25
+ #include <cstdint>
26
+ #include <memory>
27
+
28
+ #include "arrow/python/visibility.h"
29
+ #include "arrow/type.h"
30
+ #include "arrow/util/macros.h"
31
+
32
+ #include "arrow/python/common.h"
33
+
34
+ namespace arrow {
35
+
36
+ class Array;
37
+ class Status;
38
+
39
+ namespace py {
40
+
41
+ struct PyConversionOptions {
42
+ PyConversionOptions() = default;
43
+
44
+ PyConversionOptions(const std::shared_ptr<DataType>& type, int64_t size,
45
+ MemoryPool* pool, bool from_pandas)
46
+ : type(type), size(size), from_pandas(from_pandas) {}
47
+
48
+ // Set to null if to be inferred
49
+ std::shared_ptr<DataType> type;
50
+
51
+ // Default is -1, which indicates the size should the same as the input sequence
52
+ int64_t size = -1;
53
+
54
+ bool from_pandas = false;
55
+
56
+ /// Used to maintain backwards compatibility for
57
+ /// timezone bugs (see ARROW-9528). Should be removed
58
+ /// after Arrow 2.0 release.
59
+ bool ignore_timezone = false;
60
+
61
+ bool strict = false;
62
+ };
63
+
64
+ /// \brief Convert sequence (list, generator, NumPy array with dtype object) of
65
+ /// Python objects.
66
+ /// \param[in] obj the sequence to convert
67
+ /// \param[in] mask a NumPy array of true/false values to indicate whether
68
+ /// values in the sequence are null (true) or not null (false). This parameter
69
+ /// may be null
70
+ /// \param[in] options various conversion options
71
+ /// \param[in] pool MemoryPool to use for allocations
72
+ /// \return Result ChunkedArray
73
+ ARROW_PYTHON_EXPORT
74
+ Result<std::shared_ptr<ChunkedArray>> ConvertPySequence(
75
+ PyObject* obj, PyObject* mask, PyConversionOptions options,
76
+ MemoryPool* pool = default_memory_pool());
77
+
78
+ } // namespace py
79
+
80
+ } // namespace arrow
venv/lib/python3.10/site-packages/pyarrow/include/arrow/python/serialize.h ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #pragma once
19
+
20
+ #include <memory>
21
+ #include <vector>
22
+
23
+ #include "arrow/ipc/options.h"
24
+ #include "arrow/python/visibility.h"
25
+ #include "arrow/sparse_tensor.h"
26
+ #include "arrow/status.h"
27
+
28
+ // Forward declaring PyObject, see
29
+ // https://mail.python.org/pipermail/python-dev/2003-August/037601.html
30
+ #ifndef PyObject_HEAD
31
+ struct _object;
32
+ typedef _object PyObject;
33
+ #endif
34
+
35
+ namespace arrow {
36
+
37
+ class Buffer;
38
+ class DataType;
39
+ class MemoryPool;
40
+ class RecordBatch;
41
+ class Tensor;
42
+
43
+ namespace io {
44
+
45
+ class OutputStream;
46
+
47
+ } // namespace io
48
+
49
+ namespace py {
50
+
51
+ struct ARROW_PYTHON_EXPORT SerializedPyObject {
52
+ std::shared_ptr<RecordBatch> batch;
53
+ std::vector<std::shared_ptr<Tensor>> tensors;
54
+ std::vector<std::shared_ptr<SparseTensor>> sparse_tensors;
55
+ std::vector<std::shared_ptr<Tensor>> ndarrays;
56
+ std::vector<std::shared_ptr<Buffer>> buffers;
57
+ ipc::IpcWriteOptions ipc_options;
58
+
59
+ SerializedPyObject();
60
+
61
+ /// \brief Write serialized Python object to OutputStream
62
+ /// \param[in,out] dst an OutputStream
63
+ /// \return Status
64
+ Status WriteTo(io::OutputStream* dst);
65
+
66
+ /// \brief Convert SerializedPyObject to a dict containing the message
67
+ /// components as Buffer instances with minimal memory allocation
68
+ ///
69
+ /// {
70
+ /// 'num_tensors': M,
71
+ /// 'num_sparse_tensors': N,
72
+ /// 'num_buffers': K,
73
+ /// 'data': [Buffer]
74
+ /// }
75
+ ///
76
+ /// Each tensor is written as two buffers, one for the metadata and one for
77
+ /// the body. Therefore, the number of buffers in 'data' is 2 * M + 2 * N + K + 1,
78
+ /// with the first buffer containing the serialized record batch containing
79
+ /// the UnionArray that describes the whole object
80
+ Status GetComponents(MemoryPool* pool, PyObject** out);
81
+ };
82
+
83
+ /// \brief Serialize Python sequence as a SerializedPyObject.
84
+ /// \param[in] context Serialization context which contains custom serialization
85
+ /// and deserialization callbacks. Can be any Python object with a
86
+ /// _serialize_callback method for serialization and a _deserialize_callback
87
+ /// method for deserialization. If context is None, no custom serialization
88
+ /// will be attempted.
89
+ /// \param[in] sequence A Python sequence object to serialize to Arrow data
90
+ /// structures
91
+ /// \param[out] out The serialized representation
92
+ /// \return Status
93
+ ///
94
+ /// Release GIL before calling
95
+ ARROW_PYTHON_EXPORT
96
+ Status SerializeObject(PyObject* context, PyObject* sequence, SerializedPyObject* out);
97
+
98
+ /// \brief Serialize an Arrow Tensor as a SerializedPyObject.
99
+ /// \param[in] tensor Tensor to be serialized
100
+ /// \param[out] out The serialized representation
101
+ /// \return Status
102
+ ARROW_PYTHON_EXPORT
103
+ Status SerializeTensor(std::shared_ptr<Tensor> tensor, py::SerializedPyObject* out);
104
+
105
+ /// \brief Write the Tensor metadata header to an OutputStream.
106
+ /// \param[in] dtype DataType of the Tensor
107
+ /// \param[in] shape The shape of the tensor
108
+ /// \param[in] tensor_num_bytes The length of the Tensor data in bytes
109
+ /// \param[in] dst The OutputStream to write the Tensor header to
110
+ /// \return Status
111
+ ARROW_PYTHON_EXPORT
112
+ Status WriteNdarrayHeader(std::shared_ptr<DataType> dtype,
113
+ const std::vector<int64_t>& shape, int64_t tensor_num_bytes,
114
+ io::OutputStream* dst);
115
+
116
+ struct PythonType {
117
+ enum type {
118
+ NONE,
119
+ BOOL,
120
+ INT,
121
+ PY2INT, // Kept for compatibility
122
+ BYTES,
123
+ STRING,
124
+ HALF_FLOAT,
125
+ FLOAT,
126
+ DOUBLE,
127
+ DATE64,
128
+ LIST,
129
+ DICT,
130
+ TUPLE,
131
+ SET,
132
+ TENSOR,
133
+ NDARRAY,
134
+ BUFFER,
135
+ SPARSECOOTENSOR,
136
+ SPARSECSRMATRIX,
137
+ SPARSECSCMATRIX,
138
+ SPARSECSFTENSOR,
139
+ NUM_PYTHON_TYPES
140
+ };
141
+ };
142
+
143
+ } // namespace py
144
+
145
+ } // namespace arrow