Skip to content

Commit fad6d62

Browse files
dnowacki-usgsshoyer
authored andcommitted
Return correct count for scalar datetime64 arrays (#2892)
BUG: Fix #2770 by changing ~ to np.logical_not() TST: Add test for scalar datetime64 value DOC: Add to whats-new.rst
1 parent 3354059 commit fad6d62

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

doc/whats-new.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Bug fixes
2626

2727
- indexing with an empty list creates an object with zero-length axis (:issue:`2882`)
2828
By `Mayeul d'Avezac <https://github.com/mdavezac>`_.
29+
- Return correct count for scalar datetime64 arrays (:issue:`2770`)
30+
By `Dan Nowacki <https://github.com/dnowacki-usgs>`_.
2931

3032
.. _whats-new.0.12.1:
3133

xarray/core/duck_array_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def array_notnull_equiv(arr1, arr2):
185185
def count(data, axis=None):
186186
"""Count the number of non-NA in this array along the given axis or axes
187187
"""
188-
return np.sum(~isnull(data), axis=axis)
188+
return np.sum(np.logical_not(isnull(data)), axis=axis)
189189

190190

191191
def where(condition, x, y):

xarray/tests/test_duck_array_ops.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ def test_count(self):
8686
expected = array([[1, 2, 3], [3, 2, 1]])
8787
assert_array_equal(expected, count(self.x, axis=-1))
8888

89+
assert 1 == count(np.datetime64('2000-01-01'))
90+
8991
def test_where_type_promotion(self):
9092
result = where([True, False], [1, 2], ['a', 'b'])
9193
assert_array_equal(result, np.array([1, 'b'], dtype=object))

0 commit comments

Comments
 (0)