Skip to content

Commit f7d5665

Browse files
committed
Handle construction from scalar
1 parent 4ba117d commit f7d5665

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
@@ -833,6 +833,29 @@ def infer_dtype_from_scalar(val) -> tuple[DtypeObj, Any]:
833833

834834
dtype = ArrowDtype(pa_dtype)
835835

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

0 commit comments

Comments
 (0)