Skip to content

Commit

Permalink
change numpy type to datetime64[ns], update test to not be necessaril…
Browse files Browse the repository at this point in the history
…y true
  • Loading branch information
mhconradt authored and ritchie46 committed Dec 27, 2021
1 parent 2182a0e commit d766068
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion py-polars/polars/internals/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1972,7 +1972,7 @@ def convert_to_date(arr): # type: ignore
if self.dtype == Date:
tp = "datetime64[D]"
else:
tp = "datetime64[ms]"
tp = "datetime64[ns]"
return arr.astype(tp)

if _PYARROW_AVAILABLE and not self.is_datelike():
Expand Down
7 changes: 4 additions & 3 deletions py-polars/tests/test_datelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def test_filter_date() -> None:


def test_diff_datetime() -> None:

df = pl.DataFrame(
{
"timestamp": ["2021-02-01", "2021-03-1", "2021-04-1"],
Expand Down Expand Up @@ -172,11 +171,13 @@ def test_rows() -> None:

def test_to_numpy() -> None:
s0 = pl.Series("date", [123543, 283478, 1243]).cast(pl.Date)
s1 = pl.Series("datetime", [123543, 283478, 1243]).cast(pl.Datetime)
s1 = pl.Series(
"datetime", [datetime(2021, 1, 2, 3, 4, 5), datetime(2021, 2, 3, 4, 5, 6)]
)
assert str(s0.to_numpy()) == "['2308-04-02' '2746-02-20' '1973-05-28']"
assert (
str(s1.to_numpy()[:2])
== "['1970-01-01T00:02:03.543' '1970-01-01T00:04:43.478']"
== "['2021-01-02T03:04:05.000000000' '2021-02-03T04:05:06.000000000']"
)


Expand Down

0 comments on commit d766068

Please sign in to comment.