Skip to content

Commit 3825cb4

Browse files
committed
Merge commit 'v0.16.2-49-g3908ad5' into debian
* commit 'v0.16.2-49-g3908ad5': DOC: release note for pandas-dev#9607, as_blocks copy arg ENH: allow as_blocks to take a copy argument (pandas-dev#9607) BUG: pandas-dev#10228 resampling empty Series caused segfaults BUG #GH10425 test_categorical big-endian fix BUG: xref pandas-dev#10428, need platform_int as indexer ENH: GH10378 Pass kwargs to interpolation methods.
2 parents be8c77a + 3908ad5 commit 3825cb4

File tree

12 files changed

+204
-11
lines changed

12 files changed

+204
-11
lines changed

doc/source/whatsnew/v0.17.0.txt

+22
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ New features
3131
Other enhancements
3232
^^^^^^^^^^^^^^^^^^
3333

34+
- ``.as_blocks`` will now take a ``copy`` optional argument to return a copy of the data, default is to copy (no change in behavior from prior versions), (:issue:`9607`)
35+
3436
.. _whatsnew_0170.api:
3537

3638
Backwards incompatible API changes
@@ -44,6 +46,7 @@ Other API Changes
4446
^^^^^^^^^^^^^^^^^
4547
- Enable writing Excel files in :ref:`memory <_io.excel_writing_buffer>` using StringIO/BytesIO (:issue:`7074`)
4648
- Enable serialization of lists and dicts to strings in ExcelWriter (:issue:`8188`)
49+
- Allow passing `kwargs` to the interpolation methods (:issue:`10378`).
4750

4851
.. _whatsnew_0170.deprecations:
4952

@@ -72,9 +75,28 @@ Bug Fixes
7275
~~~~~~~~~
7376
- Bug in ``DataFrame.apply`` when function returns categorical series. (:issue:`9573`)
7477

78+
7579
- Bug in ``Index.drop_duplicates`` dropping name(s) (:issue:`10115`)
80+
81+
7682
- Bug in ``pd.Series`` when setting a value on an empty ``Series`` whose index has a frequency. (:issue:`10193`)
83+
84+
7785
- Bug in ``DataFrame.reset_index`` when index contains `NaT`. (:issue:`10388`)
86+
87+
7888
- Bug in ``ExcelReader`` when worksheet is empty (:issue:`6403`)
89+
90+
7991
- Bug in ``Table.select_column`` where name is not preserved (:issue:`10392`)
92+
93+
8094
- Bug in ``DataFrame.interpolate`` with ``axis=1`` and ``inplace=True`` (:issue:`10395`)
95+
96+
97+
98+
- Bug in ``test_categorical`` on big-endian builds (:issue:`10425`)
99+
100+
101+
102+
- Bug that caused segfault when resampling an empty Series (:issue:`10228`)

pandas/algos.pyx

+4
Original file line numberDiff line numberDiff line change
@@ -2157,6 +2157,8 @@ def group_nth_bin_object(ndarray[object, ndim=2] out,
21572157
nobs = np.zeros((<object> out).shape, dtype=np.float64)
21582158
resx = np.empty((<object> out).shape, dtype=object)
21592159

2160+
if len(bins) == 0:
2161+
return
21602162
if bins[len(bins) - 1] == len(values):
21612163
ngroups = len(bins)
21622164
else:
@@ -2247,6 +2249,8 @@ def group_last_bin_object(ndarray[object, ndim=2] out,
22472249
nobs = np.zeros((<object> out).shape, dtype=np.float64)
22482250
resx = np.empty((<object> out).shape, dtype=object)
22492251

2252+
if len(bins) == 0:
2253+
return
22502254
if bins[len(bins) - 1] == len(values):
22512255
ngroups = len(bins)
22522256
else:

pandas/core/common.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,8 @@ def backfill_2d(values, limit=None, mask=None, dtype=None):
15881588
return values
15891589

15901590

1591-
def _clean_interp_method(method, order=None):
1591+
def _clean_interp_method(method, **kwargs):
1592+
order = kwargs.get('order')
15921593
valid = ['linear', 'time', 'index', 'values', 'nearest', 'zero', 'slinear',
15931594
'quadratic', 'cubic', 'barycentric', 'polynomial',
15941595
'krogh', 'piecewise_polynomial',
@@ -1603,7 +1604,7 @@ def _clean_interp_method(method, order=None):
16031604

16041605

16051606
def interpolate_1d(xvalues, yvalues, method='linear', limit=None,
1606-
fill_value=None, bounds_error=False, order=None):
1607+
fill_value=None, bounds_error=False, order=None, **kwargs):
16071608
"""
16081609
Logic for the 1-d interpolation. The result should be 1-d, inputs
16091610
xvalues and yvalues will each be 1-d arrays of the same length.
@@ -1682,18 +1683,17 @@ def _interp_limit(invalid, limit):
16821683
'piecewise_polynomial', 'pchip']
16831684
if method in sp_methods:
16841685
new_x = new_x[firstIndex:]
1685-
xvalues = xvalues[firstIndex:]
16861686

16871687
result[firstIndex:][invalid] = _interpolate_scipy_wrapper(
16881688
valid_x, valid_y, new_x, method=method, fill_value=fill_value,
1689-
bounds_error=bounds_error, order=order)
1689+
bounds_error=bounds_error, order=order, **kwargs)
16901690
if limit:
16911691
result[violate_limit] = np.nan
16921692
return result
16931693

16941694

16951695
def _interpolate_scipy_wrapper(x, y, new_x, method, fill_value=None,
1696-
bounds_error=False, order=None):
1696+
bounds_error=False, order=None, **kwargs):
16971697
"""
16981698
passed off to scipy.interpolate.interp1d. method is scipy's kind.
16991699
Returns an array interpolated at new_x. Add any new methods to
@@ -1734,7 +1734,7 @@ def _interpolate_scipy_wrapper(x, y, new_x, method, fill_value=None,
17341734
bounds_error=bounds_error)
17351735
new_y = terp(new_x)
17361736
elif method == 'spline':
1737-
terp = interpolate.UnivariateSpline(x, y, k=order)
1737+
terp = interpolate.UnivariateSpline(x, y, k=order, **kwargs)
17381738
new_y = terp(new_x)
17391739
else:
17401740
# GH 7295: need to be able to write for some reason
@@ -1746,7 +1746,7 @@ def _interpolate_scipy_wrapper(x, y, new_x, method, fill_value=None,
17461746
if not new_x.flags.writeable:
17471747
new_x = new_x.copy()
17481748
method = alt_methods[method]
1749-
new_y = method(x, y, new_x)
1749+
new_y = method(x, y, new_x, **kwargs)
17501750
return new_y
17511751

17521752

pandas/core/generic.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -2359,14 +2359,18 @@ def ftypes(self):
23592359
return Series(self._data.get_ftypes(), index=self._info_axis,
23602360
dtype=np.object_)
23612361

2362-
def as_blocks(self):
2362+
def as_blocks(self, copy=True):
23632363
"""
23642364
Convert the frame to a dict of dtype -> Constructor Types that each has
23652365
a homogeneous dtype.
23662366
23672367
NOTE: the dtypes of the blocks WILL BE PRESERVED HERE (unlike in
23682368
as_matrix)
23692369
2370+
Parameters
2371+
----------
2372+
copy : boolean, default True
2373+
23702374
Returns
23712375
-------
23722376
values : a dict of dtype -> Constructor Types
@@ -2381,7 +2385,7 @@ def as_blocks(self):
23812385
for dtype, blocks in bd.items():
23822386
# Must combine even after consolidation, because there may be
23832387
# sparse items which are never consolidated into one block.
2384-
combined = self._data.combine(blocks, copy=True)
2388+
combined = self._data.combine(blocks, copy=copy)
23852389
result[dtype] = self._constructor(combined).__finalize__(self)
23862390

23872391
return result
@@ -2896,6 +2900,7 @@ def interpolate(self, method='linear', axis=0, limit=None, inplace=False,
28962900
Update the NDFrame in place if possible.
28972901
downcast : optional, 'infer' or None, defaults to None
28982902
Downcast dtypes if possible.
2903+
kwargs : keyword arguments to pass on to the interpolating function.
28992904
29002905
Returns
29012906
-------

pandas/core/index.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5261,7 +5261,8 @@ def convert_indexer(start, stop, step, indexer=indexer, labels=labels):
52615261
# set that we have selected
52625262
from pandas import Series
52635263
mapper = Series(indexer)
5264-
result = Series(Index(labels.take(indexer)).isin(r).nonzero()[0])
5264+
indexer = labels.take(com._ensure_platform_int(indexer))
5265+
result = Series(Index(indexer).isin(r).nonzero()[0])
52655266
m = result.map(mapper).values
52665267

52675268
else:

pandas/src/generate_code.py

+20
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,8 @@ def group_last_bin_%(name)s(ndarray[%(dest_type2)s, ndim=2] out,
751751
nobs = np.zeros_like(out)
752752
resx = np.empty_like(out)
753753
754+
if len(bins) == 0:
755+
return
754756
if bins[len(bins) - 1] == len(values):
755757
ngroups = len(bins)
756758
else:
@@ -797,6 +799,8 @@ def group_nth_bin_%(name)s(ndarray[%(dest_type2)s, ndim=2] out,
797799
nobs = np.zeros_like(out)
798800
resx = np.empty_like(out)
799801
802+
if len(bin) == 0:
803+
return
800804
if bins[len(bins) - 1] == len(values):
801805
ngroups = len(bins)
802806
else:
@@ -948,6 +952,8 @@ def group_add_bin_%(name)s(ndarray[%(dest_type2)s, ndim=2] out,
948952
nobs = np.zeros_like(out)
949953
sumx = np.zeros_like(out)
950954
955+
if len(bins) == 0:
956+
return
951957
if bins[len(bins) - 1] == len(values):
952958
ngroups = len(bins)
953959
else:
@@ -1064,6 +1070,8 @@ def group_prod_bin_%(name)s(ndarray[%(dest_type2)s, ndim=2] out,
10641070
nobs = np.zeros_like(out)
10651071
prodx = np.ones_like(out)
10661072
1073+
if len(bins) == 0:
1074+
return
10671075
if bins[len(bins) - 1] == len(values):
10681076
ngroups = len(bins)
10691077
else:
@@ -1184,6 +1192,8 @@ def group_var_bin_%(name)s(ndarray[%(dest_type2)s, ndim=2] out,
11841192
sumx = np.zeros_like(out)
11851193
sumxx = np.zeros_like(out)
11861194
1195+
if len(bins) == 0:
1196+
return
11871197
if bins[len(bins) - 1] == len(values):
11881198
ngroups = len(bins)
11891199
else:
@@ -1285,6 +1295,8 @@ def group_count_bin_%(name)s(ndarray[%(dest_type2)s, ndim=2] out,
12851295
ndarray[int64_t, ndim=2] nobs = np.zeros((out.shape[0], out.shape[1]),
12861296
dtype=np.int64)
12871297
1298+
if len(bins) == 0:
1299+
return
12881300
ngroups = len(bins) + (bins[len(bins) - 1] != N)
12891301
12901302
for i in range(N):
@@ -1329,6 +1341,8 @@ def group_min_bin_%(name)s(ndarray[%(dest_type2)s, ndim=2] out,
13291341
minx = np.empty_like(out)
13301342
minx.fill(%(inf_val)s)
13311343
1344+
if len(bins) == 0:
1345+
return
13321346
if bins[len(bins) - 1] == len(values):
13331347
ngroups = len(bins)
13341348
else:
@@ -1453,6 +1467,8 @@ def group_max_bin_%(name)s(ndarray[%(dest_type2)s, ndim=2] out,
14531467
maxx = np.empty_like(out)
14541468
maxx.fill(-%(inf_val)s)
14551469
1470+
if len(bins) == 0:
1471+
return
14561472
if bins[len(bins) - 1] == len(values):
14571473
ngroups = len(bins)
14581474
else:
@@ -1629,6 +1645,8 @@ def group_mean_bin_%(name)s(ndarray[%(dest_type2)s, ndim=2] out,
16291645
sumx = np.zeros_like(out)
16301646
16311647
N, K = (<object> values).shape
1648+
if len(bins) == 0:
1649+
return
16321650
if bins[len(bins) - 1] == len(values):
16331651
ngroups = len(bins)
16341652
else:
@@ -1685,6 +1703,8 @@ def group_ohlc_%(name)s(ndarray[%(dest_type2)s, ndim=2] out,
16851703
%(dest_type2)s vopen, vhigh, vlow, vclose, NA
16861704
bint got_first = 0
16871705
1706+
if len(bins) == 0:
1707+
return
16881708
if bins[len(bins) - 1] == len(values):
16891709
ngroups = len(bins)
16901710
else:

0 commit comments

Comments
 (0)