Skip to content

DatetimeIndex constructor is inconsistent #1769

Closed
@mcobzarenco

Description

@mcobzarenco

It would be really neat if the DatetimeIndex constructor took an argument "dayfirst" which would force it to interpret a date as DD-MM-YYYY or similar when presented with a sequence of strings.

What it should never do is assume different formats for different strings in the same sequence (the current behaviour):

  • If the string can be interpreted as a "month first" date, i.e. <= 12 it's parsed this way
  • Otherwise it's parse as a day first string

I.e. all strings in the sequence for which the day happens to be <= 12 are parsed as "month first" and the rest as "day first".

pandas.DatetimeIndex(['12/05/2007', '25/01/2008'])

<class 'pandas.tseries.index.DatetimeIndex'>
[2007-12-05 00:00:00, 2008-01-25 00:00:00]
Length: 2, Freq: None, Timezone: None

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