Skip to content

Commit 25fc49d

Browse files
Garrett-Rjreback
authored andcommitted
BUG: #10228 resampling empty Series caused segfaults
1 parent 7e9026d commit 25fc49d

File tree

6 files changed

+138
-0
lines changed

6 files changed

+138
-0
lines changed

doc/source/whatsnew/v0.17.0.txt

+18
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,28 @@ Bug Fixes
7373
~~~~~~~~~
7474
- Bug in ``DataFrame.apply`` when function returns categorical series. (:issue:`9573`)
7575

76+
7677
- Bug in ``Index.drop_duplicates`` dropping name(s) (:issue:`10115`)
78+
79+
7780
- Bug in ``pd.Series`` when setting a value on an empty ``Series`` whose index has a frequency. (:issue:`10193`)
81+
82+
7883
- Bug in ``DataFrame.reset_index`` when index contains `NaT`. (:issue:`10388`)
84+
85+
7986
- Bug in ``ExcelReader`` when worksheet is empty (:issue:`6403`)
87+
88+
8089
- Bug in ``Table.select_column`` where name is not preserved (:issue:`10392`)
90+
91+
8192
- Bug in ``DataFrame.interpolate`` with ``axis=1`` and ``inplace=True`` (:issue:`10395`)
93+
94+
95+
8296
- Bug in ``test_categorical`` on big-endian builds (:issue:`10425`)
97+
98+
99+
100+
- 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/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:

pandas/src/generated.pyx

+54
Original file line numberDiff line numberDiff line change
@@ -6725,6 +6725,8 @@ def group_add_bin_float64(ndarray[float64_t, ndim=2] out,
67256725
nobs = np.zeros_like(out)
67266726
sumx = np.zeros_like(out)
67276727

6728+
if len(bins) == 0:
6729+
return
67286730
if bins[len(bins) - 1] == len(values):
67296731
ngroups = len(bins)
67306732
else:
@@ -6781,6 +6783,8 @@ def group_add_bin_float32(ndarray[float32_t, ndim=2] out,
67816783
nobs = np.zeros_like(out)
67826784
sumx = np.zeros_like(out)
67836785

6786+
if len(bins) == 0:
6787+
return
67846788
if bins[len(bins) - 1] == len(values):
67856789
ngroups = len(bins)
67866790
else:
@@ -6951,6 +6955,8 @@ def group_prod_bin_float64(ndarray[float64_t, ndim=2] out,
69516955
nobs = np.zeros_like(out)
69526956
prodx = np.ones_like(out)
69536957

6958+
if len(bins) == 0:
6959+
return
69546960
if bins[len(bins) - 1] == len(values):
69556961
ngroups = len(bins)
69566962
else:
@@ -7007,6 +7013,8 @@ def group_prod_bin_float32(ndarray[float32_t, ndim=2] out,
70077013
nobs = np.zeros_like(out)
70087014
prodx = np.ones_like(out)
70097015

7016+
if len(bins) == 0:
7017+
return
70107018
if bins[len(bins) - 1] == len(values):
70117019
ngroups = len(bins)
70127020
else:
@@ -7186,6 +7194,8 @@ def group_var_bin_float64(ndarray[float64_t, ndim=2] out,
71867194
sumx = np.zeros_like(out)
71877195
sumxx = np.zeros_like(out)
71887196

7197+
if len(bins) == 0:
7198+
return
71897199
if bins[len(bins) - 1] == len(values):
71907200
ngroups = len(bins)
71917201
else:
@@ -7247,6 +7257,8 @@ def group_var_bin_float32(ndarray[float32_t, ndim=2] out,
72477257
sumx = np.zeros_like(out)
72487258
sumxx = np.zeros_like(out)
72497259

7260+
if len(bins) == 0:
7261+
return
72507262
if bins[len(bins) - 1] == len(values):
72517263
ngroups = len(bins)
72527264
else:
@@ -7412,6 +7424,8 @@ def group_mean_bin_float64(ndarray[float64_t, ndim=2] out,
74127424
sumx = np.zeros_like(out)
74137425

74147426
N, K = (<object> values).shape
7427+
if len(bins) == 0:
7428+
return
74157429
if bins[len(bins) - 1] == len(values):
74167430
ngroups = len(bins)
74177431
else:
@@ -7465,6 +7479,8 @@ def group_mean_bin_float32(ndarray[float32_t, ndim=2] out,
74657479
sumx = np.zeros_like(out)
74667480

74677481
N, K = (<object> values).shape
7482+
if len(bins) == 0:
7483+
return
74687484
if bins[len(bins) - 1] == len(values):
74697485
ngroups = len(bins)
74707486
else:
@@ -7520,6 +7536,8 @@ def group_ohlc_float64(ndarray[float64_t, ndim=2] out,
75207536
float64_t vopen, vhigh, vlow, vclose, NA
75217537
bint got_first = 0
75227538

7539+
if len(bins) == 0:
7540+
return
75237541
if bins[len(bins) - 1] == len(values):
75247542
ngroups = len(bins)
75257543
else:
@@ -7594,6 +7612,8 @@ def group_ohlc_float32(ndarray[float32_t, ndim=2] out,
75947612
float32_t vopen, vhigh, vlow, vclose, NA
75957613
bint got_first = 0
75967614

7615+
if len(bins) == 0:
7616+
return
75977617
if bins[len(bins) - 1] == len(values):
75987618
ngroups = len(bins)
75997619
else:
@@ -7801,6 +7821,8 @@ def group_last_bin_float64(ndarray[float64_t, ndim=2] out,
78017821
nobs = np.zeros_like(out)
78027822
resx = np.empty_like(out)
78037823

7824+
if len(bins) == 0:
7825+
return
78047826
if bins[len(bins) - 1] == len(values):
78057827
ngroups = len(bins)
78067828
else:
@@ -7845,6 +7867,8 @@ def group_last_bin_float32(ndarray[float32_t, ndim=2] out,
78457867
nobs = np.zeros_like(out)
78467868
resx = np.empty_like(out)
78477869

7870+
if len(bins) == 0:
7871+
return
78487872
if bins[len(bins) - 1] == len(values):
78497873
ngroups = len(bins)
78507874
else:
@@ -7889,6 +7913,8 @@ def group_last_bin_int64(ndarray[int64_t, ndim=2] out,
78897913
nobs = np.zeros_like(out)
78907914
resx = np.empty_like(out)
78917915

7916+
if len(bins) == 0:
7917+
return
78927918
if bins[len(bins) - 1] == len(values):
78937919
ngroups = len(bins)
78947920
else:
@@ -8067,6 +8093,8 @@ def group_nth_bin_float64(ndarray[float64_t, ndim=2] out,
80678093
nobs = np.zeros_like(out)
80688094
resx = np.empty_like(out)
80698095

8096+
if len(bin) == 0:
8097+
return
80708098
if bins[len(bins) - 1] == len(values):
80718099
ngroups = len(bins)
80728100
else:
@@ -8112,6 +8140,8 @@ def group_nth_bin_float32(ndarray[float32_t, ndim=2] out,
81128140
nobs = np.zeros_like(out)
81138141
resx = np.empty_like(out)
81148142

8143+
if len(bin) == 0:
8144+
return
81158145
if bins[len(bins) - 1] == len(values):
81168146
ngroups = len(bins)
81178147
else:
@@ -8157,6 +8187,8 @@ def group_nth_bin_int64(ndarray[int64_t, ndim=2] out,
81578187
nobs = np.zeros_like(out)
81588188
resx = np.empty_like(out)
81598189

8190+
if len(bin) == 0:
8191+
return
81608192
if bins[len(bins) - 1] == len(values):
81618193
ngroups = len(bins)
81628194
else:
@@ -8386,6 +8418,8 @@ def group_min_bin_float64(ndarray[float64_t, ndim=2] out,
83868418
minx = np.empty_like(out)
83878419
minx.fill(np.inf)
83888420

8421+
if len(bins) == 0:
8422+
return
83898423
if bins[len(bins) - 1] == len(values):
83908424
ngroups = len(bins)
83918425
else:
@@ -8447,6 +8481,8 @@ def group_min_bin_float32(ndarray[float32_t, ndim=2] out,
84478481
minx = np.empty_like(out)
84488482
minx.fill(np.inf)
84498483

8484+
if len(bins) == 0:
8485+
return
84508486
if bins[len(bins) - 1] == len(values):
84518487
ngroups = len(bins)
84528488
else:
@@ -8508,6 +8544,8 @@ def group_min_bin_int64(ndarray[int64_t, ndim=2] out,
85088544
minx = np.empty_like(out)
85098545
minx.fill(9223372036854775807)
85108546

8547+
if len(bins) == 0:
8548+
return
85118549
if bins[len(bins) - 1] == len(values):
85128550
ngroups = len(bins)
85138551
else:
@@ -8750,6 +8788,8 @@ def group_max_bin_float64(ndarray[float64_t, ndim=2] out,
87508788
maxx = np.empty_like(out)
87518789
maxx.fill(-np.inf)
87528790

8791+
if len(bins) == 0:
8792+
return
87538793
if bins[len(bins) - 1] == len(values):
87548794
ngroups = len(bins)
87558795
else:
@@ -8810,6 +8850,8 @@ def group_max_bin_float32(ndarray[float32_t, ndim=2] out,
88108850
maxx = np.empty_like(out)
88118851
maxx.fill(-np.inf)
88128852

8853+
if len(bins) == 0:
8854+
return
88138855
if bins[len(bins) - 1] == len(values):
88148856
ngroups = len(bins)
88158857
else:
@@ -8870,6 +8912,8 @@ def group_max_bin_int64(ndarray[int64_t, ndim=2] out,
88708912
maxx = np.empty_like(out)
88718913
maxx.fill(-9223372036854775807)
88728914

8915+
if len(bins) == 0:
8916+
return
88738917
if bins[len(bins) - 1] == len(values):
88748918
ngroups = len(bins)
88758919
else:
@@ -9110,6 +9154,8 @@ def group_count_bin_float64(ndarray[float64_t, ndim=2] out,
91109154
ndarray[int64_t, ndim=2] nobs = np.zeros((out.shape[0], out.shape[1]),
91119155
dtype=np.int64)
91129156

9157+
if len(bins) == 0:
9158+
return
91139159
ngroups = len(bins) + (bins[len(bins) - 1] != N)
91149160

91159161
for i in range(N):
@@ -9144,6 +9190,8 @@ def group_count_bin_float32(ndarray[float32_t, ndim=2] out,
91449190
ndarray[int64_t, ndim=2] nobs = np.zeros((out.shape[0], out.shape[1]),
91459191
dtype=np.int64)
91469192

9193+
if len(bins) == 0:
9194+
return
91479195
ngroups = len(bins) + (bins[len(bins) - 1] != N)
91489196

91499197
for i in range(N):
@@ -9178,6 +9226,8 @@ def group_count_bin_int64(ndarray[int64_t, ndim=2] out,
91789226
ndarray[int64_t, ndim=2] nobs = np.zeros((out.shape[0], out.shape[1]),
91799227
dtype=np.int64)
91809228

9229+
if len(bins) == 0:
9230+
return
91819231
ngroups = len(bins) + (bins[len(bins) - 1] != N)
91829232

91839233
for i in range(N):
@@ -9212,6 +9262,8 @@ def group_count_bin_object(ndarray[object, ndim=2] out,
92129262
ndarray[int64_t, ndim=2] nobs = np.zeros((out.shape[0], out.shape[1]),
92139263
dtype=np.int64)
92149264

9265+
if len(bins) == 0:
9266+
return
92159267
ngroups = len(bins) + (bins[len(bins) - 1] != N)
92169268

92179269
for i in range(N):
@@ -9246,6 +9298,8 @@ def group_count_bin_int64(ndarray[int64_t, ndim=2] out,
92469298
ndarray[int64_t, ndim=2] nobs = np.zeros((out.shape[0], out.shape[1]),
92479299
dtype=np.int64)
92489300

9301+
if len(bins) == 0:
9302+
return
92499303
ngroups = len(bins) + (bins[len(bins) - 1] != N)
92509304

92519305
for i in range(N):

0 commit comments

Comments
 (0)