Replies: 1 comment
-
|
I have asked Grok about this issue: Response: import pandas as pd
import numpy as np
drange = pd.date_range(start=pd.to_datetime("2024/01/01"), end=pd.to_datetime("2025/09/01"), freq="M")
print(drange)fails in Pythonista 3.4 with a TypeError: unsupported operand type(s) for +: 'Timestamp' and 'pandas._libs.tslibs.offsets.MonthEnd', but works in a local conda environment with the same pandas/numpy versions. The error occurs because Pythonista’s pandas implementation struggles with month-end or year-end frequency offsets (freq="M" or "Y") due to a potential bug or incompatibility in the rollforward method. Workaround import pandas as pd
import numpy as np
# Generate a period range with monthly frequency
periods = pd.period_range(start="2024/01/01", end="2025/09/01", freq="M")
# Convert periods to timestamps (month-end)
drange = periods.to_timestamp(how="end")
print(drange)Explanation
Notes
Here is the result I get when I run the "Workaround" in Pythonista 3.4: It looks like the full month of the end date is included. This could be filtered out: drange = drange[drange < "2025-09-01"] |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I have a very simple piece of code attempting to generate a date range with pandas in Pythonista 3.4. I created a conda envioronment in my machine with the same versions of pandas and numpy and the code runs fine.
This runs if I try daily ("D") or hourly ("H") frequencies, but "M", "Y" fail. Any ideas?
Beta Was this translation helpful? Give feedback.
All reactions