Skip to content
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
34 changes: 23 additions & 11 deletions src/_arraykit.c
Original file line number Diff line number Diff line change
Expand Up @@ -3770,17 +3770,29 @@ isna_element(PyObject *m, PyObject *args, PyObject *kwargs)
}
// Try to identify Pandas Timestamp NATs
if (PyObject_HasAttrString(element, "to_numpy")) {
PyObject *to_numpy = PyObject_GetAttrString(element, "to_numpy");
if (to_numpy == NULL) {
return NULL;
}
if (!PyCallable_Check(to_numpy)) {
Py_RETURN_FALSE;
}
PyObject* post = PyObject_CallFunction(to_numpy, NULL);
Py_DECREF(to_numpy);
if (post == NULL) return NULL;
return PyBool_FromLong(PyArrayScalar_VAL(post, Datetime) == NPY_DATETIME_NAT);
// strcmp returns 0 on match
return PyBool_FromLong(strcmp(element->ob_type->tp_name, "NaTType") == 0);
// the long way
// PyObject *to_numpy = PyObject_GetAttrString(element, "to_numpy");
// if (to_numpy == NULL) {
// return NULL;
// }
// if (!PyCallable_Check(to_numpy)) {
// Py_DECREF(to_numpy);
// Py_RETURN_FALSE;
// }
// PyObject* scalar = PyObject_CallFunction(to_numpy, NULL);
// Py_DECREF(to_numpy);
// if (scalar == NULL) {
// return NULL;
// }
// if (!PyArray_IsScalar(scalar, Datetime)) {
// Py_DECREF(scalar);
// Py_RETURN_FALSE;
// }
// PyObject* pb = PyBool_FromLong(PyArrayScalar_VAL(scalar, Datetime) == NPY_DATETIME_NAT);
// Py_DECREF(scalar);
// return pb;
}
Py_RETURN_FALSE;
}
Expand Down
4 changes: 4 additions & 0 deletions test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,17 @@ def test_isna_element_d(self) -> None:
ts = pd.Timestamp('nat')
self.assertTrue(isna_element(ts))

s1 = pd.Series((0,))
self.assertFalse(isna_element(s1))


def test_isna_element_e(self) -> None:
from types import SimpleNamespace
sn = SimpleNamespace()
sn.to_numpy = None
self.assertFalse(isna_element(sn))


#---------------------------------------------------------------------------

def test_dtype_from_element_core_dtypes(self) -> None:
Expand Down