|
23 | 23 | #include "duckdb/main/chunk_scan_state/query_result.hpp" |
24 | 24 | #include "duckdb/common/arrow/arrow_query_result.hpp" |
25 | 25 |
|
| 26 | +using namespace pybind11::literals; |
| 27 | + |
26 | 28 | namespace duckdb { |
27 | 29 |
|
28 | 30 | DuckDBPyResult::DuckDBPyResult(unique_ptr<QueryResult> result_p) : result(std::move(result_p)) { |
@@ -293,8 +295,10 @@ void DuckDBPyResult::ChangeToTZType(PandasDataFrame &df) { |
293 | 295 | if (result->types[i] == LogicalType::TIMESTAMP_TZ) { |
294 | 296 | // first localize to UTC then convert to timezone_config |
295 | 297 | auto utc_local = df[names[i].c_str()].attr("dt").attr("tz_localize")("UTC"); |
296 | | - df.attr("__setitem__")(names[i].c_str(), |
297 | | - utc_local.attr("dt").attr("tz_convert")(result->client_properties.time_zone)); |
| 298 | + auto new_value = utc_local.attr("dt").attr("tz_convert")(result->client_properties.time_zone); |
| 299 | + // We need to create the column anew because the exact dt changed to a new timezone |
| 300 | + df.attr("drop")("columns"_a = names[i].c_str(), "inplace"_a = true); |
| 301 | + df.attr("__setitem__")(names[i].c_str(), new_value); |
298 | 302 | } |
299 | 303 | } |
300 | 304 | } |
@@ -378,7 +382,9 @@ PandasDataFrame DuckDBPyResult::FrameFromNumpy(bool date_as_object, const py::ha |
378 | 382 | if (date_as_object) { |
379 | 383 | for (idx_t i = 0; i < result->ColumnCount(); i++) { |
380 | 384 | if (result->types[i] == LogicalType::DATE) { |
381 | | - df.attr("__setitem__")(names[i].c_str(), df[names[i].c_str()].attr("dt").attr("date")); |
| 385 | + auto new_value = df[names[i].c_str()].attr("dt").attr("date"); |
| 386 | + df.attr("drop")("columns"_a = names[i].c_str(), "inplace"_a = true); |
| 387 | + df.attr("__setitem__")(names[i].c_str(), new_value); |
382 | 388 | } |
383 | 389 | } |
384 | 390 | } |
|
0 commit comments