Skip to content

BUG: Exception to the boolean frame comparison guarantee  #16155

Closed
@ResidentMario

Description

@ResidentMario

The implementation for core._com_method_FRAME makes the following note:

            # straight boolean comparisions we want to allow all columns
            # (regardless of dtype to pass thru) See #4537 for discussion.

However, I think I stumbled on an exception here.

The root cause is that astype(bool) has a "hole" in it in the case of datetime dtypes. The following:

import pandas as pd
from io import StringIO

# create our surprisingly slippery frame
res = pd.read_csv(StringIO(""",dates1,dates2
0,1970-01-01 00:00:00.000000000,1970-01-01 00:00:00.000000000
1,1970-01-01 00:00:00.000000000,"""), index_col=0)
res['dates1'] = pd.to_datetime(res['dates1'])

res.astype(bool)

Raises:

TypeError: cannot astype a datetimelike from [datetime64[ns]] to [bool]

If you get this frame as a fillna output (not possible on master, but possible in the feature branch I am working on), it will raise this same error when passed through _com_method_FRAME, due to:

return res.fillna(True).astype(bool)

This is a problem in PR#15653.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions