forked from duckdb/duckdb-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyresult.hpp
More file actions
86 lines (59 loc) · 2.5 KB
/
pyresult.hpp
File metadata and controls
86 lines (59 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//===----------------------------------------------------------------------===//
// DuckDB
//
// duckdb_python/pyresult.hpp
//
//
//===----------------------------------------------------------------------===//
#pragma once
#include "duckdb_python/numpy/numpy_result_conversion.hpp"
#include "duckdb.hpp"
#include "duckdb/main/chunk_scan_state.hpp"
#include "duckdb_python/pybind11/pybind_wrapper.hpp"
#include "duckdb_python/python_objects.hpp"
#include "duckdb_python/pybind11/dataframe.hpp"
namespace duckdb {
struct DuckDBPyResult {
public:
explicit DuckDBPyResult(unique_ptr<QueryResult> result);
~DuckDBPyResult();
public:
Optional<py::tuple> Fetchone();
py::list Fetchmany(idx_t size);
py::list Fetchall();
py::dict FetchNumpy();
py::dict FetchNumpyInternal(bool stream = false, idx_t vectors_per_chunk = 1,
unique_ptr<NumpyResultConversion> conversion = nullptr);
PandasDataFrame FetchDF(bool date_as_object);
duckdb::pyarrow::Table FetchArrowTable(idx_t rows_per_batch, bool to_polars);
PandasDataFrame FetchDFChunk(const idx_t vectors_per_chunk = 1, bool date_as_object = false);
py::dict FetchPyTorch();
py::dict FetchTF();
ArrowArrayStream FetchArrowArrayStream(idx_t rows_per_batch = 1000000);
duckdb::pyarrow::RecordBatchReader FetchRecordBatchReader(idx_t rows_per_batch = 1000000);
py::object FetchArrowCapsule(idx_t rows_per_batch = 1000000);
static py::list GetDescription(const vector<string> &names, const vector<LogicalType> &types);
void Close();
bool IsClosed() const;
unique_ptr<DataChunk> FetchChunk();
const vector<string> &GetNames();
const vector<LogicalType> &GetTypes();
ClientProperties GetClientProperties();
private:
void FillNumpy(py::dict &res, idx_t col_idx, NumpyResultConversion &conversion, const char *name);
PandasDataFrame FrameFromNumpy(bool date_as_object, const py::handle &o);
void ConvertDateTimeTypes(PandasDataFrame &df, bool date_as_object) const;
unique_ptr<DataChunk> FetchNext(QueryResult &result);
unique_ptr<DataChunk> FetchNextRaw(QueryResult &result);
unique_ptr<NumpyResultConversion> InitializeNumpyConversion(bool pandas = false);
private:
idx_t chunk_offset = 0;
unique_ptr<QueryResult> result;
unique_ptr<DataChunk> current_chunk;
// Holds the categories of Categorical/ENUM types
unordered_map<idx_t, py::list> categories;
// Holds the categorical type of Categorical/ENUM types
unordered_map<idx_t, py::object> categories_type;
bool result_closed = false;
};
} // namespace duckdb