Skip to content

Converting None values with pandas.to_datetime is unpredictable #23055

Open
@dinya

Description

@dinya

Why does pandas convert None values in the different ways for to_datetime (unpredictable) and to_numeric (predictable)?

import pandas as pd
  
VALUE = None
    
print(pd.to_datetime(VALUE))
print(pd.to_numeric(VALUE))

print(pd.__version__)

returns

None
nan
0.23.4

due to https://github.com/pandas-dev/pandas/blob/v0.23.4/pandas/core/tools/datetimes.py#L382

Why not pd.to_datetime(None) is pd.NaT by design?

See also original post at stackoverflow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    API - ConsistencyInternal Consistency of API/BehaviorBugDatetimeDatetime data dtypeMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions