Skip to content

Commit ce1bc00

Browse files
committed
Handle construction from scalar
1 parent 423496a commit ce1bc00

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
@@ -2660,6 +2660,7 @@ def maybe_convert_objects(ndarray[object] objects,
26602660

26612661
elif seen.time_:
26622662
if is_time_array(objects):
2663+
# FIXME: need to ensure this is not timetz
26632664
opt = get_option("future.infer_time")
26642665
if opt is True:
26652666
import pyarrow as pa

pandas/core/dtypes/cast.py

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

846+
elif isinstance(val, dt.time):
847+
if val.tzinfo is None:
848+
# pyarrow doesn't have a dtype for timetz.
849+
opt = get_option("future.infer_time")
850+
if opt is None:
851+
warnings.warn(
852+
"Pandas type inference with a `datetime.time` "
853+
"object is deprecated. In a future version, this will give "
854+
"time32[pyarrow] dtype, which will require pyarrow to be "
855+
"installed. To opt in to the new behavior immediately set "
856+
"`pd.set_option('future.infer_time', True)`. To keep the "
857+
"old behavior pass `dtype=object`.",
858+
FutureWarning,
859+
stacklevel=find_stack_level(),
860+
)
861+
elif opt is True:
862+
import pyarrow as pa
863+
864+
pa_dtype = pa.time64("us")
865+
from pandas.core.arrays.arrow import ArrowDtype
866+
867+
dtype = ArrowDtype(pa_dtype)
868+
846869
elif is_bool(val):
847870
dtype = np.dtype(np.bool_)
848871

0 commit comments

Comments
 (0)