Skip to content

Commit e9cc084

Browse files
BUG: fixed datetime64[ns] conversion issue in numpy.vectorize, see numpy#25936
1 parent c369433 commit e9cc084

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

numpy/lib/_function_base_impl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2330,7 +2330,7 @@ def __init__(self, pyfunc=np._NoValue, otypes=None, doc=None,
23302330
if char not in typecodes['All']:
23312331
raise ValueError("Invalid otype specified: %s" % (char,))
23322332
elif iterable(otypes):
2333-
otypes = ''.join([_nx.dtype(x).char for x in otypes])
2333+
otypes = [_nx.dtype(x) for x in otypes]
23342334
elif otypes is not None:
23352335
raise ValueError("Invalid otype specification")
23362336
self.otypes = otypes

numpy/lib/tests/test_function_base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,6 +1901,13 @@ def test_positional_regression_9477(self):
19011901
r = f([2])
19021902
assert_equal(r.dtype, np.dtype('float64'))
19031903

1904+
def test_datetime_conversion(self):
1905+
otype = "datetime64[ns]"
1906+
arr = np.array(['2024-01-01', '2024-01-02', '2024-01-03'],
1907+
dtype='datetime64[ns]')
1908+
assert_array_equal(np.vectorize(lambda x: x, signature="(i)->(j)",
1909+
otypes=[otype])(arr), arr)
1910+
19041911

19051912
class TestLeaks:
19061913
class A:

0 commit comments

Comments
 (0)