Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/duckdb_py/pyresult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ void DuckDBPyResult::ChangeToTZType(PandasDataFrame &df) {
auto new_value = utc_local.attr("dt").attr("tz_convert")(result->client_properties.time_zone);
// We need to create the column anew because the exact dt changed to a new timezone
df.attr("drop")("columns"_a = names[i].c_str(), "inplace"_a = true);
df.attr("__setitem__")(names[i].c_str(), new_value);
df.attr("insert")(i, names[i].c_str(), new_value);
}
}
}
Expand Down Expand Up @@ -384,7 +384,7 @@ PandasDataFrame DuckDBPyResult::FrameFromNumpy(bool date_as_object, const py::ha
if (result->types[i] == LogicalType::DATE) {
auto new_value = df[names[i].c_str()].attr("dt").attr("date");
df.attr("drop")("columns"_a = names[i].c_str(), "inplace"_a = true);
df.attr("__setitem__")(names[i].c_str(), new_value);
df.attr("insert")(i, names[i].c_str(), new_value);
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions tests/fast/pandas/test_column_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest

import pandas as pd
import duckdb

class TestColumnOrder:
def test_column_order(self, duckdb_cursor):
to_execute = """
CREATE OR REPLACE TABLE t1 AS (
SELECT NULL AS col1,
NULL::TIMESTAMPTZ AS timepoint,
);
SELECT timepoint, col1 FROM t1;
"""
df = duckdb.execute(to_execute).fetchdf()
cols = list(df.columns)
assert cols == ['timepoint', 'col1']
Loading