Skip to content

Commit c86f042

Browse files
authored
ENH,MAINT: rewrite np.fix to use np.trunc internally (numpy#30197)
* DEP: rewrite np.fix to use np.trunc internally * TST: add trunc to object for ufunclike tests
1 parent 3abf579 commit c86f042

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

numpy/lib/_ufunclike_impl.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,7 @@ def fix(x, out=None):
5656
array([ 2., 2., -2., -2.])
5757
5858
"""
59-
# promote back to an array if flattened
60-
res = nx.ceil(x, out=... if out is None else out)
61-
res = nx.floor(x, out=res, where=nx.greater_equal(x, 0))
62-
63-
# when no out argument is passed and no subclasses are involved, flatten
64-
# scalars
65-
if out is None and type(res) is nx.ndarray:
66-
res = res[()]
67-
return res
59+
return nx.trunc(x, out=out)
6860

6961

7062
@array_function_dispatch(_dispatcher, verify=False, module='numpy')

numpy/typing/tests/data/pass/ufunclike.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ def __ceil__(self) -> Object:
1212
def __floor__(self) -> Object:
1313
return self
1414

15+
def __trunc__(self) -> Object:
16+
return self
17+
1518
def __ge__(self, value: object) -> bool:
1619
return True
1720

0 commit comments

Comments
 (0)