8000 Add tests for leading NaT values, and fix np.min() bug · githubmlai/numpy@9748970 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9748970

Browse files
committed
Add tests for leading NaT values, and fix np.min() bug
1 parent 84c0555 commit 9748970

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

numpy/core/src/umath/loops.c.src

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,26 +1141,17 @@ NPY_NO_EXPORT void
11411141
NPY_NO_EXPORT void
11421142
@TYPE@_@kind@(char **args, npy_intp *dimensions, npy_intp *steps, void *NPY_UNUSED(func))
11431143
{
1144-
if (IS_BINARY_REDUCE) {
1145-
BINARY_REDUCE_LOOP(@type@) {
1146-
const @type@ in2 = *(@type@ *)ip2;
1147-
io1 = (io1 @OP@ in2 || in2 == NPY_DATETIME_NAT) ? io1 : in2;
1144+
BINARY_LOOP {
1145+
const @type@ in1 = *(@type@ *)ip1;
1146+
const @type@ in2 = *(@type@ *)ip2;
1147+
if (in1 == NPY_DATETIME_NAT) {
1148+
*((@type@ *)op1) = in2;
11481149
}
1149-
*((@type@ *)iop1) = io1;
1150-
}
1151-
else {
1152-
BINARY_LOOP {
1153-
const @type@ in1 = *(@type@ *)ip1;
1154-
const @type@ in2 = *(@type@ *)ip2;
1155-
if (in1 == NPY_DATETIME_NAT) {
1156-
*((@type@ *)op1) = in2;
1157-
}
1158-
else if (in2 == NPY_DATETIME_NAT) {
1159-
*((@type@ *)op1) = in1;
1160-
}
1161-
else {
1162-
*((@type@ *)op1) = (in1 @OP@ in2) ? in1 : in2;
1163-
}
1150+
else if (in2 == NPY_DATETIME_NAT) {
1151+
*((@type@ *)op1) = in1;
1152+
}
1153+
else {
1154+
*((@type@ *)op1) = (in1 @OP@ in2) ? in1 : in2;
11641155
}
11651156
}
11661157
}

numpy/core/tests/test_multiarray.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2681,6 +2681,13 @@ class TestArgmax(TestCase):
26812681
np.datetime64('2015-11-20T12:20:59'),
26822682
np.datetime64('1932-09-23T10:10:13'),
26832683
np.datetime64('2014-10-10T03:50:30')], 3),
2684+
# Assorted tests with NaTs
2685+
([np.datetime64('NaT'),
2686+
np.datetime64('NaT'),
2687+
np.datetime64('2010-01-03T05:14:12'),
2688+
np.datetime64('NaT'),
2689+
np.datetime64('2015-09-23T10:10:13'),
2690+
np.datetime64('1932-10-10T03:50:30')], 4),
26842691
([np.datetime64('2059-03-14T12:43:12'),
26852692
np.datetime64('1996-09-21T14:43:15'),
26862693
np.datetime64('NaT'),
@@ -2798,6 +2805,13 @@ class TestArgmin(TestCase):
27982805
np.datetime64('2014-11-20T12:20:59'),
27992806
np.datetime64('2015-09-23T10:10:13'),
28002807
np.datetime64('1932-10-10T03:50:30')], 5),
2808+
# Assorted tests with NaTs
2809+
([np.datetime64('NaT'),
2810+
np.datetime64('NaT'),
2811+
np.datetime64('2010-01-03T05:14:12'),
2812+
np.datetime64('NaT'),
2813+
np.datetime64('2015-09-23T10:10:13'),
2814+
np.datetime64('1932-10-10T03:50:30')], 5),
28012815
([np.datetime64('2059-03-14T12:43:12'),
28022816
np.datetime64('1996-09-21T14:43:15'),
28032817
np.datetime64('NaT'),
@@ -2 6B43 918,6 +2932,9 @@ def test_datetime(self):
29182932
a[3] = 'NaT'
29192933
assert_equal(np.amin(a), a[0])
29202934
assert_equal(np.amax(a), a[9])
2935+
a[0] = 'NaT'
2936+
assert_equal(np.amin(a), a[1])
2937+
assert_equal(np.amax(a), a[9])
29212938
a.fill('NaT')
29222939
assert_equal(np.amin(a), a[0])
29232940
assert_equal(np.amax(a), a[0])

0 commit comments

Comments
 (0)
0