jzhan-2026 opened a new pull request, #60577:
URL: https://github.com/apache/spark/pull/60577

   ### What changes were proposed in this pull request?
   
   This PR adds `axis=1` support to `DataFrame.at_time` and 
`DataFrame.between_time` in pandas API on Spark.
   
   With `axis=1`, the methods select columns whose labels match the time, the 
same as pandas. The column labels are kept on the driver, so the positions come 
from pandas `DatetimeIndex.indexer_at_time` / `indexer_between_time`. The 
columns are then selected with `iloc`. No Spark job runs to find the columns.
   
   If the column labels are not a `DatetimeIndex`, a `TypeError("Index must be 
DatetimeIndex")` is raised, as in pandas.
   
   `Series.at_time` and `Series.between_time` now raise `ValueError("No axis 
named 1 for object type Series")` for `axis=1`, as in pandas. Before, they 
raised the `NotImplementedError` from the `DataFrame` method.
   
   This PR also removes the `TODO(SPARK-46159)` comment and adds `axis=1` 
doctest examples.
   
   ### Why are the changes needed?
   
   `axis=1` is part of the pandas API, but pandas API on Spark raised 
`NotImplementedError` for it.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes.
   
   Before:
   
   ```python
   >>> idx = pd.date_range("2018-04-09", periods=4, freq="12h")
   >>> psdf = ps.DataFrame([[1, 2, 3, 4]], columns=idx)
   >>> psdf.at_time("12:00", axis=1)
   NotImplementedError: at_time currently only works for axis=0
   ```
   
   After:
   
   ```python
   >>> psdf.at_time("12:00", axis=1)
      2018-04-09 12:00:00  2018-04-10 12:00:00
   0                    2                    4
   ```
   
   `DataFrame.between_time(..., axis=1)` changes in the same way. 
`Series.at_time` / `Series.between_time` with `axis=1` now raise `ValueError` 
instead of `NotImplementedError`. The method signatures and the `axis=0` 
behavior do not change.
   
   ### How was this patch tested?
   
   New tests in `pyspark.pandas.tests.frame.test_reindexing` cover:
   - `axis=1` and `axis="columns"`
   - all `inclusive` values, and `start_time` later than `end_time`
   - a selection with no matching column
   - the `TypeError` for non-datetime column labels
   - the `ValueError` for `Series`
   
   Ran locally:
   
   ```
   python/run-tests --testnames 
"pyspark.pandas.tests.frame.test_reindexing,pyspark.pandas.tests.connect.frame.test_parity_reindexing"
   ```
   
   The new doctests also pass.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code
   
   🤖 Generated with [Claude Code](https://claude.com/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]

Reply via email to