Skip to content

Commit 503ccf9

Browse files
committed
BLD: remaining build/merge issues from master into c-parser
1 parent dd598d5 commit 503ccf9

File tree

4 files changed

+11
-254
lines changed

4 files changed

+11
-254
lines changed

pandas/io/tests/test_parsers.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -772,8 +772,8 @@ def test_parse_cols_str(self):
772772
df2 = df2.reindex(columns=['A', 'B', 'C'])
773773
df3 = xls.parse('Sheet2', skiprows=[1], index_col=0,
774774
parse_dates=True, parse_cols='A:D')
775-
assert_frame_equal(df, df2)
776-
assert_frame_equal(df3, df2)
775+
tm.assert_frame_equal(df, df2)
776+
tm.assert_frame_equal(df3, df2)
777777
del df, df2, df3
778778

779779
df = xls.parse('Sheet1', index_col=0, parse_dates=True,
@@ -783,8 +783,8 @@ def test_parse_cols_str(self):
783783
df3 = xls.parse('Sheet2', skiprows=[1], index_col=0,
784784
parse_dates=True,
785785
parse_cols='A,C,D')
786-
assert_frame_equal(df, df2)
787-
assert_frame_equal(df3, df2)
786+
tm.assert_frame_equal(df, df2)
787+
tm.assert_frame_equal(df3, df2)
788788
del df, df2, df3
789789

790790
df = xls.parse('Sheet1', index_col=0, parse_dates=True,
@@ -794,8 +794,8 @@ def test_parse_cols_str(self):
794794
df3 = xls.parse('Sheet2', skiprows=[1], index_col=0,
795795
parse_dates=True,
796796
parse_cols='A,C:D')
797-
assert_frame_equal(df, df2)
798-
assert_frame_equal(df3, df2)
797+
tm.assert_frame_equal(df, df2)
798+
tm.assert_frame_equal(df3, df2)
799799

800800
def test_read_table_unicode(self):
801801
fin = BytesIO(u'\u0141aski, Jan;1'.encode('utf-8'))
@@ -1794,7 +1794,7 @@ def test_decompression(self):
17941794
os.remove('__tmp__')
17951795
except:
17961796
pass
1797-
1797+
17981798
def test_memory_map(self):
17991799
# it works!
18001800
result = self.read_csv(self.csv1, memory_map=True)

pandas/src/inference.pyx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ def extract_ordinals(ndarray[object] values, freq):
309309
return ordinals
310310

311311

312+
cdef extern from "parse_helper.h":
313+
inline int floatify(object, double *result) except -1
314+
312315

313316
def maybe_convert_numeric(ndarray[object] values, set na_values,
314317
convert_empty=True):
@@ -355,7 +358,7 @@ def maybe_convert_numeric(ndarray[object] values, set na_values,
355358
complexes[i] = val
356359
seen_complex = 1
357360
else:
358-
status = util.floatify(val, &fval)
361+
status = floatify(val, &fval)
359362
floats[i] = fval
360363
if not seen_float:
361364
if '.' in val or fval == INF or fval == NEGINF:

pandas/src/numpy_helper.h

Lines changed: 0 additions & 245 deletions
Original file line numberDiff line numberDiff line change
@@ -133,70 +133,6 @@ char_to_string(char* data) {
133133
// return PyString_Check(obj);
134134
// #endif
135135

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-
200136
PyObject* sarr_from_data(PyArray_Descr *descr, int length, void* data) {
201137
PyArrayObject *result;
202138
npy_intp dims[1] = {length};
@@ -229,187 +165,6 @@ void transfer_object_column(char *dst, char *src, size_t stride,
229165
}
230166

231167

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-
413168
void set_array_owndata(PyArrayObject *ao) {
414169
ao->flags |= NPY_OWNDATA;
415170
}

pandas/src/util.pxd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ cdef extern from "numpy_helper.h":
1515
inline cnp.int64_t get_nat()
1616
inline object get_value_1d(ndarray, Py_ssize_t)
1717
inline char *get_c_string(object)
18-
inline int floatify(object, double *result) except -1
1918
inline object char_to_string(char*)
2019
inline void transfer_object_column(char *dst, char *src, size_t stride,
2120
size_t length)

0 commit comments

Comments
 (0)