@@ -689,14 +689,14 @@ static PyObject *Py_convert_to_string(PyObject *self, PyObject *args)
689689}
690690
691691
692- const char *Py_is_sorted__doc__ =
693- " is_sorted (array)\n "
692+ const char *Py_is_sorted_and_has_non_nan__doc__ =
693+ " is_sorted_and_has_non_nan (array, / )\n "
694694 " --\n\n "
695- " Return whether the 1D *array* is monotonically increasing, ignoring NaNs.\n " ;
695+ " Return whether the 1D *array* is monotonically increasing, ignoring NaNs,\n "
696+ " and has at least one non-nan value." ;
696697
697- static PyObject *Py_is_sorted (PyObject *self, PyObject *obj)
698+ static PyObject *Py_is_sorted_and_has_non_nan (PyObject *self, PyObject *obj)
698699{
699- npy_intp size;
700700 bool result;
701701
702702 PyArrayObject *array = (PyArrayObject *)PyArray_FromAny (
@@ -706,38 +706,30 @@ static PyObject *Py_is_sorted(PyObject *self, PyObject *obj)
706706 return NULL ;
707707 }
708708
709- size = PyArray_DIM (array, 0 );
710-
711- if (size < 2 ) {
712- Py_DECREF (array);
713- Py_RETURN_TRUE;
714- }
715-
716- /* Handle just the most common types here, otherwise coerce to
717- double */
709+ /* Handle just the most common types here, otherwise coerce to double */
718710 switch (PyArray_TYPE (array)) {
719711 case NPY_INT:
720- result = is_sorted <npy_int>(array);
712+ result = is_sorted_and_has_non_nan <npy_int>(array);
721713 break ;
722714 case NPY_LONG:
723- result = is_sorted <npy_long>(array);
715+ result = is_sorted_and_has_non_nan <npy_long>(array);
724716 break ;
725717 case NPY_LONGLONG:
726- result = is_sorted <npy_longlong>(array);
718+ result = is_sorted_and_has_non_nan <npy_longlong>(array);
727719 break ;
728720 case NPY_FLOAT:
729- result = is_sorted <npy_float>(array);
721+ result = is_sorted_and_has_non_nan <npy_float>(array);
730722 break ;
731723 case NPY_DOUBLE:
732- result = is_sorted <npy_double>(array);
724+ result = is_sorted_and_has_non_nan <npy_double>(array);
733725 break ;
734726 default :
735727 Py_DECREF (array);
736728 array = (PyArrayObject *)PyArray_FromObject (obj, NPY_DOUBLE, 1 , 1 );
737729 if (array == NULL ) {
738730 return NULL ;
739731 }
740- result = is_sorted <npy_double>(array);
732+ result = is_sorted_and_has_non_nan <npy_double>(array);
741733 }
742734
743735 Py_DECREF (array);
@@ -765,7 +757,7 @@ static PyMethodDef module_functions[] = {
765757 {" convert_path_to_polygons" , (PyCFunction)Py_convert_path_to_polygons, METH_VARARGS|METH_KEYWORDS, Py_convert_path_to_polygons__doc__},
766758 {" cleanup_path" , (PyCFunction)Py_cleanup_path, METH_VARARGS, Py_cleanup_path__doc__},
767759 {" convert_to_string" , (PyCFunction)Py_convert_to_string, METH_VARARGS, Py_convert_to_string__doc__},
768- {" is_sorted " , (PyCFunction)Py_is_sorted , METH_O, Py_is_sorted__doc__ },
760+ {" is_sorted_and_has_non_nan " , (PyCFunction)Py_is_sorted_and_has_non_nan , METH_O, Py_is_sorted_and_has_non_nan__doc__ },
769761 {NULL }
770762};
771763
0 commit comments