I have witnessed some strange behaviour accessing attributes such as _m or _s from a pandas timedelta object .
Let me explain the problem with a minimal example, that I run from the console in PyCharm (PyCharm 2020.2.3 (Community Edition))
>>> import pandas as pd
>>> # Creating a dataFrame with 2 pandas timedeltas:
... df_test=pd.DataFrame({"Timedeltas":[pd.Timedelta('1 days 1:01:01'), pd.Timedelta('2 days 2:02:02')]})
Timedelta('0 days 00:02:56.230217907')
>>> mean_timedelta=df_test['Timedeltas'].mean()
... print(mean_timedelta._m)
0
>>> mean_timedelta=df_test['Timedeltas'].mean()
... print(mean_timedelta)
... print(mean_timedelta._m)
1 days 13:31:31.500000
31
Why isn't 31 printed the first time I executed
print(mean_timedelta._m)? And why do I get0instead?Why is 31 printed only if I run
print(mean_timedelta)before?