@@ -585,13 +585,20 @@ py::object PythonObject::FromValue(const Value &val, const LogicalType &type,
585585 auto tmp_datetime_with_tz = import_cache.datetime .datetime .combine ()(tmp_datetime, py_time, timezone_offset);
586586 return tmp_datetime_with_tz.attr (" timetz" )();
587587 }
588- case LogicalTypeId::TIME: {
588+ case LogicalTypeId::TIME:
589+ case LogicalTypeId::TIME_NS: {
589590 D_ASSERT (type.InternalType () == PhysicalType::INT64);
590- int32_t hour, min, sec, microsec;
591- auto time = val.GetValueUnsafe <dtime_t >();
592- duckdb::Time::Convert (time, hour, min, sec, microsec);
591+ int32_t hour, min, sec, usec;
592+ dtime_t time;
593+ if (type.id () == LogicalTypeId::TIME) {
594+ time = val.GetValueUnsafe <dtime_t >();
595+ } else {
596+ // Python's datetime doesn't support nanoseconds, we convert to micros.
597+ time = val.GetValueUnsafe <dtime_ns_t >().time ();
598+ }
599+ duckdb::Time::Convert (time, hour, min, sec, usec);
593600 try {
594- auto pytime = PyTime_FromTime (hour, min, sec, microsec );
601+ auto pytime = PyTime_FromTime (hour, min, sec, usec );
595602 if (!pytime) {
596603 throw py::error_already_set ();
597604 }
0 commit comments