@@ -1859,72 +1859,17 @@ arraydescr_protocol_typestr_get(PyArray_Descr *self)
1859
1859
}
1860
1860
1861
1861
static PyObject *
1862
- arraydescr_typename_get (PyArray_Descr * self )
1862
+ arraydescr_name_get (PyArray_Descr * self )
1863
1863
{
1864
- static const char np_prefix [] = "numpy." ;
1865
- const int np_prefix_len = sizeof (np_prefix ) - 1 ;
1866
- PyTypeObject * typeobj = self -> typeobj ;
1864
+ /* let python handle this */
1865
+ PyObject * _numpy_dtype ;
1867
1866
PyObject * res ;
1868
- char * s ;
1869
- int len ;
1870
- int prefix_len ;
1871
- int suffix_len ;
1872
-
1873
- if (PyTypeNum_ISUSERDEF (self -> type_num )) {
1874
- s = strrchr (typeobj -> tp_name , '.' );
1875
- if (s == NULL ) {
1876
- res = PyUString_FromString (typeobj -> tp_name );
1877
- }
1878
- else {
1879
- res = PyUString_FromStringAndSize (s + 1 , strlen (s ) - 1 );
1880
- }
1881
- return res ;
1882
- }
1883
- else {
1884
- /*
1885
- * NumPy type or subclass
1886
- *
1887
- * res is derived from typeobj->tp_name with the following rules:
1888
- * - if starts with "numpy.", that prefix is removed
1889
- * - if ends with "_", that suffix is removed
1890
- */
1891
- len = strlen (typeobj -> tp_name );
1892
-
1893
- if (! strncmp (typeobj -> tp_name , np_prefix , np_prefix_len )) {
1894
- prefix_len = np_prefix_len ;
1895
- }
1896
- else {
1897
- prefix_len = 0 ;
1898
- }
1899
-
1900
- if (typeobj -> tp_name [len - 1 ] == '_' ) {
1901
- suffix_len = 1 ;
1902
- }
1903
- else {
1904
- suffix_len = 0 ;
1905
- }
1906
-
1907
- len -= prefix_len ;
1908
- len -= suffix_len ;
1909
- res = PyUString_FromStringAndSize (typeobj -> tp_name + prefix_len , len );
1910
- }
1911
- if (PyTypeNum_ISFLEXIBLE (self -> type_num ) && !PyDataType_ISUNSIZED (self )) {
1912
- PyObject * p ;
1913
- p = PyUString_FromFormat ("%d" , self -> elsize * 8 );
1914
- PyUString_ConcatAndDel (& res , p );
1915
- }
1916
- if (PyDataType_ISDATETIME (self )) {
1917
- PyArray_DatetimeMetaData * meta ;
1918
-
1919
- meta = get_datetime_metadata_from_dtype (self );
1920
- if (meta == NULL ) {
1921
- Py_DECREF (res );
1922
- return NULL ;
1923
- }
1924
-
1925
- res = append_metastr_to_string (meta , 0 , res );
1867
+ _numpy_dtype = PyImport_ImportModule ("numpy.core._dtype" );
1868
+ if (_numpy_dtype == NULL ) {
1869
+ return NULL ;
1926
1870
}
1927
-
1871
+ res = PyObject_CallMethod (_numpy_dtype , "_name_get" , "O" , self );
1872
+ Py_DECREF (_numpy_dtype );
1928
1873
return res ;
1929
1874
}
1930
1875
@@ -2218,7 +2163,7 @@ static PyGetSetDef arraydescr_getsets[] = {
2218
2163
(getter )arraydescr_protocol_typestr_get ,
2219
2164
NULL , NULL , NULL },
2220
2165
{"name" ,
2221
- (getter )arraydescr_typename_get ,
2166
+ (getter )arraydescr_name_get ,
2222
2167
NULL , NULL , NULL },
2223
2168
{"base" ,
2224
2169
(getter )arraydescr_base_get ,
0 commit comments