@@ -133,70 +133,6 @@ char_to_string(char* data) {
133
133
// return PyString_Check(obj);
134
134
// #endif
135
135
136
- #include <errno.h>
137
- #include <float.h>
138
-
139
- double PANDAS_INLINE xstrtod (const char * p , char * * q , char decimal , char sci , int skip_trailing );
140
-
141
- int to_double (char * item , double * p_value , char sci , char decimal )
142
- {
143
- char * p_end ;
144
-
145
- * p_value = xstrtod (item , & p_end , decimal , sci , 1 );
146
-
147
- return (errno == 0 ) && (!* p_end );
148
- }
149
-
150
- #if PY_VERSION_HEX < 0x02060000
151
- #define PyBytes_Check PyString_Check
152
- #define PyBytes_AS_STRING PyString_AS_STRING
153
- #endif
154
-
155
- PANDAS_INLINE int floatify (PyObject * str , double * result ) {
156
- int status ;
157
- char * data ;
158
- PyObject * tmp = NULL ;
159
- const char sci = 'E' ;
160
- const char dec = '.' ;
161
-
162
- if (PyBytes_Check (str )) {
163
- data = PyBytes_AS_STRING (str );
164
- } else if (PyUnicode_Check (str )) {
165
- tmp = PyUnicode_AsUTF8String (str );
166
- data = PyBytes_AS_STRING (tmp );
167
- } else {
168
- PyErr_SetString (PyExc_TypeError , "Invalid object type" );
169
- return -1 ;
170
- }
171
-
172
- status = to_double (data , result , sci , dec );
173
-
174
- if (!status ) {
175
- /* handle inf/-inf */
176
- if (0 == strcmp (data , "-inf" )) {
177
- * result = - HUGE_VAL ;
178
- } else if (0 == strcmp (data , "inf" )) {
179
- * result = HUGE_VAL ;
180
- } else {
181
- PyErr_SetString (PyExc_ValueError , "Unable to parse string" );
182
- Py_XDECREF (tmp );
183
- return -1 ;
184
- }
185
- }
186
-
187
- Py_XDECREF (tmp );
188
- return 0 ;
189
-
190
- /*
191
- #if PY_VERSION_HEX >= 0x03000000
192
- return PyFloat_FromString(str);
193
- #else
194
- return PyFloat_FromString(str, NULL);
195
- #endif
196
- */
197
-
198
- }
199
-
200
136
PyObject * sarr_from_data (PyArray_Descr * descr , int length , void * data ) {
201
137
PyArrayObject * result ;
202
138
npy_intp dims [1 ] = {length };
@@ -229,187 +165,6 @@ void transfer_object_column(char *dst, char *src, size_t stride,
229
165
}
230
166
231
167
232
- // ---------------------------------------------------------------------------
233
- // Implementation of xstrtod
234
-
235
- //
236
- // strtod.c
237
- //
238
- // Convert string to double
239
- //
240
- // Copyright (C) 2002 Michael Ringgaard. All rights reserved.
241
- //
242
- // Redistribution and use in source and binary forms, with or without
243
- // modification, are permitted provided that the following conditions
244
- // are met:
245
- //
246
- // 1. Redistributions of source code must retain the above copyright
247
- // notice, this list of conditions and the following disclaimer.
248
- // 2. Redistributions in binary form must reproduce the above copyright
249
- // notice, this list of conditions and the following disclaimer in the
250
- // documentation and/or other materials provided with the distribution.
251
- // 3. Neither the name of the project nor the names of its contributors
252
- // may be used to endorse or promote products derived from this software
253
- // without specific prior written permission.
254
- //
255
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
256
- // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
257
- // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
258
- // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
259
- // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
260
- // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
261
- // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
262
- // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
263
- // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
264
- // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
265
- // SUCH DAMAGE.
266
- //
267
- // -----------------------------------------------------------------------
268
- // Modifications by Warren Weckesser, March 2011:
269
- // * Rename strtod() to xstrtod().
270
- // * Added decimal and sci arguments.
271
- // * Skip trailing spaces.
272
- // * Commented out the other functions.
273
- //
274
-
275
- PANDAS_INLINE void lowercase (char * p ) {
276
- for ( ; * p ; ++ p ) * p = tolower (* p );
277
- }
278
-
279
- PANDAS_INLINE void uppercase (char * p ) {
280
- for ( ; * p ; ++ p ) * p = toupper (* p );
281
- }
282
-
283
-
284
- double PANDAS_INLINE xstrtod (const char * str , char * * endptr , char decimal ,
285
- char sci , int skip_trailing )
286
- {
287
- double number ;
288
- int exponent ;
289
- int negative ;
290
- char * p = (char * ) str ;
291
- double p10 ;
292
- int n ;
293
- int num_digits ;
294
- int num_decimals ;
295
-
296
- errno = 0 ;
297
-
298
- // Skip leading whitespace
299
- while (isspace (* p )) p ++ ;
300
-
301
- // Handle optional sign
302
- negative = 0 ;
303
- switch (* p )
304
- {
305
- case '-' : negative = 1 ; // Fall through to increment position
306
- case '+' : p ++ ;
307
- }
308
-
309
- number = 0. ;
310
- exponent = 0 ;
311
- num_digits = 0 ;
312
- num_decimals = 0 ;
313
-
314
- // Process string of digits
315
- while (isdigit (* p ))
316
- {
317
- number = number * 10. + (* p - '0' );
318
- p ++ ;
319
- num_digits ++ ;
320
- }
321
-
322
- // Process decimal part
323
- if (* p == decimal )
324
- {
325
- p ++ ;
326
-
327
- while (isdigit (* p ))
328
- {
329
- number = number * 10. + (* p - '0' );
330
- p ++ ;
331
- num_digits ++ ;
332
- num_decimals ++ ;
333
- }
334
-
335
- exponent -= num_decimals ;
336
- }
337
-
338
- if (num_digits == 0 )
339
- {
340
- errno = ERANGE ;
341
- return 0.0 ;
342
- }
343
-
344
- // Correct for sign
345
- if (negative ) number = - number ;
346
-
347
- // Process an exponent string
348
- if (toupper (* p ) == toupper (sci ))
349
- {
350
- // Handle optional sign
351
- negative = 0 ;
352
- switch (* ++ p )
353
- {
354
- case '-' : negative = 1 ; // Fall through to increment pos
355
- case '+' : p ++ ;
356
- }
357
-
358
- // Process string of digits
359
- n = 0 ;
360
- while (isdigit (* p ))
361
- {
362
- n = n * 10 + (* p - '0' );
363
- p ++ ;
364
- }
365
-
366
- if (negative )
367
- exponent -= n ;
368
- else
369
- exponent += n ;
370
- }
371
-
372
-
373
- if (exponent < DBL_MIN_EXP || exponent > DBL_MAX_EXP )
374
- {
375
-
376
- errno = ERANGE ;
377
- return HUGE_VAL ;
378
- }
379
-
380
- // Scale the result
381
- p10 = 10. ;
382
- n = exponent ;
383
- if (n < 0 ) n = - n ;
384
- while (n )
385
- {
386
- if (n & 1 )
387
- {
388
- if (exponent < 0 )
389
- number /= p10 ;
390
- else
391
- number *= p10 ;
392
- }
393
- n >>= 1 ;
394
- p10 *= p10 ;
395
- }
396
-
397
-
398
- if (number == HUGE_VAL ) {
399
- errno = ERANGE ;
400
- }
401
-
402
- if (skip_trailing ) {
403
- // Skip trailing whitespace
404
- while (isspace (* p )) p ++ ;
405
- }
406
-
407
- if (endptr ) * endptr = p ;
408
-
409
-
410
- return number ;
411
- }
412
-
413
168
void set_array_owndata (PyArrayObject * ao ) {
414
169
ao -> flags |= NPY_OWNDATA ;
415
170
}
0 commit comments