COMPAT: force int when doing unit conversions in pd.to_datetime · Issue #11760 · pandas-dev/pandas (original) (raw)
Navigation Menu
- GitHub Copilot Write better code with AI
- GitHub Models New Manage and compare prompts
- GitHub Advanced Security Find and fix vulnerabilities
- Actions Automate any workflow
- Codespaces Instant dev environments
- Issues Plan and track work
- Code Review Manage code changes
- Discussions Collaborate outside of code
- Code Search Find more, search less
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Description
We should force int conversions when unit
is passed (as by definition these are int-like things).
In [21]: s = pd.Series(["1440643875", "1440644191", "1440645638", "1440998720"], dtype=object)
In [22]: pd.to_datetime(s,unit='s')
ValueError: year is out of range
In [23]: pd.to_datetime(s.astype(int),unit='s')
Out[23]:
0 2015-08-27 02:51:15
1 2015-08-27 02:56:31
2 2015-08-27 03:20:38
3 2015-08-31 05:25:20
dtype: datetime64[ns]