Skip to content

BUG: .loc Indexing with pyarrow backed DatetimeIndex does not allow string comparison #58307

Closed
@WillAyd

Description

@WillAyd

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

In [18]: df = pd.DataFrame({
    ...:     "data": range(3),
    ...:     "pa_dates": pd.Series(["2024-01-01", "2024-01-02", "2024-01-03"], dtype=pd.ArrowDtype(pa.timestamp("s"))),
    ...:     "pd_dates": pd.Series(["2024-01-01", "2024-01-02", "2024-01-03"], dtype="datetime64[s]"),
    ...: })
    ...: 

In [19]: df.set_index("pd_dates").loc[:"2024-01-01"]
    ...: 
Out[19]: 
            data             pa_dates
pd_dates                             
2024-01-01     0  2024-01-01 00:00:00

In [20]: df.set_index("pa_dates").loc[:"2024-01-01"]
TypeError: '<' not supported between instances of 'datetime.datetime' and 'str'


### Issue Description

TypeError: '<' not supported between instances of 'datetime.datetime' and 'str'

### Expected Behavior

I would expect the pyarrow backed datetimeindex to be supported just like the pandas one

### Installed Versions

In [21]: pd.__version__
Out[21]: '3.0.0.dev0+681.g434fda08cf'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Arrowpyarrow functionalityBugDatetimeDatetime data dtype

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions