31 DAPySeries& operator=(
const pybind11::object& obj);
37 pybind11::object operator[](std::size_t i)
const;
39 pybind11::object operator[](
const QString& colName)
const;
43 pybind11::dtype dtype()
const;
47 std::size_t size()
const;
51 pybind11::object iat(std::size_t i)
const;
52 void iat(std::size_t r,
const pybind11::object& v);
54 QVariant value(std::size_t i)
const;
55 bool setValue(std::size_t i,
const QVariant& v);
57 bool isNumeric()
const;
58 bool isDateTime()
const;
59 bool isString()
const;
60 bool isCategorical()
const;
64 QStringList indexAsStringList()
const;
65 QVector< double > indexAsDoubleVector()
const;
66 QVector< QDateTime > indexAsDateTimeVector()
const;
68 DAPySeries astype(
const pybind11::dtype& dt)
const;
73 static bool isSeries(
const pybind11::object& obj);
75 template<
typename T,
typename VectLikeIte >
76 void castTo(VectLikeIte begin)
const;
80 void checkObjectValid();
84 QString toString(std::size_t maxele = 12)
const;
121 pybind11::object series = object();
122 pybind11::object values = series.attr(
"values");
125 if (pybind11::isinstance(series, pybind11::module::import(
"pandas").
attr(
"Series"))) {
126 pybind11::object
dtype = series.attr(
"dtype");
127 std::string dtype_str = pybind11::str(
dtype).cast< std::string >();
130 if (dtype_str.find(
"datetime64") == 0) {
132 bool has_timezone =
false;
134 pybind11::object dt_accessor = series.attr(
"dt");
135 pybind11::object tz = dt_accessor.attr(
"tz");
136 has_timezone = !tz.is_none();
138 has_timezone =
false;
143 pybind11::object dt_accessor = series.attr(
"dt");
144 pybind11::object utc_series = dt_accessor.attr(
"tz_convert")(
"UTC");
145 values = utc_series.attr(
"astype")(
"int64").
attr(
"values");
148 values = series.attr(
"astype")(
"int64").
attr(
"values");
153 values.cast< pybind11::array_t< int64_t, pybind11::array::c_style | pybind11::array::forcecast > >();
155 std::transform(buf.data(), buf.data() + buf.size(), begin, [](int64_t ns) ->
double {
156 qint64 utcMs = ns / 1'000'000;
162 else if (dtype_str.find(
"timedelta64") == 0) {
164 values = series.attr(
"astype")(
"int64").
attr(
"values");
171 values.cast< pybind11::array_t< int64_t, pybind11::array::c_style | pybind11::array::forcecast > >();
172 std::transform(buf.data(), buf.data() + buf.size(), begin, [](int64_t ns) ->
double {
173 return static_cast< double >(ns) / 1e9;
178 else if (dtype_str.find(
"category") == 0) {
180 values = series.attr(
"cat").attr(
"codes").attr(
"values");
181 auto buf = values.cast< pybind11::array_t< T, pybind11::array::c_style | pybind11::array::forcecast > >();
182 std::copy(buf.data(), buf.data() + buf.size(), begin);
186 else if (dtype_str ==
"bool") {
187 values = series.attr(
"astype")(
"int8").
attr(
"values");
188 auto buf = values.cast< pybind11::array_t< int8_t, pybind11::array::c_style | pybind11::array::forcecast > >();
189 std::transform(buf.data(), buf.data() + buf.size(), begin, [](int8_t b) -> T { return static_cast< T >(b); });
195 auto buf = values.cast< pybind11::array_t< T, pybind11::array::c_style | pybind11::array::forcecast > >();
196 std::copy(buf.data(), buf.data() + buf.size(), begin);
pybind11::dtype dtype() const
Return the dtype object of the underlying data.
Definition DAPySeries.cpp:110
std::vector< double > toVectorDouble(const DAPySeries &ser)
series 转换为vector< double >
Definition DAPySeries.cpp:386
QVector< double > toQVectorDouble(const DAPySeries &ser)
series 转换为QVector< double >
Definition DAPySeries.cpp:408