Replies: 4 comments
|
I get: ChatGPT said: TypeError: Cannot compare tz-naive and tz-aware datetime-like objects This means that somewhere in your data you're mixing: timezone-aware datetimes (e.g. 2026-07-21 20:02:23+02:00) |
|
Still working on this currently. Maybe it has to do with the code, which is exposed in a different way in older Pandas, and treated gracefully in newer pandas. I will come back on this one. |
|
This is the decisive clue. Your data is not the problem. Both environments have: datetime64[ns, Europe/Brussels] and both have: <class 'pandas._libs.tslibs.timestamps.Timestamp'> So the Series is already a proper timezone-aware pandas datetime column. The failure happens when Pythonista's pandas 1.4.4 tries to interpret the timezone metadata for Europe/Brussels: pandas/_libs/tslibs/timezones.pyx", line 266, in get_dst_info This is coming from the older pandas timezone handling code, not from your subtraction. Why the subtraction triggers it This line: _df["RAW_cumulative time"] = ( forces pandas to align and operate on the timezone-aware datetime array. During that operation, pandas 1.4.4 asks the timezone object for DST transition information. The timezone is: zoneinfo.ZoneInfo(key="Europe/Brussels") and pandas 1.4.4 was not fully compatible with Python's zoneinfo objects in all cases. It expected older pytz-style timezone objects, where DST metadata was available in the way pandas expected. Your laptop has pandas 2.3.3, which fixed/improved this area. Recommended fix: use pytz for pandas 1.4.4 compatibility In your Utils.now_local() function, change: return datetime.now(ZoneInfo(timezone)) to: import pytz return datetime.now(pytz.timezone(timezone)) Then your timestamps will carry: tzinfo=<DstTzInfo 'Europe/Brussels' ...> instead of: tzinfo=zoneinfo.ZoneInfo(key='Europe/Brussels') Pandas 1.4.4 handles the former much better. Alternative: convert before creating the DataFrame If you want to keep ZoneInfo everywhere else, normalize only at the pandas boundary: import pytz _df[column_name] = _df[column_name].apply( However, I would prefer fixing the timestamp creation point because then all downstream calculations stay consistent. Longer-term option If Pythonista allows it, upgrading pandas from 1.4.4 would likely solve this without code changes. But given Pythonista's packaging constraints, switching from zoneinfo to pytz is probably the cleanest compatibility fix. One small note: zoneinfo is the modern Python approach, so your original implementation was correct for current Python. The change is mainly to accommodate the older pandas stack on iOS. |
|
What I observe is the following:
Unless I am missing essential skills/knowledge, this was not much fun as one of the first uses of the Pythonista app. |
Uh oh!
There was an error while loading. Please reload this page.
Hello all,
So I installed Pythonista and I am generally very happy with the result.
When I am now trying to use my 4K lines script in Python, while it works fine on the laptop, I get issues on Pandas timezone conversions (or so it seems). I am pretty sure it has to do with older versions of Pandas whereas it is more recent on my laptop.
Is this something that others have struggled with as well? Any solution I could adopt?
The script is about a hike and different stops along the way. I calculate the difference in time between successive stops. Pythonista and Pandas for some reason do not like it. On the laptop works well.
All reactions