Skip to content

Commit 03ef1a3

Browse files
committed
Handle construction from scalar
1 parent ed257bb commit 03ef1a3

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

pandas/_libs/lib.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2644,6 +2644,7 @@ def maybe_convert_objects(ndarray[object] objects,
26442644

26452645
elif seen.time_:
26462646
if is_time_array(objects):
2647+
# FIXME: need to ensure this is not timetz
26472648
opt = get_option("future.infer_time")
26482649
if opt is True:
26492650
import pyarrow as pa

pandas/core/dtypes/cast.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,29 @@ def infer_dtype_from_scalar(val) -> tuple[DtypeObj, Any]:
832832
pa_dtype = pa.time64("us")
833833
dtype = ArrowDtype(pa_dtype)
834834

835+
elif isinstance(val, dt.time):
836+
if val.tzinfo is None:
837+
# pyarrow doesn't have a dtype for timetz.
838+
opt = get_option("future.infer_time")
839+
if opt is None:
840+
warnings.warn(
841+
"Pandas type inference with a `datetime.time` "
842+
"object is deprecated. In a future version, this will give "
843+
"time32[pyarrow] dtype, which will require pyarrow to be "
844+
"installed. To opt in to the new behavior immediately set "
845+
"`pd.set_option('future.infer_time', True)`. To keep the "
846+
"old behavior pass `dtype=object`.",
847+
FutureWarning,
848+
stacklevel=find_stack_level(),
849+
)
850+
elif opt is True:
851+
import pyarrow as pa
852+
853+
pa_dtype = pa.time64("us")
854+
from pandas.core.arrays.arrow import ArrowDtype
855+
856+
dtype = ArrowDtype(pa_dtype)
857+
835858
elif is_bool(val):
836859
dtype = np.dtype(np.bool_)
837860

0 commit comments

Comments
 (0)