Skip to content

Commit

Permalink
fix[python]: Series init issue with unit/precision (from python datet…
Browse files Browse the repository at this point in the history
…ime) (#4921)
  • Loading branch information
alexander-beedie committed Sep 21, 2022
1 parent 6cdc83e commit d4f38bc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
9 changes: 8 additions & 1 deletion py-polars/polars/internals/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,14 @@ def sequence_to_pyseries(

else:
if python_dtype is None:
python_dtype = float if (value is None) else type(value)
if value is None:
# generic default dtype
python_dtype = float
else:
python_dtype = type(value)
if datetime == python_dtype:
# note: python-native datetimes have microsecond precision
temporal_unit = "us"

# temporal branch
if python_dtype in py_temporal_types:
Expand Down
16 changes: 16 additions & 0 deletions py-polars/tests/unit/test_datelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,22 @@ def test_datetime_consistency() -> None:
)
]

test_data = [
datetime(2000, 1, 1, 1, 1, 1, 555555),
datetime(2514, 5, 30, 1, 53, 4, 986754),
datetime(3099, 12, 31, 23, 59, 59, 123456),
datetime(9999, 12, 31, 23, 59, 59, 999999),
]
ddf = pl.DataFrame({"dtm": test_data}).with_column(
pl.col("dtm").dt.nanosecond().alias("ns")
)
assert ddf.rows() == [
(test_data[0], 555555000),
(test_data[1], 986754000),
(test_data[2], 123456000),
(test_data[3], 999999000),
]


def test_timezone() -> None:
ts = pa.timestamp("s")
Expand Down

0 comments on commit d4f38bc

Please sign in to comment.