Skip to content

Commit

Permalink
Refactor type casting logic to use datatypes.py
Browse files Browse the repository at this point in the history
  • Loading branch information
zundertj authored and ritchie46 committed Nov 26, 2021
1 parent 2eb476f commit 81a0d21
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions py-polars/polars/internals/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@

from polars import internals as pli
from polars.datatypes import (
Boolean,
DataType,
Date,
Datetime,
Float64,
Int64,
Object,
UInt32,
Utf8,
py_type_to_dtype,
)


Expand Down Expand Up @@ -672,14 +670,7 @@ def cast(self, dtype: Type[Any], strict: bool = True) -> "Expr":
strict
Throw an error if a cast could not be done for instance due to an overflow
"""
if dtype == str:
dtype = Utf8
elif dtype == bool:
dtype = Boolean
elif dtype == float:
dtype = Float64
elif dtype == int:
dtype = Int64
dtype = py_type_to_dtype(dtype)
return wrap_expr(self._pyexpr.cast(dtype, strict))

def sort(self, reverse: bool = False) -> "Expr":
Expand Down Expand Up @@ -1052,14 +1043,8 @@ def map(
agg_list
"""
if return_dtype == str:
return_dtype = Utf8
elif return_dtype == int:
return_dtype = Int64
elif return_dtype == float:
return_dtype = Float64
elif return_dtype == bool:
return_dtype = Boolean
if return_dtype is not None:
return_dtype = py_type_to_dtype(return_dtype)
return wrap_expr(self._pyexpr.map(f, return_dtype, agg_list))

def apply(
Expand Down

0 comments on commit 81a0d21

Please sign in to comment.