pandas/convert-then-drop-zone
| Rule | convert-then-drop-zone |
|---|---|
| Pack | pandas |
| Severity | warning |
| Fix | safe, with xpd check --fix |
| Library versions | every version |
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).
Message
Section titled “Message”xpd prints this message with the issue. A name that starts with $ stands for code from your file.
tz_convert(None) converts to UTC and drops the time zone in one call. Write $X.dt.tz_convert(None).Browse the other rules of the pandas pack.