Re:It's Time for a Change: Datetime.utcnow() Is Now Deprecated
by nooorofe on Sunday November 19, 2023 @11:30AM
(#38334176)
>pendulum is probably your best bet
It is best until you work with Pandas DataFrame (https://stackoverflow.com/questions/47849342/making-pandas-w...)
Re:It's Time for a Change: Datetime.utcnow() Is Now Deprecated
by BiteCode_dev on Sunday November 19, 2023 @12:16PM
(#38334840)
Numpy and pandas are their own little island. It's not just dates and time, it's everything.
If you use numpy and pandas, you should also not use Python datetime, generators, most stdlib mathematical functions, the itertools module, random, etc.
It's the first thing you learn if you read any good pandas book, and the first thing I teach in my numpy/pandas trainings.
It has pretty much nothing to do with pendulum.
Basically, half the Python ecosystem is "well, except with numpy/pandas of course".
Re:It's Time for a Change: Datetime.utcnow() Is Now Deprecated
by nooorofe on Sunday November 19, 2023 @06:16PM
(#38339645)
from zoneinfo import ZoneInfo
import pendulum
import datetime
def pendulum_to_datetime(pendulum_dt: pendulum.DateTime) -> datetime.datetime:
return datetime.datetime.fromtimestamp(pendulum_dt.timestamp(),
ZoneInfo(pendulum_dt.timezone_name))
# test
df = pd.DataFrame([[1, 2], [1, 2]], columns=['a', 'b'])
df["time_column"] = pendulum_to_datetime(pendulum.now())
print(df)
output a b time_column
0 1 2 2023-11-19 18:14:16.027777-05:00
1 1 2 2023-11-19 18:14:16.027777-05:00
>> df.dtypes
a int64
b int64
time_column datetime64[ns, America/New_York]
dtype: object
I'd like to add that if you have any fancy datetime manipulation to do in Python, pendulum (https://pendulum.eustace.io/) is probably your best bet.