Skip to content

BUG: Unexpected behaviour when inserting timestamps into Series #57596

@KowalMar

Description

@KowalMar

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

import pandas as pd dt = pd.to_datetime(['2024-02-24 10:00']) s = pd.Series([1],index=dt) s.loc['2024-02-24 9:57'] = None # is inserted into s print(s) s.loc['2024-02-24 10:2:30'] = None # is inserted into s print(s) s.loc['2024-02-24 10:08'] = None # is _not_ inserted into s print(s) s.loc['2024-02-24 10:08:00'] = None # is inserted into s print(s)

Issue Description

When inserting timestamps into a pandas Series, beginning with the format 'yyyy-mm-dd hh:mm', they are inserted correctly, until first time switching to format 'yyyy-mm-dd hh:mm:ss'. From then on format 'yyyy-mm-dd hh:mm' is silently not inserted, ending with seconds required.

Not sure if this is intended, unexpected behaviour in my opinion.

Expected Behavior

Insert timestamps as long as their format is parsed unambiguously.

Installed Versions

pandas 2.1.4 py311hf62ec03_0

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexingRelated to indexing on series/frames, not to indexes themselvesNeeds TriageIssue that has not been reviewed by a pandas team membersetitem-with-expansion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions