Skip to content

BUG: Raise on coercion of ambiguous datetime strings to datetime64 #61489

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
wants to merge 1 commit into from

Conversation

iabhi4
Copy link
Contributor

@iabhi4 iabhi4 commented May 24, 2025

This PR addresses a bug where object-dtype arrays containing ambiguous datetime strings (e.g., "12/01/2020", "13/01/2020") were being silently coerced to datetime64[ns], potentially resulting in inconsistent or unintended parsing.

  • Introduced stricter input validation during coercion to detect and raise a ValueError when an ambiguous format is inferred but cannot be consistently parsed.

  • Added tests to cover both direct assignment and constructor-based coercion scenarios.

  • closes 61353

  • Tests added and passed

  • All code checks passed

  • Added an entry in the latest doc/source/whatsnew/v3.0.0.rst file

@iabhi4
Copy link
Contributor Author

iabhi4 commented May 24, 2025

The pre-commit is currently failing due to the unwanted-patterns-private-import-across-module hook

This PR imports _guess_datetime_format_for_array from pandas.core.tools.datetimes, which is a private function.
There’s currently no public alternative that offers this functionality. specifically, inferring a consistent datetime format from an array of strings without coercion.

Happy to refactor this if needed, for example, by moving it to a shared utility module or discussing exposing it publicly if that makes more sense long-term

@iabhi4
Copy link
Contributor Author

iabhi4 commented May 25, 2025

Closing this PR as the current approach doesn’t feel quite right from a design and maintainability perspective. I believe there might be a cleaner solution that avoids adding complexity across multiple layers

@iabhi4 iabhi4 closed this May 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant