Skip to content

Commit 965f721

Browse files
committed
Merge branch 'master' of https://github.com/pandas-dev/pandas into div_zero2
2 parents d648ef6 + fb3b237 commit 965f721

29 files changed

+585
-458
lines changed

ci/requirements-3.6.run

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ lxml
1313
html5lib
1414
jinja2
1515
sqlalchemy
16-
pymysql
16+
pymysql<0.8.0
1717
feather-format
1818
pyarrow
1919
psycopg2

doc/source/10min.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Selection
154154
While standard Python / Numpy expressions for selecting and setting are
155155
intuitive and come in handy for interactive work, for production code, we
156156
recommend the optimized pandas data access methods, ``.at``, ``.iat``,
157-
``.loc``, ``.iloc`` and ``.ix``.
157+
``.loc`` and ``.iloc``.
158158

159159
See the indexing documentation :ref:`Indexing and Selecting Data <indexing>` and :ref:`MultiIndex / Advanced Indexing <advanced>`.
160160

doc/source/whatsnew/v0.23.0.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ Deprecations
373373
- :func:`read_excel` has deprecated the ``skip_footer`` parameter. Use ``skipfooter`` instead (:issue:`18836`)
374374
- The ``is_copy`` attribute is deprecated and will be removed in a future version (:issue:`18801`).
375375
- ``IntervalIndex.from_intervals`` is deprecated in favor of the :class:`IntervalIndex` constructor (:issue:`19263`)
376-
376+
- :func:``DataFrame.from_items`` is deprecated. Use :func:``DataFrame.from_dict()`` instead, or :func:``DataFrame.from_dict(OrderedDict())`` if you wish to preserve the key order (:issue:`17320`)
377377

378378
.. _whatsnew_0230.prior_deprecations:
379379

@@ -464,6 +464,7 @@ Datetimelike
464464
- Bug in ``.astype()`` to non-ns timedelta units would hold the incorrect dtype (:issue:`19176`, :issue:`19223`, :issue:`12425`)
465465
- Bug in subtracting :class:`Series` from ``NaT`` incorrectly returning ``NaT`` (:issue:`19158`)
466466
- Bug in :func:`Series.truncate` which raises ``TypeError`` with a monotonic ``PeriodIndex`` (:issue:`17717`)
467+
- Bug in :func:`~DataFrame.pct_change` using ``periods`` and ``freq`` returned different length outputs (:issue:`7292`)
467468

468469
Timezones
469470
^^^^^^^^^

pandas/_libs/src/numpy_helper.h

-40
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,6 @@ The full license is in the LICENSE file, distributed with this software.
1818

1919
PANDAS_INLINE npy_int64 get_nat(void) { return NPY_MIN_INT64; }
2020

21-
PANDAS_INLINE int is_integer_object(PyObject* obj) {
22-
return (!PyBool_Check(obj)) && PyArray_IsIntegerScalar(obj);
23-
}
24-
25-
PANDAS_INLINE int is_float_object(PyObject* obj) {
26-
return (PyFloat_Check(obj) || PyArray_IsScalar(obj, Floating));
27-
}
28-
PANDAS_INLINE int is_complex_object(PyObject* obj) {
29-
return (PyComplex_Check(obj) || PyArray_IsScalar(obj, ComplexFloating));
30-
}
31-
32-
PANDAS_INLINE int is_bool_object(PyObject* obj) {
33-
return (PyBool_Check(obj) || PyArray_IsScalar(obj, Bool));
34-
}
35-
36-
PANDAS_INLINE int is_string_object(PyObject* obj) {
37-
return (PyString_Check(obj) || PyUnicode_Check(obj));
38-
}
39-
40-
PANDAS_INLINE int is_datetime64_object(PyObject* obj) {
41-
return PyArray_IsScalar(obj, Datetime);
42-
}
43-
44-
PANDAS_INLINE int is_timedelta64_object(PyObject* obj) {
45-
return PyArray_IsScalar(obj, Timedelta);
46-
}
47-
4821
PANDAS_INLINE int assign_value_1d(PyArrayObject* ap, Py_ssize_t _i,
4922
PyObject* v) {
5023
npy_intp i = (npy_intp)_i;
@@ -80,17 +53,4 @@ void set_array_not_contiguous(PyArrayObject* ao) {
8053
ao->flags &= ~(NPY_C_CONTIGUOUS | NPY_F_CONTIGUOUS);
8154
}
8255

83-
// If arr is zerodim array, return a proper array scalar (e.g. np.int64).
84-
// Otherwise, return arr as is.
85-
PANDAS_INLINE PyObject* unbox_if_zerodim(PyObject* arr) {
86-
if (PyArray_IsZeroDim(arr)) {
87-
PyObject* ret;
88-
ret = PyArray_ToScalar(PyArray_DATA(arr), arr);
89-
return ret;
90-
} else {
91-
Py_INCREF(arr);
92-
return arr;
93-
}
94-
}
95-
9656
#endif // PANDAS__LIBS_SRC_NUMPY_HELPER_H_

pandas/_libs/src/period_helper.c

-32
Original file line numberDiff line numberDiff line change
@@ -1275,38 +1275,6 @@ npy_int64 get_python_ordinal(npy_int64 period_ordinal, int freq) {
12751275
return toDaily(period_ordinal, 'E', &af_info) + ORD_OFFSET;
12761276
}
12771277

1278-
char *str_replace(const char *s, const char *old, const char *new) {
1279-
char *ret;
1280-
int i, count = 0;
1281-
size_t newlen = strlen(new);
1282-
size_t oldlen = strlen(old);
1283-
1284-
for (i = 0; s[i] != '\0'; i++) {
1285-
if (strstr(&s[i], old) == &s[i]) {
1286-
count++;
1287-
i += oldlen - 1;
1288-
}
1289-
}
1290-
1291-
ret = PyArray_malloc(i + 1 + count * (newlen - oldlen));
1292-
if (ret == NULL) {
1293-
return (char *)PyErr_NoMemory();
1294-
}
1295-
1296-
i = 0;
1297-
while (*s) {
1298-
if (strstr(s, old) == s) {
1299-
strncpy(&ret[i], new, sizeof(char) * newlen);
1300-
i += newlen;
1301-
s += oldlen;
1302-
} else {
1303-
ret[i++] = *s++;
1304-
}
1305-
}
1306-
ret[i] = '\0';
1307-
1308-
return ret;
1309-
}
13101278

13111279
// function to generate a nice string representation of the period
13121280
// object, originally from DateObject_strftime

pandas/_libs/src/period_helper.h

-10
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,6 @@ frequency conversion routines.
112112

113113
#define INT_ERR_CODE INT32_MIN
114114

115-
#define MEM_CHECK(item) \
116-
if (item == NULL) { \
117-
return PyErr_NoMemory(); \
118-
}
119-
#define ERR_CHECK(item) \
120-
if (item == NULL) { \
121-
return NULL; \
122-
}
123-
124115
typedef struct asfreq_info {
125116
int from_week_end; // day the week ends on in the "from" frequency
126117
int to_week_end; // day the week ends on in the "to" frequency
@@ -182,7 +173,6 @@ int pminute(npy_int64 ordinal, int freq);
182173
int psecond(npy_int64 ordinal, int freq);
183174
int pdays_in_month(npy_int64 ordinal, int freq);
184175

185-
double getAbsTime(int freq, npy_int64 dailyDate, npy_int64 originalDate);
186176
char *c_strftime(struct date_info *dinfo, char *fmt);
187177
int get_yq(npy_int64 ordinal, int freq, int *quarter, int *year);
188178

pandas/_libs/src/util.pxd

+80-9
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,76 @@
1-
from numpy cimport ndarray
1+
from numpy cimport ndarray, NPY_C_CONTIGUOUS, NPY_F_CONTIGUOUS
22
cimport numpy as cnp
3+
cnp.import_array()
4+
35
cimport cpython
6+
from cpython cimport PyTypeObject
7+
8+
cdef extern from "Python.h":
9+
# Note: importing extern-style allows us to declare these as nogil
10+
# functions, whereas `from cpython cimport` does not.
11+
bint PyUnicode_Check(object obj) nogil
12+
bint PyString_Check(object obj) nogil
13+
bint PyBool_Check(object obj) nogil
14+
bint PyFloat_Check(object obj) nogil
15+
bint PyComplex_Check(object obj) nogil
16+
bint PyObject_TypeCheck(object obj, PyTypeObject* type) nogil
17+
18+
19+
cdef extern from "numpy/arrayobject.h":
20+
PyTypeObject PyFloatingArrType_Type
21+
22+
cdef extern from "numpy/ndarrayobject.h":
23+
PyTypeObject PyTimedeltaArrType_Type
24+
PyTypeObject PyDatetimeArrType_Type
25+
PyTypeObject PyComplexFloatingArrType_Type
26+
PyTypeObject PyBoolArrType_Type
27+
28+
bint PyArray_IsIntegerScalar(obj) nogil
29+
bint PyArray_Check(obj) nogil
30+
31+
# --------------------------------------------------------------------
32+
# Type Checking
33+
34+
cdef inline bint is_string_object(object obj) nogil:
35+
return PyString_Check(obj) or PyUnicode_Check(obj)
36+
37+
38+
cdef inline bint is_integer_object(object obj) nogil:
39+
return not PyBool_Check(obj) and PyArray_IsIntegerScalar(obj)
40+
41+
42+
cdef inline bint is_float_object(object obj) nogil:
43+
return (PyFloat_Check(obj) or
44+
(PyObject_TypeCheck(obj, &PyFloatingArrType_Type)))
45+
446

47+
cdef inline bint is_complex_object(object obj) nogil:
48+
return (PyComplex_Check(obj) or
49+
PyObject_TypeCheck(obj, &PyComplexFloatingArrType_Type))
50+
51+
52+
cdef inline bint is_bool_object(object obj) nogil:
53+
return (PyBool_Check(obj) or
54+
PyObject_TypeCheck(obj, &PyBoolArrType_Type))
55+
56+
57+
cdef inline bint is_timedelta64_object(object obj) nogil:
58+
return PyObject_TypeCheck(obj, &PyTimedeltaArrType_Type)
59+
60+
61+
cdef inline bint is_datetime64_object(object obj) nogil:
62+
return PyObject_TypeCheck(obj, &PyDatetimeArrType_Type)
63+
64+
# --------------------------------------------------------------------
565

666
cdef extern from "numpy_helper.h":
767
void set_array_not_contiguous(ndarray ao)
868

9-
int is_integer_object(object)
10-
int is_float_object(object)
11-
int is_complex_object(object)
12-
int is_bool_object(object)
13-
int is_string_object(object)
14-
int is_datetime64_object(object)
15-
int is_timedelta64_object(object)
1669
int assign_value_1d(ndarray, Py_ssize_t, object) except -1
1770
cnp.int64_t get_nat()
1871
object get_value_1d(ndarray, Py_ssize_t)
1972
char *get_c_string(object) except NULL
2073
object char_to_string(char*)
21-
object unbox_if_zerodim(object arr)
2274

2375
ctypedef fused numeric:
2476
cnp.int8_t
@@ -112,3 +164,22 @@ cdef inline bint _checknan(object val):
112164

113165
cdef inline bint is_period_object(object val):
114166
return getattr(val, '_typ', '_typ') == 'period'
167+
168+
169+
cdef inline object unbox_if_zerodim(object arr):
170+
"""
171+
If arr is zerodim array, return a proper array scalar (e.g. np.int64).
172+
Otherwise, return arr as is.
173+
174+
Parameters
175+
----------
176+
arr : object
177+
178+
Returns
179+
-------
180+
result : object
181+
"""
182+
if cnp.PyArray_IsZeroDim(arr):
183+
return cnp.PyArray_ToScalar(cnp.PyArray_DATA(arr), arr)
184+
else:
185+
return arr

pandas/_libs/tslibs/period.pyx

-9
Original file line numberDiff line numberDiff line change
@@ -372,15 +372,6 @@ cdef object _period_strftime(int64_t value, int freq, object fmt):
372372
ctypedef int (*accessor)(int64_t ordinal, int freq) except INT32_MIN
373373

374374

375-
def get_period_field(int code, int64_t value, int freq):
376-
cdef accessor f = _get_accessor_func(code)
377-
if f is NULL:
378-
raise ValueError('Unrecognized period code: %d' % code)
379-
if value == iNaT:
380-
return np.nan
381-
return f(value, freq)
382-
383-
384375
def get_period_field_arr(int code, ndarray[int64_t] arr, int freq):
385376
cdef:
386377
Py_ssize_t i, sz

pandas/core/frame.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def _constructor(self):
313313

314314
_constructor_sliced = Series
315315
_deprecations = NDFrame._deprecations | frozenset(
316-
['sortlevel', 'get_value', 'set_value', 'from_csv'])
316+
['sortlevel', 'get_value', 'set_value', 'from_csv', 'from_items'])
317317

318318
@property
319319
def _constructor_expanddim(self):
@@ -1246,6 +1246,12 @@ def to_records(self, index=True, convert_datetime64=True):
12461246
@classmethod
12471247
def from_items(cls, items, columns=None, orient='columns'):
12481248
"""
1249+
.. deprecated:: 0.23.0
1250+
from_items is deprecated and will be removed in a
1251+
future version. Use :meth:`DataFrame.from_dict(dict())`
1252+
instead. :meth:`DataFrame.from_dict(OrderedDict(...))` may be used
1253+
to preserve the key order.
1254+
12491255
Convert (key, value) pairs to DataFrame. The keys will be the axis
12501256
index (usually the columns, but depends on the specified
12511257
orientation). The values should be arrays or Series.
@@ -1266,6 +1272,13 @@ def from_items(cls, items, columns=None, orient='columns'):
12661272
-------
12671273
frame : DataFrame
12681274
"""
1275+
1276+
warnings.warn("from_items is deprecated. Please use "
1277+
"DataFrame.from_dict(dict()) instead. "
1278+
"DataFrame.from_dict(OrderedDict()) may be used to "
1279+
"preserve the key order.",
1280+
FutureWarning, stacklevel=2)
1281+
12691282
keys, values = lzip(*items)
12701283

12711284
if orient == 'columns':

pandas/core/generic.py

+1
Original file line numberDiff line numberDiff line change
@@ -7315,6 +7315,7 @@ def pct_change(self, periods=1, fill_method='pad', limit=None, freq=None,
73157315

73167316
rs = (data.div(data.shift(periods=periods, freq=freq, axis=axis,
73177317
**kwargs)) - 1)
7318+
rs = rs.reindex_like(data)
73187319
if freq is None:
73197320
mask = isna(com._values_from_object(self))
73207321
np.putmask(rs.values, mask, np.nan)

pandas/core/internals.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def make_block_same_class(self, values, placement=None, ndim=None,
230230
if dtype is not None:
231231
# issue 19431 fastparquet is passing this
232232
warnings.warn("dtype argument is deprecated, will be removed "
233-
"in a future release.", FutureWarning)
233+
"in a future release.", DeprecationWarning)
234234
if placement is None:
235235
placement = self.mgr_locs
236236
return make_block(values, placement=placement, ndim=ndim,

pandas/io/stata.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import datetime
1414
import struct
1515
import sys
16+
from collections import OrderedDict
1617

1718
import numpy as np
1819
from dateutil.relativedelta import relativedelta
@@ -1571,7 +1572,7 @@ def read(self, nrows=None, convert_dates=None,
15711572
else:
15721573
data_formatted.append((col, data[col]))
15731574
if requires_type_conversion:
1574-
data = DataFrame.from_items(data_formatted)
1575+
data = DataFrame.from_dict(OrderedDict(data_formatted))
15751576
del data_formatted
15761577

15771578
self._do_convert_missing(data, convert_missing)
@@ -1609,7 +1610,7 @@ def read(self, nrows=None, convert_dates=None,
16091610
convert = True
16101611
retyped_data.append((col, data[col].astype(dtype)))
16111612
if convert:
1612-
data = DataFrame.from_items(retyped_data)
1613+
data = DataFrame.from_dict(OrderedDict(retyped_data))
16131614

16141615
if index_col is not None:
16151616
data = data.set_index(data.pop(index_col))
@@ -1722,7 +1723,7 @@ def _do_convert_categoricals(self, data, value_label_dict, lbllist,
17221723
cat_converted_data.append((col, cat_data))
17231724
else:
17241725
cat_converted_data.append((col, data[col]))
1725-
data = DataFrame.from_items(cat_converted_data)
1726+
data = DataFrame.from_dict(OrderedDict(cat_converted_data))
17261727
return data
17271728

17281729
def data_label(self):
@@ -1997,7 +1998,7 @@ def _prepare_categoricals(self, data):
19971998
data_formatted.append((col, values))
19981999
else:
19992000
data_formatted.append((col, data[col]))
2000-
return DataFrame.from_items(data_formatted)
2001+
return DataFrame.from_dict(OrderedDict(data_formatted))
20012002

20022003
def _replace_nans(self, data):
20032004
# return data

0 commit comments

Comments
 (0)