@@ -225,7 +225,9 @@ Value PyTime::ToDuckValue() {
225225 auto seconds = PyTimezone::GetUTCOffsetSeconds (this ->timezone_obj );
226226 return Value::TIMETZ (dtime_tz_t (duckdb_time, seconds));
227227 }
228- return Value::TIME (duckdb_time);
228+ // For non-timezoned time's we default to TIME_NS
229+ const auto nanos = Time::ToNanoTime (hour, minute, second, microsecond * 1000 );
230+ return Value::TIME_NS (dtime_ns_t (nanos));
229231}
230232
231233int32_t PyTime::GetHours (py::handle &obj) {
@@ -585,13 +587,20 @@ py::object PythonObject::FromValue(const Value &val, const LogicalType &type,
585587 auto tmp_datetime_with_tz = import_cache.datetime .datetime .combine ()(tmp_datetime, py_time, timezone_offset);
586588 return tmp_datetime_with_tz.attr (" timetz" )();
587589 }
588- case LogicalTypeId::TIME: {
590+ case LogicalTypeId::TIME:
591+ case LogicalTypeId::TIME_NS: {
589592 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);
593+ int32_t hour, min, sec, usec;
594+ dtime_t time;
595+ if (type.id () == LogicalTypeId::TIME) {
596+ time = val.GetValueUnsafe <dtime_t >();
597+ } else {
598+ // Python's datetime doesn't support nanoseconds, we convert to micros.
599+ time = val.GetValueUnsafe <dtime_ns_t >().time ();
600+ }
601+ duckdb::Time::Convert (time, hour, min, sec, usec);
593602 try {
594- auto pytime = PyTime_FromTime (hour, min, sec, microsec );
603+ auto pytime = PyTime_FromTime (hour, min, sec, usec );
595604 if (!pytime) {
596605 throw py::error_already_set ();
597606 }
0 commit comments