Skip to content

Commit

Permalink
Improve pytz integration (#4386)
Browse files Browse the repository at this point in the history
Following up on #3357
- list pytz as an optional dependency. No version bound, I dont think the api has changed in a long time as far as I can see
- provide user with more clear error message if pytz import fails in case not installed
  • Loading branch information
zundertj committed Aug 13, 2022
1 parent 643189d commit 614b9dd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion py-polars/polars/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,12 @@ def _to_python_datetime(
else:
raise ValueError(f"time unit: {tu} not expected")
if tz is not None and len(tz) > 0:
import pytz
try:
import pytz
except ImportError:
raise ImportError(
"pytz is not installed. Please run `pip install pytz`."
) from None

return pytz.timezone(tz).localize(dt)
return dt
Expand Down
1 change: 1 addition & 0 deletions py-polars/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ numpy = ["numpy >= 1.16.0"]
fsspec = ["fsspec"]
connectorx = ["connectorx"]
xlsx2csv = ["xlsx2csv >= 0.8.0"]
pytz = ["pytz"]

[tool.isort]
profile = "black"
Expand Down

0 comments on commit 614b9dd

Please sign in to comment.