@@ -12,29 +12,30 @@ gil_error(PyObject *type, const char *msg)
12
12
PyGILState_Release (gstate );
13
13
}
14
14
15
- #define ANY_TO_STRING_RESOLVE_DESCRIPTORS (safety ) \
16
- static NPY_CASTING any_to_string_##safety##_resolve_descriptors( \
17
- PyObject *NPY_UNUSED(self), PyArray_DTypeMeta *dtypes[2], \
18
- PyArray_Descr *given_descrs[2], PyArray_Descr *loop_descrs[2], \
19
- npy_intp *NPY_UNUSED(view_offset)) \
20
- { \
21
- if (given_descrs[1] == NULL) { \
22
- PyArray_Descr *new = (PyArray_Descr *)new_stringdtype_instance( \
23
- (PyTypeObject *)dtypes[1]); \
24
- if (new == NULL) { \
25
- return (NPY_CASTING)-1; \
26
- } \
27
- loop_descrs[1] = new; \
28
- } \
29
- else { \
30
- Py_INCREF(given_descrs[1]); \
31
- loop_descrs[1] = given_descrs[1]; \
32
- } \
33
- \
34
- Py_INCREF(given_descrs[0]); \
35
- loop_descrs[0] = given_descrs[0]; \
36
- \
37
- return NPY_##safety##_CASTING; \
15
+ #define ANY_TO_STRING_RESOLVE_DESCRIPTORS (safety ) \
16
+ static NPY_CASTING any_to_string_##safety##_resolve_descriptors( \
17
+ PyObject *NPY_UNUSED(self), \
18
+ PyArray_DTypeMeta *NPY_UNUSED(dtypes[2]), \
19
+ PyArray_Descr *given_descrs[2], PyArray_Descr *loop_descrs[2], \
20
+ npy_intp *NPY_UNUSED(view_offset)) \
21
+ { \
22
+ if (given_descrs[1] == NULL) { \
23
+ PyArray_Descr *new = \
24
+ (PyArray_Descr *)new_stringdtype_instance(NA_OBJ); \
25
+ if (new == NULL) { \
26
+ return (NPY_CASTING)-1; \
27
+ } \
28
+ loop_descrs[1] = new; \
29
+ } \
30
+ else { \
31
+ Py_INCREF(given_descrs[1]); \
32
+ loop_descrs[1] = given_descrs[1]; \
33
+ } \
34
+ \
35
+ Py_INCREF(given_descrs[0]); \
36
+ loop_descrs[0] = given_descrs[0]; \
37
+ \
38
+ return NPY_##safety##_CASTING; \
38
39
}
39
40
40
41
ANY_TO_STRING_RESOLVE_DESCRIPTORS (SAFE )
@@ -83,10 +84,12 @@ string_to_string(PyArrayMethod_Context *NPY_UNUSED(context),
83
84
while (N -- ) {
84
85
s = (ss * )in ;
85
86
os = (ss * )out ;
86
- ssfree (os );
87
- if (ssdup (s , os ) < 0 ) {
88
- gil_error (PyExc_MemoryError , "ssdup failed" );
89
- return -1 ;
87
+ if (in != out ) {
88
+ ssfree (os );
89
+ if (ssdup (s , os ) < 0 ) {
90
+ gil_error (PyExc_MemoryError , "ssdup failed" );
91
+ return -1 ;
92
+ }
90
93
}
91
94
92
95
in += in_stride ;
@@ -103,9 +106,6 @@ static PyType_Slot s2s_slots[] = {
103
106
{0 , NULL }};
104
107
105
108
static char * s2s_name = "cast_StringDType_to_StringDType" ;
106
- static char * p2p_name = "cast_PandasStringDType_to_PandasStringDType" ;
107
- static char * s2p_name = "cast_StringDType_to_PandasStringDType" ;
108
- static char * p2s_name = "cast_PandasStringDType_to_StringDType" ;
109
109
110
110
// unicode to string
111
111
@@ -535,6 +535,9 @@ static npy_longlong
535
535
string_to_int (char * in , npy_longlong * value )
536
536
{
537
537
PyObject * pylong_value = string_to_pylong (in );
538
+ if (pylong_value == NULL ) {
539
+ return -1 ;
540
+ }
538
541
* value = PyLong_AsLongLong (pylong_value );
539
542
if (* value == -1 && PyErr_Occurred ()) {
540
543
Py_DECREF (pylong_value );
@@ -683,16 +686,16 @@ uint_to_string(unsigned long long in, char *out)
683
686
static char *shortname##2s_name = "cast_" #typename "_to_StringDType";
684
687
685
688
#define DTYPES_AND_CAST_SPEC (shortname , typename ) \
686
- PyArray_DTypeMeta **s2##shortname##_dtypes = \
687
- get_dtypes(this , &PyArray_##typename##DType); \
689
+ PyArray_DTypeMeta **s2##shortname##_dtypes = get_dtypes( \
690
+ (PyArray_DTypeMeta *)&StringDType , &PyArray_##typename##DType); \
688
691
\
689
692
PyArrayMethod_Spec *StringTo##typename##CastSpec = \
690
693
get_cast_spec(s2##shortname##_name, NPY_UNSAFE_CASTING, \
691
694
NPY_METH_REQUIRES_PYAPI, s2##shortname##_dtypes, \
692
695
s2##shortname##_slots); \
693
696
\
694
- PyArray_DTypeMeta **shortname##2s_dtypes = \
695
- get_dtypes( &PyArray_##typename##DType, this); \
697
+ PyArray_DTypeMeta **shortname##2s_dtypes = get_dtypes( \
698
+ &PyArray_##typename##DType, (PyArray_DTypeMeta *)&StringDType); \
696
699
\
697
700
PyArrayMethod_Spec *typename##ToStringCastSpec = get_cast_spec( \
698
701
shortname##2s_name, NPY_UNSAFE_CASTING, NPY_METH_REQUIRES_PYAPI, \
@@ -946,28 +949,18 @@ get_dtypes(PyArray_DTypeMeta *dt1, PyArray_DTypeMeta *dt2)
946
949
}
947
950
948
951
PyArrayMethod_Spec * *
949
- get_casts (PyArray_DTypeMeta * this , PyArray_DTypeMeta * other )
952
+ get_casts ()
950
953
{
951
- char * t2t_name = NULL ;
954
+ char * t2t_name = s2s_name ;
952
955
953
- if (this == (PyArray_DTypeMeta * )& StringDType ) {
954
- t2t_name = s2s_name ;
955
- }
956
- else {
957
- t2t_name = p2p_name ;
958
- }
959
-
960
- PyArray_DTypeMeta * * t2t_dtypes = get_dtypes (this , this );
956
+ PyArray_DTypeMeta * * t2t_dtypes =
957
+ get_dtypes ((PyArray_DTypeMeta * )& StringDType ,
958
+ (PyArray_DTypeMeta * )& StringDType );
961
959
962
960
PyArrayMethod_Spec * ThisToThisCastSpec =
963
961
get_cast_spec (t2t_name , NPY_NO_CASTING ,
964
962
NPY_METH_SUPPORTS_UNALIGNED , t2t_dtypes , s2s_slots );
965
963
966
- PyArrayMethod_Spec * ThisToOtherCastSpec = NULL ;
967
- PyArrayMethod_Spec * OtherToThisCastSpec = NULL ;
968
-
969
- int is_pandas = (this == (PyArray_DTypeMeta * )& PandasStringDType );
970
-
971
964
int num_casts = 27 ;
972
965
973
966
#if NPY_SIZEOF_BYTE == NPY_SIZEOF_SHORT
@@ -983,41 +976,29 @@ get_casts(PyArray_DTypeMeta *this, PyArray_DTypeMeta *other)
983
976
num_casts += 4 ;
984
977
#endif
985
978
986
- if (is_pandas ) {
987
- num_casts += 2 ;
988
-
989
- PyArray_DTypeMeta * * t2o_dtypes = get_dtypes (this , other );
990
-
991
- ThisToOtherCastSpec = get_cast_spec (p2s_name , NPY_NO_CASTING ,
992
- NPY_METH_SUPPORTS_UNALIGNED ,
993
- t2o_dtypes , s2s_slots );
994
-
995
- PyArray_DTypeMeta * * o2t_dtypes = get_dtypes (other , this );
996
-
997
- OtherToThisCastSpec = get_cast_spec (s2p_name , NPY_NO_CASTING ,
998
- NPY_METH_SUPPORTS_UNALIGNED ,
999
- o2t_dtypes , s2s_slots );
1000
- }
1001
-
1002
- PyArray_DTypeMeta * * u2s_dtypes = get_dtypes (& PyArray_UnicodeDType , this );
979
+ PyArray_DTypeMeta * * u2s_dtypes = get_dtypes (
980
+ & PyArray_UnicodeDType , (PyArray_DTypeMeta * )& StringDType );
1003
981
1004
982
PyArrayMethod_Spec * UnicodeToStringCastSpec = get_cast_spec (
1005
983
u2s_name , NPY_SAFE_CASTING , NPY_METH_NO_FLOATINGPOINT_ERRORS ,
1006
984
u2s_dtypes , u2s_slots );
1007
985
1008
- PyArray_DTypeMeta * * s2u_dtypes = get_dtypes (this , & PyArray_UnicodeDType );
986
+ PyArray_DTypeMeta * * s2u_dtypes = get_dtypes (
987
+ (PyArray_DTypeMeta * )& StringDType , & PyArray_UnicodeDType );
1009
988
1010
989
PyArrayMethod_Spec * StringToUnicodeCastSpec = get_cast_spec (
1011
990
s2u_name , NPY_SAFE_CASTING , NPY_METH_NO_FLOATINGPOINT_ERRORS ,
1012
991
s2u_dtypes , s2u_slots );
1013
992
1014
- PyArray_DTypeMeta * * s2b_dtypes = get_dtypes (this , & PyArray_BoolDType );
993
+ PyArray_DTypeMeta * * s2b_dtypes =
994
+ get_dtypes ((PyArray_DTypeMeta * )& StringDType , & PyArray_BoolDType );
1015
995
1016
996
PyArrayMethod_Spec * StringToBoolCastSpec = get_cast_spec (
1017
997
s2b_name , NPY_UNSAFE_CASTING , NPY_METH_NO_FLOATINGPOINT_ERRORS ,
1018
998
s2b_dtypes , s2b_slots );
1019
999
1020
- PyArray_DTypeMeta * * b2s_dtypes = get_dtypes (& PyArray_BoolDType , this );
1000
+ PyArray_DTypeMeta * * b2s_dtypes =
1001
+ get_dtypes (& PyArray_BoolDType , (PyArray_DTypeMeta * )& StringDType );
1021
1002
1022
1003
PyArrayMethod_Spec * BoolToStringCastSpec = get_cast_spec (
1023
1004
b2s_name , NPY_SAFE_CASTING , NPY_METH_NO_FLOATINGPOINT_ERRORS ,
@@ -1108,14 +1089,7 @@ get_casts(PyArray_DTypeMeta *this, PyArray_DTypeMeta *other)
1108
1089
casts [cast_i ++ ] = FloatToStringCastSpec ;
1109
1090
casts [cast_i ++ ] = StringToHalfCastSpec ;
1110
1091
casts [cast_i ++ ] = HalfToStringCastSpec ;
1111
- if (is_pandas ) {
1112
- casts [cast_i ++ ] = ThisToOtherCastSpec ;
1113
- casts [cast_i ++ ] = OtherToThisCastSpec ;
1114
- casts [cast_i ++ ] = NULL ;
1115
- }
1116
- else {
1117
- casts [cast_i ++ ] = NULL ;
1118
- }
1092
+ casts [cast_i ++ ] = NULL ;
1119
1093
1120
1094
assert (casts [num_casts ] == NULL );
1121
1095
assert (cast_i == num_casts + 1 );
0 commit comments