quasardb 3.14.2.dev3__cp39-cp39-win_amd64.whl → 3.14.2.dev5__cp39-cp39-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of quasardb might be problematic. Click here for more details.

Files changed (105) hide show
  1. quasardb/INSTALL.vcxproj +5 -4
  2. quasardb/__init__.py +21 -7
  3. quasardb/cmake_install.cmake +6 -0
  4. quasardb/date/ALL_BUILD.vcxproj +9 -8
  5. quasardb/date/CMakeFiles/Export/df49adab93b9e0c10c64f72458b31971/dateTargets.cmake +2 -2
  6. quasardb/date/CMakeFiles/generate.stamp.depend +4 -4
  7. quasardb/date/INSTALL.vcxproj +5 -4
  8. quasardb/date/cmake_install.cmake +6 -0
  9. quasardb/date/dateTargets.cmake +2 -2
  10. quasardb/extensions/writer.py +59 -61
  11. quasardb/firehose.py +24 -22
  12. quasardb/numpy/__init__.py +181 -120
  13. quasardb/pandas/__init__.py +145 -95
  14. quasardb/pool.py +13 -2
  15. quasardb/pybind11/ALL_BUILD.vcxproj +9 -8
  16. quasardb/pybind11/CMakeFiles/generate.stamp.depend +14 -14
  17. quasardb/pybind11/INSTALL.vcxproj +5 -4
  18. quasardb/pybind11/cmake_install.cmake +6 -0
  19. quasardb/qdb_api.dll +0 -0
  20. quasardb/quasardb.cp39-win_amd64.pyd +0 -0
  21. quasardb/range-v3/ALL_BUILD.vcxproj +9 -8
  22. quasardb/range-v3/CMakeFiles/Export/d94ef200eca10a819b5858b33e808f5b/range-v3-targets.cmake +2 -2
  23. quasardb/range-v3/CMakeFiles/generate.stamp.depend +11 -11
  24. quasardb/range-v3/INSTALL.vcxproj +5 -4
  25. quasardb/range-v3/cmake_install.cmake +6 -0
  26. quasardb/range-v3/range-v3-config.cmake +2 -2
  27. quasardb/range-v3/range.v3.headers.vcxproj +9 -8
  28. quasardb/stats.py +92 -80
  29. quasardb/table_cache.py +5 -1
  30. {quasardb-3.14.2.dev3.dist-info → quasardb-3.14.2.dev5.dist-info}/METADATA +13 -8
  31. quasardb-3.14.2.dev5.dist-info/RECORD +54 -0
  32. {quasardb-3.14.2.dev3.dist-info → quasardb-3.14.2.dev5.dist-info}/WHEEL +1 -1
  33. quasardb/CMakeLists.txt +0 -517
  34. quasardb/batch_column.hpp +0 -80
  35. quasardb/batch_inserter.hpp +0 -248
  36. quasardb/blob.hpp +0 -150
  37. quasardb/cluster.cpp +0 -102
  38. quasardb/cluster.hpp +0 -593
  39. quasardb/concepts.hpp +0 -322
  40. quasardb/continuous.cpp +0 -199
  41. quasardb/continuous.hpp +0 -109
  42. quasardb/convert/array.hpp +0 -299
  43. quasardb/convert/point.hpp +0 -330
  44. quasardb/convert/range.hpp +0 -282
  45. quasardb/convert/unicode.hpp +0 -598
  46. quasardb/convert/util.hpp +0 -22
  47. quasardb/convert/value.hpp +0 -782
  48. quasardb/convert.hpp +0 -38
  49. quasardb/detail/invoke.hpp +0 -0
  50. quasardb/detail/qdb_resource.hpp +0 -129
  51. quasardb/detail/retry.cpp +0 -30
  52. quasardb/detail/retry.hpp +0 -147
  53. quasardb/detail/sleep.hpp +0 -53
  54. quasardb/detail/ts_column.hpp +0 -224
  55. quasardb/detail/writer.cpp +0 -440
  56. quasardb/detail/writer.hpp +0 -550
  57. quasardb/direct_blob.hpp +0 -108
  58. quasardb/direct_handle.hpp +0 -83
  59. quasardb/direct_integer.hpp +0 -94
  60. quasardb/dispatch.hpp +0 -157
  61. quasardb/double.hpp +0 -87
  62. quasardb/entry.hpp +0 -273
  63. quasardb/error.hpp +0 -393
  64. quasardb/handle.cpp +0 -29
  65. quasardb/handle.hpp +0 -98
  66. quasardb/integer.hpp +0 -88
  67. quasardb/logger.cpp +0 -106
  68. quasardb/logger.hpp +0 -228
  69. quasardb/masked_array.hpp +0 -658
  70. quasardb/metrics.cpp +0 -103
  71. quasardb/metrics.hpp +0 -112
  72. quasardb/module.cpp +0 -92
  73. quasardb/module.hpp +0 -24
  74. quasardb/node.hpp +0 -132
  75. quasardb/numpy.cpp +0 -6
  76. quasardb/numpy.hpp +0 -489
  77. quasardb/object_tracker.hpp +0 -282
  78. quasardb/options.hpp +0 -273
  79. quasardb/perf.hpp +0 -336
  80. quasardb/properties.cpp +0 -41
  81. quasardb/properties.hpp +0 -85
  82. quasardb/pytypes.hpp +0 -221
  83. quasardb/query.cpp +0 -420
  84. quasardb/query.hpp +0 -92
  85. quasardb/reader.cpp +0 -282
  86. quasardb/reader.hpp +0 -256
  87. quasardb/remove_cvref.hpp +0 -31
  88. quasardb/string.hpp +0 -160
  89. quasardb/table.cpp +0 -257
  90. quasardb/table.hpp +0 -366
  91. quasardb/tag.hpp +0 -77
  92. quasardb/timestamp.hpp +0 -97
  93. quasardb/traits.hpp +0 -642
  94. quasardb/ts_iterator.hpp +0 -193
  95. quasardb/utils/blob_deque.hpp +0 -96
  96. quasardb/utils/ostream.hpp +0 -17
  97. quasardb/utils/permutation.hpp +0 -50
  98. quasardb/utils/stable_sort.hpp +0 -25
  99. quasardb/utils/unzip_view.hpp +0 -89
  100. quasardb/utils.cpp +0 -28
  101. quasardb/utils.hpp +0 -174
  102. quasardb/writer.hpp +0 -354
  103. quasardb-3.14.2.dev3.dist-info/RECORD +0 -124
  104. {quasardb-3.14.2.dev3.dist-info → quasardb-3.14.2.dev5.dist-info}/LICENSE.md +0 -0
  105. {quasardb-3.14.2.dev3.dist-info → quasardb-3.14.2.dev5.dist-info}/top_level.txt +0 -0
quasardb/masked_array.hpp DELETED
@@ -1,658 +0,0 @@
1
- /*
2
- *
3
- * Official Python API
4
- *
5
- * Copyright (c) 2009-2024, quasardb SAS. All rights reserved.
6
- * All rights reserved.
7
- *
8
- * Redistribution and use in source and binary forms, with or without
9
- * modification, are permitted provided that the following conditions are met:
10
- *
11
- * * Redistributions of source code must retain the above copyright
12
- * notice, this list of conditions and the following disclaimer.
13
- * * Redistributions in binary form must reproduce the above copyright
14
- * notice, this list of conditions and the following disclaimer in the
15
- * documentation and/or other materials provided with the distribution.
16
- * * Neither the name of quasardb nor the names of its contributors may
17
- * be used to endorse or promote products derived from this software
18
- * without specific prior written permission.
19
- *
20
- * THIS SOFTWARE IS PROVIDED BY QUASARDB AND CONTRIBUTORS ``AS IS'' AND ANY
21
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
- * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
24
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
- */
31
- #pragma once
32
-
33
- #include "concepts.hpp"
34
- #include "numpy.hpp"
35
- #include "traits.hpp"
36
- #include <pybind11/numpy.h>
37
- #include <pybind11/stl_bind.h>
38
- #include <range/v3/algorithm/for_each.hpp>
39
- #include <range/v3/view/chunk.hpp>
40
- #include <range/v3/view/counted.hpp>
41
-
42
- namespace qdb::detail
43
- {
44
-
45
- enum mask_probe_t
46
- {
47
- mask_unknown = 0,
48
- mask_all_true = 1 << 0,
49
- mask_all_false = 1 << 1,
50
- mask_mixed = mask_all_true | mask_all_false
51
- };
52
-
53
- /**
54
- * Efficiently probes one chunk, without returning early.
55
- */
56
- template <typename Rng>
57
- inline std::uint8_t probe_chunk(Rng const & xs) noexcept
58
- {
59
- std::uint8_t state{static_cast<std::uint8_t>(mask_unknown)};
60
-
61
- // XXX(leon): Super hot code path, but it's auto-vectorized which makes it
62
- // faster than any alternative (including reinterpreting them
63
- // as 64-bit integers).
64
- ranges::for_each(xs, [&state](bool x) -> void {
65
- state |=
66
- (x ? static_cast<std::uint8_t>(mask_all_true) : static_cast<std::uint8_t>(mask_all_false));
67
- });
68
-
69
- return state;
70
- }
71
-
72
- template <typename Rng>
73
- inline enum qdb::detail::mask_probe_t probe_mask(Rng const & xs) noexcept
74
- {
75
- // We don't accept empty arrays
76
- assert(ranges::size(xs) > 0);
77
-
78
- // In order for auto-vectorization to work, we use an outer loop (this function)
79
- // which divides work into chunks of 256 booleans; these are then processed as
80
- // one work unit.
81
- //
82
- // The outer loop checks whether we already have a mixed mask, and shortcuts when
83
- // that's the case.
84
- //
85
- // This ensures that, if we're dealing with large, mixed masked, we scan only a
86
- // fraction of it.
87
- constexpr std::size_t chunk_size = 256; // not chosen scientifically
88
- std::uint8_t state = mask_unknown;
89
-
90
- // Interpret the booleans as a range with `chunk_size` chunks of data.
91
- auto rng = xs | ranges::views::chunk(chunk_size);
92
-
93
- for (auto chunk : rng)
94
- {
95
- state |= probe_chunk(chunk);
96
-
97
- if (state == mask_mixed)
98
- {
99
- // Exit early if we have found mixed data.
100
- break;
101
- }
102
- }
103
-
104
- assert(0 < state && state <= 3);
105
- return static_cast<mask_probe_t>(state);
106
- }
107
-
108
- inline enum qdb::detail::mask_probe_t probe_mask(bool const * xs, std::size_t n) noexcept
109
- {
110
- return probe_mask(ranges::views::counted(xs, n));
111
- };
112
-
113
- inline enum mask_probe_t probe_mask(py::array const & xs) noexcept
114
- {
115
- assert(xs.dtype().kind() == 'b');
116
- bool const * xs_ = xs.unchecked<bool>().data();
117
- return probe_mask(xs_, xs.size());
118
- };
119
-
120
- template <bool v>
121
- constexpr mask_probe_t probe_of_bool();
122
-
123
- template <>
124
- constexpr inline mask_probe_t probe_of_bool<true>()
125
- {
126
- return mask_all_true;
127
- };
128
-
129
- template <>
130
- constexpr inline mask_probe_t probe_of_bool<false>()
131
- {
132
- return mask_all_false;
133
- };
134
-
135
- constexpr inline mask_probe_t probe_of_bool(bool b)
136
- {
137
- return (b == true ? probe_of_bool<true>() : probe_of_bool<false>());
138
- };
139
-
140
- template <mask_probe_t v>
141
- constexpr bool bool_of_probe();
142
-
143
- template <>
144
- constexpr inline bool bool_of_probe<mask_all_true>()
145
- {
146
- return true;
147
- };
148
-
149
- template <>
150
- constexpr inline bool bool_of_probe<mask_all_false>()
151
- {
152
- return false;
153
- };
154
-
155
- constexpr inline bool bool_of_probe(mask_probe_t p)
156
- {
157
- switch (p)
158
- {
159
- case mask_all_true:
160
- return true;
161
- case mask_all_false:
162
- return false;
163
- default:
164
- throw qdb::internal_local_exception(
165
- "Mask probe not convertible to boolean: " + std::to_string(p));
166
- };
167
- };
168
-
169
- }; // namespace qdb::detail
170
-
171
- namespace qdb
172
- {
173
- namespace py = pybind11;
174
-
175
- class mask
176
- {
177
- public:
178
- /**
179
- * Default constructor required because objects of this class are wrapped
180
- * inside masked_array, and py::cast needs default constructors to work.
181
- */
182
- inline mask() noexcept {};
183
-
184
- inline mask(mask const & o) noexcept
185
- : xs_{o.xs_}
186
- , probe_{o.probe_} {};
187
-
188
- inline mask(mask && o) noexcept
189
- : xs_{std::move(o.xs_)}
190
- , probe_{std::move(o.probe_)} {};
191
-
192
- inline mask(py::array const & xs, detail::mask_probe_t probe) noexcept
193
- : xs_{xs}
194
- , probe_{probe} {};
195
-
196
- inline mask & operator=(mask const & o) noexcept
197
- {
198
- xs_ = o.xs_;
199
- probe_ = o.probe_;
200
- return *this;
201
- };
202
-
203
- static inline mask of_array(py::array const & xs) noexcept
204
- {
205
- return mask{xs, detail::probe_mask(xs)};
206
- };
207
-
208
- inline bool load(py::array const & xs) noexcept
209
- {
210
- return load(xs, detail::probe_mask(xs));
211
- }
212
-
213
- inline bool load(py::array const & xs, detail::mask_probe_t probe) noexcept
214
- {
215
- if (xs.size() == 0) [[unlikely]]
216
- {
217
- return false;
218
- };
219
-
220
- xs_ = xs;
221
- probe_ = probe;
222
- return true;
223
- }
224
- /**
225
- * Initialize a mask of size `n` with all values set to `true` (everything
226
- * masked, i.e. everything hidden).
227
- */
228
- template <bool v>
229
- static inline mask of_all(py::ssize_t n) noexcept
230
- {
231
- assert(n > 0);
232
- return mask{numpy::array::initialize(n, v), detail::probe_of_bool(v)};
233
- };
234
-
235
- /**
236
- * Initialize a mask of size `n` with all values set to `true`.
237
- */
238
- template <detail::mask_probe_t p>
239
- static inline mask of_probe(py::ssize_t n) noexcept
240
- {
241
- assert(n > 0);
242
- return mask{numpy::array::initialize(n, detail::bool_of_probe<p>()), p};
243
- };
244
-
245
- /**
246
- * Returns amount of elemenbts in the mask.
247
- */
248
- py::ssize_t size() const noexcept
249
- {
250
- return xs_.size();
251
- };
252
-
253
- py::array const & array() const noexcept
254
- {
255
- return xs_;
256
- };
257
-
258
- bool const * data() const noexcept
259
- {
260
- return xs_.unchecked<bool>().data();
261
- };
262
-
263
- bool * mutable_data() noexcept
264
- {
265
- return xs_.mutable_unchecked<bool>().mutable_data();
266
- };
267
-
268
- detail::mask_probe_t probe() const noexcept
269
- {
270
- return probe_;
271
- };
272
-
273
- private:
274
- py::array xs_;
275
- detail::mask_probe_t probe_;
276
- };
277
-
278
- /**
279
- * Masked array that can hold any type of data. Types are templated in the member
280
- * functions that require them, and no type checking is done upon initialization.
281
- */
282
- class masked_array
283
- {
284
- public:
285
- using ShapeContainer = typename py::array::ShapeContainer;
286
-
287
- public:
288
- // Default constructor 'deleted' but necessary for py::cast
289
- masked_array() = default;
290
-
291
- // Initialize a masked array with everything open
292
- explicit masked_array(py::array arr)
293
- : masked_array(arr, qdb::mask::of_probe<detail::mask_all_false>(arr.size()))
294
- {}
295
-
296
- // Initialized from an array and a mask array. Mask array should be with dtype bool.
297
- // Automatically 'probes' the mask to find all-true / all-false patterns.
298
- masked_array(py::array arr, py::array mask)
299
- : masked_array{arr, mask::of_array(mask)}
300
- {}
301
-
302
- // Initialized from an array and a mask array. Mask
303
- // array should be with dtype bool. True indicates masked (invisible).
304
- masked_array(py::array arr, qdb::mask mask)
305
- : logger_("quasardb.masked_array")
306
- , arr_{arr}
307
- , mask_{mask}
308
- {
309
- assert(arr.size() == mask.size());
310
- }
311
-
312
- // Copy constructor
313
- masked_array(const masked_array & ma)
314
- : arr_{ma.arr_}
315
- , mask_{ma.mask_}
316
- {}
317
-
318
- ~masked_array()
319
- {}
320
-
321
- /**
322
- * Cast this masked array to an actual numpy.ma.MaskedArray. This invokes
323
- * a python function and can be slow.
324
- */
325
- py::handle cast(py::return_value_policy policy) const
326
- {
327
- py::module numpy_ma = py::module::import("numpy.ma");
328
- py::object init = numpy_ma.attr("masked_array");
329
-
330
- return init(arr_, mask_.array()).inc_ref();
331
- }
332
-
333
- py::array data() const
334
- {
335
- return arr_;
336
- }
337
-
338
- qdb::mask const & mask() const
339
- {
340
- return mask_;
341
- }
342
-
343
- inline bool load(py::object src)
344
- {
345
-
346
- if (masked_array::check(src)) [[likely]]
347
- {
348
- // This is an actual numpy.ma.array
349
- logger_.debug("loading masked array from numpy.ma.MaskedArray object");
350
- return load(src.attr("data"), src.attr("mask"));
351
- }
352
- else if (py::isinstance<py::array>(src))
353
- {
354
- logger_.debug(
355
- "initializing quasardb.masked_array from numpy.ndarray with size %d", arr_.size());
356
- py::array src_ = py::cast<py::array>(src);
357
- return load(src_, mask::of_all<false>(src_.size()));
358
- }
359
-
360
- return false;
361
- }
362
-
363
- inline bool load(py::array arr, py::array mask)
364
- {
365
- if (arr.size() != mask.size())
366
- {
367
- logger_.warn("array[%d] and mask[%d] not of identical size", arr.size(), mask.size());
368
- };
369
- assert(arr.size() == mask.size());
370
-
371
- arr_ = py::array::ensure(arr);
372
- if (mask_.load(mask) == false)
373
- {
374
- logger_.warn("unable to load mask");
375
- return false;
376
- };
377
-
378
- return true;
379
- }
380
-
381
- inline bool load(py::array arr, qdb::mask mask)
382
- {
383
- assert(arr.size() == mask.size());
384
-
385
- arr_ = py::array::ensure(arr);
386
- mask_ = mask;
387
-
388
- return true;
389
- }
390
-
391
- bool load(std::pair<py::array, py::array> const & src)
392
- {
393
- return load(std::get<0>(src), std::get<1>(src));
394
- }
395
-
396
- /**
397
- * Returns `true` if handle is of a masked array type.
398
- */
399
- static bool check(py::handle x)
400
- {
401
- // XXX(leon): perhaps there's a higher performance way to check the
402
- // type, such as acquiring a reference to the type of
403
- // `numpy.MaskedArray` and invoking py::isinstance().
404
- //
405
- // but this path is not very performance critical.
406
- py::module numpy_ma = py::module::import("numpy.ma");
407
- py::object isMA = numpy_ma.attr("isMaskedArray");
408
-
409
- return py::cast<bool>(isMA(x));
410
- }
411
-
412
- inline py::dtype dtype() const
413
- {
414
- return arr_.dtype();
415
- }
416
-
417
- /**
418
- * Returns size of array. Includes "masked" items, i.e. those that are not visible.
419
- */
420
- inline std::size_t size() const noexcept
421
- {
422
- assert(arr_.size() == mask_.size());
423
- return arr_.size();
424
- }
425
-
426
- inline ShapeContainer shape() const noexcept
427
- {
428
- return ShapeContainer{{size()}};
429
- }
430
-
431
- /**
432
- * Return a regular numpy array with the masked values "filled" with
433
- * the provided value.
434
- *
435
- * The behavior mirrors the numpy.ma.filled function, and aligns fairly
436
- * well with how QuasarDB wants data to be shaped.
437
- *
438
- * This specific implementation is for dtypes with fixed length, which
439
- * allows us to use "fast" point-based copies.
440
- */
441
- template <concepts::dtype T>
442
- inline py::array filled(typename T::value_type const & fill_value) const
443
- {
444
- assert(arr_.size() == mask_.size());
445
-
446
- py::array ret;
447
-
448
- switch (mask_.probe())
449
- {
450
- case detail::mask_all_true:
451
- // Everything masked: which can just initialize a whole array with fill_value
452
- // and call it a day.
453
- return qdb::numpy::array::initialize<T>(arr_.size(), fill_value);
454
- break;
455
-
456
- case detail::mask_all_false:
457
- // Fast(est) path: nothing masked, which implies it's identical to arr_
458
- return arr_;
459
-
460
- case detail::mask_mixed:
461
- return qdb::numpy::array::fill_with_mask<T>(arr_, mask_.array(), fill_value);
462
- case detail::mask_unknown:
463
- // This is an internal error: mask should always be probed (as it's probed
464
- // in the constructor).
465
- //
466
- // Only condition would be when masked_array is default-constructed and
467
- // not initialized.
468
- throw qdb::internal_local_exception{"Mask probe is unknown, masked array not initialized?"};
469
-
470
- default:
471
- throw qdb::internal_local_exception{
472
- "Mask probe is corrupted: not a known value: " + std::to_string(mask_.probe())};
473
- };
474
- }
475
-
476
- template <concepts::dtype T>
477
- inline py::array filled() const
478
- {
479
- return filled<T>(T::null_value());
480
- }
481
-
482
- static inline masked_array masked_all(py::array xs)
483
- {
484
- return masked_array{xs, mask::of_all<true>(xs.size())};
485
- };
486
-
487
- static inline masked_array masked_none(py::array xs)
488
- {
489
- return masked_array{xs, mask::of_all<false>(xs.size())};
490
- };
491
-
492
- // Initialize an array mask from a regular array and a "null" value.
493
- //
494
- // Intended to be used as follows:
495
- //
496
- // py::array xs{"float64", 100};
497
- // // .. fill data, some of them NaN .. //
498
- // auto ma = masked_array{xs, masked_array::masked_null(xs)};
499
-
500
- template <concepts::dtype Dtype>
501
- static qdb::mask masked_null(py::array const & xs)
502
- {
503
- using value_type = typename Dtype::value_type;
504
-
505
- py::array_t<bool> ret{ShapeContainer{xs.size()}};
506
- bool * p_ret = static_cast<bool *>(ret.mutable_data());
507
-
508
- // The step_size is `1` for all fixed-width dtypes, but in case
509
- // of variable width dtypes, is, well, variable.
510
- py::ssize_t step_size = Dtype::stride_size(xs.itemsize());
511
-
512
- value_type const * begin = static_cast<value_type const *>(xs.data());
513
- value_type const * end = begin + (xs.size() * step_size);
514
-
515
- // TODO(leon): [perf] we should be able to determine the mask_probe_t while
516
- // we iterate over this array.
517
- for (value_type const * cur = begin; cur != end; cur += step_size, ++p_ret)
518
- {
519
- *p_ret = Dtype::is_null(*cur);
520
- };
521
-
522
- return mask::of_array(py::cast<py::array>(ret));
523
- }
524
-
525
- protected:
526
- qdb::logger logger_;
527
- py::array arr_;
528
- qdb::mask mask_;
529
- };
530
-
531
- /**
532
- * "Typed" masked array, like py::array / py::array_t, except in our case our 'type'
533
- * is our dtype dispatch tag.
534
- *
535
- * IMPORTANT: we do *not* have a virtual destructor, this is fine because we do not
536
- * have any member objects.
537
- */
538
- template <concepts::dtype T>
539
- class masked_array_t : public masked_array
540
- {
541
- public:
542
- bool load(py::object src)
543
- {
544
- if (masked_array::load(src) == true) [[likely]]
545
- {
546
- return true;
547
- }
548
-
549
- if (py::isinstance<py::list>(src))
550
- {
551
- logger_.warn("Converting list to masked array: this is a very expensive operation. If you "
552
- "are having performance issues, "
553
- "consider using numpy.ndarray instead..");
554
-
555
- // Convert list to numpy array and try again.
556
- //
557
- // The reason we can do this, is that because we have the "additional" context
558
- // in masked_array_t of knowing what dtype we're looking for, we can also
559
- // reasonably cast a list to that type; otherwise you'll end up with a numpy
560
- // array of objects, which is very much meh.
561
- return masked_array::load(numpy::array::of_list_with_mask<T>(py::cast<py::list>(src)));
562
- }
563
-
564
- return false;
565
- }
566
-
567
- static py::array masked_null(py::array const & xs)
568
- {
569
- return masked_array::masked_null<T>(xs);
570
- };
571
-
572
- inline py::array filled(typename T::value_type const & fill_value) const
573
- {
574
- return masked_array::filled<T>(fill_value);
575
- };
576
-
577
- inline py::array filled() const
578
- {
579
- return masked_array::filled<T>(T::null_value());
580
- };
581
- };
582
-
583
- template <typename Module>
584
- static inline void register_masked_array(Module & m)
585
- {
586
- namespace py = pybind11;
587
-
588
- py::class_<masked_array>{m, "MaskedArray"};
589
- }
590
-
591
- } // namespace qdb
592
-
593
- namespace PYBIND11_NAMESPACE
594
- {
595
- namespace detail
596
- {
597
-
598
- /**
599
- * Implements custom type caster for our ts_value class, so that conversion
600
- * to and from native python types is completely transparent.
601
- */
602
- template <>
603
- struct type_caster<qdb::masked_array>
604
- {
605
- public:
606
- /**
607
- * Note that this macro magically sets a member variable called 'value'.
608
- */
609
- PYBIND11_TYPE_CASTER(qdb::masked_array, const_name("numpy.ma.MaskedArray"));
610
-
611
- /**
612
- * Python->C++.
613
- */
614
- bool load(py::handle src, bool)
615
- {
616
- py::object obj = reinterpret_borrow<py::object>(src);
617
- bool result = value.load(obj);
618
- return result;
619
- }
620
-
621
- /**
622
- * C++->Python
623
- */
624
- static py::handle cast(qdb::masked_array && src, return_value_policy policy, handle /* parent */)
625
- {
626
- return src.cast(policy);
627
- }
628
- };
629
-
630
- template <qdb::concepts::dtype T>
631
- struct type_caster<qdb::masked_array_t<T>>
632
- {
633
- public:
634
- using type = qdb::masked_array_t<T>;
635
- PYBIND11_TYPE_CASTER(type, const_name("numpy.ma.MaskedArray<T>"));
636
-
637
- /**
638
- * Python->C++.
639
- */
640
- bool load(py::handle src, bool)
641
- {
642
- py::object obj = reinterpret_borrow<py::object>(src);
643
- bool result = value.load(obj);
644
- return result;
645
- };
646
-
647
- /**
648
- * C++->Python
649
- */
650
- static py::object cast(type && src, return_value_policy policy, handle /* parent */)
651
- {
652
- return src.cast(policy);
653
- }
654
- };
655
-
656
- }; // namespace detail
657
-
658
- }; // namespace PYBIND11_NAMESPACE