@@ -2098,87 +2098,54 @@ array_setstate(PyArrayObject *self, PyObject *args)
2098
2098
NPY_NO_EXPORT int
2099
2099
PyArray_Dump (PyObject * self , PyObject * file , int protocol )
2100
2100
{
2101
- PyObject * cpick = NULL ;
2101
+ static PyObject * method = NULL ;
2102
2102
PyObject * ret ;
2103
- if (protocol < 0 ) {
2104
- protocol = 2 ;
2105
- }
2106
-
2107
- #if defined(NPY_PY3K )
2108
- cpick = PyImport_ImportModule ("pickle" );
2109
- #else
2110
- cpick = PyImport_ImportModule ("cPickle" );
2111
- #endif
2112
- if (cpick == NULL ) {
2103
+ npy_cache_import ("numpy.core._methods" , "_dump" , & method );
2104
+ if (method == NULL ) {
2113
2105
return -1 ;
2114
2106
}
2115
- if (PyBytes_Check (file ) || PyUnicode_Check (file )) {
2116
- file = npy_PyFile_OpenFile (file , "wb" );
2117
- if (file == NULL ) {
2118
- Py_DECREF (cpick );
2119
- return -1 ;
2120
- }
2107
+ if (protocol < 0 ) {
2108
+ ret = PyObject_CallFunction (method , "OO" , self , file );
2121
2109
}
2122
2110
else {
2123
- Py_INCREF ( file );
<
10000
/code>
2111
+ ret = PyObject_CallFunction ( method , "OOi" , self , file , protocol );
2124
2112
}
2125
- ret = PyObject_CallMethod (cpick , "dump" , "OOi" , self , file , protocol );
2126
- Py_XDECREF (ret );
2127
- Py_DECREF (file );
2128
- Py_DECREF (cpick );
2129
- if (PyErr_Occurred ()) {
2113
+ if (ret == NULL ) {
2130
2114
return -1 ;
2131
2115
}
2116
+ Py_DECREF (ret );
2132
2117
return 0 ;
2133
2118
}
2134
2119
2135
2120
/*NUMPY_API*/
2136
2121
NPY_NO_EXPORT PyObject *
2137
2122
PyArray_Dumps (PyObject * self , int protocol )
2138
2123
{
2139
- PyObject * cpick = NULL ;
2140
- PyObject * ret ;
2124
+ static PyObject * method = NULL ;
2125
+ npy_cache_import ("numpy.core._methods" , "_dumps" , & method );
2126
+ if (method == NULL ) {
2127
+ return NULL ;
2128
+ }
2141
2129
if (protocol < 0 ) {
2142
- protocol = 2 ;
2130
+ return PyObject_CallFunction ( method , "O" , self ) ;
2143
2131
}
2144
- #if defined(NPY_PY3K )
2145
- cpick = PyImport_ImportModule ("pickle" );
2146
- #else
2147
- cpick = PyImport_ImportModule ("cPickle" );
2148
- #endif
2149
- if (cpick == NULL ) {
2150
- return NULL ;
2132
+ else {
2133
+ return PyObject_CallFunction (method , "Oi" , self , protocol );
2151
2134
}
2152
- ret = PyObject_CallMethod (cpick , "dumps" , "Oi" , self , protocol );
2153
- Py_DECREF (cpick );
2154
- return ret ;
2155
2135
}
2156
2136
2157
2137
2158
2138
static PyObject *
2159
- array_dump (PyArrayObject * self , PyObject * args )
2139
+ array_dump (PyArrayObject * self , PyObject * args , PyObject * kwds )
2160
2140
{
2161
- PyObject * file = NULL ;
2162
- int ret ;
2163
-
2164
- if (!PyArg_ParseTuple (args , "O:dump" , & file )) {
2165
- return NULL ;
2166
- }
2167
- ret = PyArray_Dump ((PyObject * )self , file , 2 );
2168
- if (ret < 0 ) {
2169
- return NULL ;
2170
- }
2171
- Py_RETURN_NONE ;
2141
+ NPY_FORWARD_NDARRAY_METHOD ("_dump" );
2172
2142
}
2173
2143
2174
2144
2175
2145
static PyObject *
2176
- array_dumps (PyArrayObject * self , PyObject * args )
2146
+ array_dumps (PyArrayObject * self , PyObject * args , PyObject * kwds )
2177
2147
{
2178
- if (!PyArg_ParseTuple (args , "" )) {
2179
- return NULL ;
2180
- }
2181
- return PyArray_Dumps ((PyObject * )self , 2 );
2148
+ NPY_FORWARD_NDARRAY_METHOD ("_dumps" );
2182
2149
}
2183
2150
2184
2151
@@ -2753,10 +2720,10 @@ NPY_NO_EXPORT PyMethodDef array_methods[] = {
2753
2720
METH_VARARGS , NULL },
2754
2721
{"dumps" ,
2755
2722
(PyCFunction ) array_dumps ,
2756
- METH_VARARGS , NULL },
2723
+ METH_VARARGS | METH_KEYWORDS , NULL },
2757
2724
{"dump" ,
2758
2725
(PyCFunction ) array_dump ,
2759
- METH_VARARGS , NULL },
2726
+ METH_VARARGS | METH_KEYWORDS , NULL },
2760
2727
2761
2728
{"__complex__" ,
2762
2729
(PyCFunction ) array_complex ,
0 commit comments