Skip to content

Commit 18f5674

Browse files
committed
fix pandas tests
1 parent dbef096 commit 18f5674

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ test = [ # dependencies used for running tests
233233
"pytest",
234234
"pytest-reraise",
235235
"pytest-timeout",
236+
"pytest-xdist",
237+
"pytest-randomly",
238+
"pytest-timestamper",
236239
"mypy",
237240
"coverage",
238241
"gcovr",

src/duckdb_py/pyresult.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include "duckdb/main/chunk_scan_state/query_result.hpp"
2424
#include "duckdb/common/arrow/arrow_query_result.hpp"
2525

26+
using namespace pybind11::literals;
27+
2628
namespace duckdb {
2729

2830
DuckDBPyResult::DuckDBPyResult(unique_ptr<QueryResult> result_p) : result(std::move(result_p)) {
@@ -293,8 +295,10 @@ void DuckDBPyResult::ChangeToTZType(PandasDataFrame &df) {
293295
if (result->types[i] == LogicalType::TIMESTAMP_TZ) {
294296
// first localize to UTC then convert to timezone_config
295297
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);
298302
}
299303
}
300304
}
@@ -378,7 +382,9 @@ PandasDataFrame DuckDBPyResult::FrameFromNumpy(bool date_as_object, const py::ha
378382
if (date_as_object) {
379383
for (idx_t i = 0; i < result->ColumnCount(); i++) {
380384
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);
382388
}
383389
}
384390
}

0 commit comments

Comments
 (0)