pandas/convert-then-drop-zone
| Pack | Severity | Fix | Versions |
|---|---|---|---|
| pandas | warning | safe, with xpd check --fix |
All versions |
tz_convert("UTC").tz_localize(None) takes two steps to get UTC times without a time zone. tz_convert(None) does the same in one call.
plain = df["time"].dt.tz_convert("UTC").dt.tz_localize(None)plain = df["time"].dt.tz_convert(None)What the rule reports
Section titled “What the rule reports”The rule reports df["d"].dt.tz_convert("UTC").dt.tz_localize(None), and the same on an index or a frame, where tz_convert(None) gives the same UTC times in one step.
How to fix it
Section titled “How to fix it”xpd check --fix applies the fix of this rule.
The safe fix writes df["d"].dt.tz_convert(None).
Diagnostic message
Section titled “Diagnostic message”tz_convert(None) converts to UTC and drops the time zone in one call. Write $X.dt.tz_convert(None).See all rules in the pandas pack.