marcuslin123 opened a new pull request, #56635:
URL: https://github.com/apache/spark/pull/56635
### What changes were proposed in this pull request?
Add support for `TimeType` columns in pandas API on Spark (`pyspark.pandas`):
- Map `datetime.time` to `TimeType` in the dtype translation layer
(`typehints.py`)
- Map `TimeType` to `np.dtype("object")` for pandas representation
- Create `TimeOps` class for column operations (comparisons supported,
arithmetic rejected)
- Register `TimeOps` in the dispatch system (`base.py`)
### Why are the changes needed?
`pyspark.pandas` does not handle `TimeType` — the Spark-to-pandas dtype
machinery treats `datetime.time` as a generic object with no explicit mapping.
Without these changes, creating a pandas-on-Spark DataFrame with
`datetime.time` values fails, and column operations on TIME columns crash with
`TypeError`.
The underlying Arrow conversion already supports TIME (SPARK-53263 /
SPARK-53305), so this wires up the remaining pyspark.pandas layer.
### Does this PR introduce _any_ user-facing change?
Yes. Users can now work with `TimeType` columns in `pyspark.pandas`:
```python
import pyspark.pandas as ps
import datetime
df = ps.DataFrame({"shift_start": [datetime.time(8, 0), datetime.time(14,
0)]})
df["shift_start"].dtype # returns object
afternoon = df[df["shift_start"] > datetime.time(12, 0)] # comparisons work
```
Previously this would fail with a TypeError or produce incorrect results.
### How was this patch tested?
- Added `datetime.time` mapping to `test_typedef.py`
- Added new `test_time_ops.py` covering arithmetic rejection and comparison
operations
- All tests pass locally: `python/run-tests --testnames
pyspark.pandas.tests.test_typedef` and `python/run-tests --testnames
pyspark.pandas.tests.data_type_ops.test_time_ops`
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]