Skip to content

Commit

Permalink
python: remove deprecated to_python_datetime (#4341)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Aug 9, 2022
1 parent 63b06e2 commit 0177350
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 38 deletions.
1 change: 0 additions & 1 deletion py-polars/docs/source/reference/expression.rst
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ The following methods are available under the `expr.dt` attribute.
ExprDateTimeNameSpace.seconds
ExprDateTimeNameSpace.strftime
ExprDateTimeNameSpace.timestamp
ExprDateTimeNameSpace.to_python_datetime
ExprDateTimeNameSpace.truncate
ExprDateTimeNameSpace.week
ExprDateTimeNameSpace.weekday
Expand Down
1 change: 0 additions & 1 deletion py-polars/docs/source/reference/series.rst
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ The following methods are available under the `Series.dt` attribute.
DateTimeNameSpace.seconds
DateTimeNameSpace.strftime
DateTimeNameSpace.timestamp
DateTimeNameSpace.to_python_datetime
DateTimeNameSpace.truncate
DateTimeNameSpace.week
DateTimeNameSpace.weekday
Expand Down
7 changes: 0 additions & 7 deletions py-polars/polars/internals/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
Datetime,
Float64,
Int32,
Object,
Time,
UInt32,
py_type_to_dtype,
Expand Down Expand Up @@ -6866,12 +6865,6 @@ def nanosecond(self) -> Expr:
"""
return wrap_expr(self._pyexpr.nanosecond())

def to_python_datetime(self) -> Expr:
"""Go from Date/Datetime to python DateTime objects."""
return wrap_expr(self._pyexpr).map(
lambda s: s.dt.to_python_datetime(), return_dtype=Object
)

def epoch(self, tu: str = "us") -> Expr:
"""
Get the time passed since the Unix EPOCH in the give time unit
Expand Down
12 changes: 0 additions & 12 deletions py-polars/polars/internals/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -5660,18 +5660,6 @@ def timestamp(self, tu: str = "us") -> Series:
"""
return wrap_s(self._s.timestamp(tu))

def to_python_datetime(self) -> Series:
"""
Go from Date/Datetime to python DateTime objects
.. deprecated:: 0.13.23
Use :func:`Series.to_list` instead.
"""
return (self.timestamp("ms") / 1000).apply(
lambda ts: datetime.utcfromtimestamp(ts), Object
)

def min(self) -> date | datetime | timedelta:
"""Return minimum as python DateTime."""
# we can ignore types because we are certain we get a logical type
Expand Down
17 changes: 0 additions & 17 deletions py-polars/tests/test_datelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,6 @@ def test_diff_datetime() -> None:
assert out[0] == out[1]


def test_timestamp() -> None:
a = pl.Series("a", [a * 1000_000 for a in [10000, 20000, 30000]], dtype=pl.Datetime)
assert a.dt.timestamp("ms") == [10000, 20000, 30000]
out = a.dt.to_python_datetime()
assert isinstance(out[0], datetime)
assert a.dt.min() == out[0]
assert a.dt.max() == out[2]

df = pl.DataFrame([out])
# test if rows returns objects
assert isinstance(df.row(0)[0], datetime)


def test_from_pydatetime() -> None:
datetimes = [
datetime(2021, 1, 1),
Expand All @@ -127,10 +114,6 @@ def test_from_pydatetime() -> None:

def test_to_python_datetime() -> None:
df = pl.DataFrame({"a": [1, 2, 3]})
assert (
df.select(pl.col("a").cast(pl.Datetime).dt.to_python_datetime())["a"].dtype
== pl.Object
)
assert (
df.select(pl.col("a").cast(pl.Datetime).dt.timestamp())["a"].dtype == pl.Int64
)
Expand Down

0 comments on commit 0177350

Please sign in to comment.