Skip to content

BUG: fillna with method segfaults on zero-length input (fixes #2775) #2778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions pandas/src/generate_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ def pad_inplace_%(name)s(ndarray[%(c_type)s] values,

N = len(values)

# GH 2778
if N == 0:
return

if limit is None:
lim = N
else:
Expand Down Expand Up @@ -419,6 +423,10 @@ def pad_2d_inplace_%(name)s(ndarray[%(c_type)s, ndim=2] values,

K, N = (<object> values).shape

# GH 2778
if N == 0:
return

if limit is None:
lim = N
else:
Expand Down Expand Up @@ -451,6 +459,10 @@ def backfill_2d_inplace_%(name)s(ndarray[%(c_type)s, ndim=2] values,

K, N = (<object> values).shape

# GH 2778
if N == 0:
return

if limit is None:
lim = N
else:
Expand Down Expand Up @@ -483,6 +495,10 @@ def backfill_inplace_%(name)s(ndarray[%(c_type)s] values,

N = len(values)

# GH 2778
if N == 0:
return

if limit is None:
lim = N
else:
Expand Down
80 changes: 80 additions & 0 deletions pandas/src/generated.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,10 @@ def pad_inplace_float64(ndarray[float64_t] values,

N = len(values)

# GH 2778
if N == 0:
return

if limit is None:
lim = N
else:
Expand Down Expand Up @@ -855,6 +859,10 @@ def pad_inplace_object(ndarray[object] values,

N = len(values)

# GH 2778
if N == 0:
return

if limit is None:
lim = N
else:
Expand Down Expand Up @@ -884,6 +892,10 @@ def pad_inplace_int32(ndarray[int32_t] values,

N = len(values)

# GH 2778
if N == 0:
return

if limit is None:
lim = N
else:
Expand Down Expand Up @@ -913,6 +925,10 @@ def pad_inplace_int64(ndarray[int64_t] values,

N = len(values)

# GH 2778
if N == 0:
return

if limit is None:
lim = N
else:
Expand Down Expand Up @@ -942,6 +958,10 @@ def pad_inplace_bool(ndarray[uint8_t] values,

N = len(values)

# GH 2778
if N == 0:
return

if limit is None:
lim = N
else:
Expand Down Expand Up @@ -972,6 +992,10 @@ def backfill_inplace_float64(ndarray[float64_t] values,

N = len(values)

# GH 2778
if N == 0:
return

if limit is None:
lim = N
else:
Expand Down Expand Up @@ -1000,6 +1024,10 @@ def backfill_inplace_object(ndarray[object] values,

N = len(values)

# GH 2778
if N == 0:
return

if limit is None:
lim = N
else:
Expand Down Expand Up @@ -1028,6 +1056,10 @@ def backfill_inplace_int32(ndarray[int32_t] values,

N = len(values)

# GH 2778
if N == 0:
return

if limit is None:
lim = N
else:
Expand Down Expand Up @@ -1056,6 +1088,10 @@ def backfill_inplace_int64(ndarray[int64_t] values,

N = len(values)

# GH 2778
if N == 0:
return

if limit is None:
lim = N
else:
Expand Down Expand Up @@ -1084,6 +1120,10 @@ def backfill_inplace_bool(ndarray[uint8_t] values,

N = len(values)

# GH 2778
if N == 0:
return

if limit is None:
lim = N
else:
Expand Down Expand Up @@ -1113,6 +1153,10 @@ def pad_2d_inplace_float64(ndarray[float64_t, ndim=2] values,

K, N = (<object> values).shape

# GH 2778
if N == 0:
return

if limit is None:
lim = N
else:
Expand Down Expand Up @@ -1143,6 +1187,10 @@ def pad_2d_inplace_object(ndarray[object, ndim=2] values,

K, N = (<object> values).shape

# GH 2778
if N == 0:
return

if limit is None:
lim = N
else:
Expand Down Expand Up @@ -1173,6 +1221,10 @@ def pad_2d_inplace_int32(ndarray[int32_t, ndim=2] values,

K, N = (<object> values).shape

# GH 2778
if N == 0:
return

if limit is None:
lim = N
else:
Expand Down Expand Up @@ -1203,6 +1255,10 @@ def pad_2d_inplace_int64(ndarray[int64_t, ndim=2] values,

K, N = (<object> values).shape

# GH 2778
if N == 0:
return

if limit is None:
lim = N
else:
Expand Down Expand Up @@ -1233,6 +1289,10 @@ def pad_2d_inplace_bool(ndarray[uint8_t, ndim=2] values,

K, N = (<object> values).shape

# GH 2778
if N == 0:
return

if limit is None:
lim = N
else:
Expand Down Expand Up @@ -1264,6 +1324,10 @@ def backfill_2d_inplace_float64(ndarray[float64_t, ndim=2] values,

K, N = (<object> values).shape

# GH 2778
if N == 0:
return

if limit is None:
lim = N
else:
Expand Down Expand Up @@ -1294,6 +1358,10 @@ def backfill_2d_inplace_object(ndarray[object, ndim=2] values,

K, N = (<object> values).shape

# GH 2778
if N == 0:
return

if limit is None:
lim = N
else:
Expand Down Expand Up @@ -1324,6 +1392,10 @@ def backfill_2d_inplace_int32(ndarray[int32_t, ndim=2] values,

K, N = (<object> values).shape

# GH 2778
if N == 0:
return

if limit is None:
lim = N
else:
Expand Down Expand Up @@ -1354,6 +1426,10 @@ def backfill_2d_inplace_int64(ndarray[int64_t, ndim=2] values,

K, N = (<object> values).shape

# GH 2778
if N == 0:
return

if limit is None:
lim = N
else:
Expand Down Expand Up @@ -1384,6 +1460,10 @@ def backfill_2d_inplace_bool(ndarray[uint8_t, ndim=2] values,

K, N = (<object> values).shape

# GH 2778
if N == 0:
return

if limit is None:
lim = N
else:
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4670,6 +4670,12 @@ def test_fillna(self):
self.assertRaises(ValueError, self.tsframe.fillna)
self.assertRaises(ValueError, self.tsframe.fillna, 5, method='ffill')

# empty frame (GH #2778)
df = DataFrame(columns=['x'])
for m in ['pad','backfill']:
df.x.fillna(method=m,inplace=1)
df.x.fillna(method=m)

def test_ffill(self):
self.tsframe['A'][:5] = nan
self.tsframe['A'][-5:] = nan
Expand Down