Skip to content

REF: remove copy keyword from ensure_foo #51213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pandas/_libs/algos.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ def diff_2d(
) -> None: ...
def ensure_platform_int(arr: object) -> npt.NDArray[np.intp]: ...
def ensure_object(arr: object) -> npt.NDArray[np.object_]: ...
def ensure_float64(arr: object, copy=...) -> npt.NDArray[np.float64]: ...
def ensure_int8(arr: object, copy=...) -> npt.NDArray[np.int8]: ...
def ensure_int16(arr: object, copy=...) -> npt.NDArray[np.int16]: ...
def ensure_int32(arr: object, copy=...) -> npt.NDArray[np.int32]: ...
def ensure_int64(arr: object, copy=...) -> npt.NDArray[np.int64]: ...
def ensure_uint64(arr: object, copy=...) -> npt.NDArray[np.uint64]: ...
def ensure_float64(arr: object) -> npt.NDArray[np.float64]: ...
def ensure_int8(arr: object) -> npt.NDArray[np.int8]: ...
def ensure_int16(arr: object) -> npt.NDArray[np.int16]: ...
def ensure_int32(arr: object) -> npt.NDArray[np.int32]: ...
def ensure_int64(arr: object) -> npt.NDArray[np.int64]: ...
def ensure_uint64(arr: object) -> npt.NDArray[np.uint64]: ...
def take_1d_int8_int8(
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
) -> None: ...
Expand Down
6 changes: 3 additions & 3 deletions pandas/_libs/algos_common_helper.pxi.in
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ def get_dispatch(dtypes):
{{for name, c_type, dtype in get_dispatch(dtypes)}}


def ensure_{{name}}(object arr, copy=True):
def ensure_{{name}}(object arr):
if util.is_array(arr):
if (<ndarray>arr).descr.type_num == NPY_{{c_type}}:
return arr
else:
# equiv: arr.astype(np.{{dtype}}, copy=copy)
# equiv: arr.astype(np.{{dtype}})
return cnp.PyArray_Cast(<ndarray>arr, cnp.NPY_{{c_type}})
else:
return np.array(arr, dtype=np.{{dtype}})
return np.asarray(arr, dtype=np.{{dtype}})

{{endfor}}
12 changes: 8 additions & 4 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2149,10 +2149,14 @@ def injection(obj):
# upcast 'by' parameter because HashTable is limited
by_type = _get_cython_type_upcast(lbv.dtype)
by_type_caster = _type_casters[by_type]
# error: Cannot call function of unknown type
left_by_values = by_type_caster(lbv) # type: ignore[operator]
# error: Cannot call function of unknown type
right_by_values = by_type_caster(rbv) # type: ignore[operator]
# error: Incompatible types in assignment (expression has type
# "ndarray[Any, dtype[generic]]", variable has type
# "List[Union[Union[ExtensionArray, ndarray[Any, Any]], Index, Series]]")
left_by_values = by_type_caster(lbv) # type: ignore[assignment]
# error: Incompatible types in assignment (expression has type
# "ndarray[Any, dtype[generic]]", variable has type
# "List[Union[Union[ExtensionArray, ndarray[Any, Any]], Index, Series]]")
right_by_values = by_type_caster(rbv) # type: ignore[assignment]

# choose appropriate function by type
func = _asof_by_function(self.direction)
Expand Down