Skip to content

API: pd.Series([py_date, py_datetime]) vs pd.Index([py_date, py_datetime]) #49341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jbrockmendel opened this issue Oct 26, 2022 · 3 comments · Fixed by #49446
Closed

API: pd.Series([py_date, py_datetime]) vs pd.Index([py_date, py_datetime]) #49341

jbrockmendel opened this issue Oct 26, 2022 · 3 comments · Fixed by #49446
Labels
API - Consistency Internal Consistency of API/Behavior Bug Constructors Series/DataFrame/Index/pd.array Constructors Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@jbrockmendel
Copy link
Member

jbrockmendel commented Oct 26, 2022

ts = pd.Timestamp.now()

vals= [ts.date(), ts.to_pydatetime()]

ser = pd.Series(vals)  # <- dt64 dtype
idx = pd.Index(vals)  # <- object dtype

Index uses lib.maybe_convert_objects for inference while Series uses infer_datetimelike_array in maybe_infer_to_datetimelike.

Ideally these would match.

@jbrockmendel jbrockmendel added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 26, 2022
@jbrockmendel jbrockmendel changed the title BUG: pd.Series([py_date, py_datetime]) vs pd.Index([py_date, py_datetime]) API: pd.Series([py_date, py_datetime]) vs pd.Index([py_date, py_datetime]) Oct 26, 2022
@jbrockmendel jbrockmendel added Constructors Series/DataFrame/Index/pd.array Constructors API - Consistency Internal Consistency of API/Behavior labels Oct 26, 2022
@jorisvandenbossche
Copy link
Member

Personally, if I would have to choose, I prefer the Index behaviour. I don't think we should automatically convert datetime.date objects to datetime dtype.

For the case of only datetime.date objects, we also don't infer it as datetime dtype.

@jbrockmendel
Copy link
Member Author

if I would have to choose, I prefer the Index behaviour

agreed

@jreback
Copy link
Contributor

jreback commented Oct 31, 2022

ok i'll agree with you folks here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API - Consistency Internal Consistency of API/Behavior Bug Constructors Series/DataFrame/Index/pd.array Constructors Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants