Skip to content

Commit

Permalink
fixing out_of_bounds issue
Browse files Browse the repository at this point in the history
  • Loading branch information
edzwilmm committed Aug 2, 2019
1 parent 8569a8d commit 1ac92ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion impyute/imputation/ts/locf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from impyute.util import find_null
from impyute.util import checks
from impyute.util import preprocess

from impyute.util.errors import BadInputError
@preprocess
@checks
def locf(data, axis=0):
Expand Down Expand Up @@ -33,6 +33,8 @@ def locf(data, axis=0):
data = np.transpose(data)
elif axis == 1:
pass
else:
raise BadInputError("Error: Axis value is invalid, please use either 0 (row format) or 1 (column format)")

null_xy = find_null(data)
for x_i, y_i in null_xy:
Expand Down
10 changes: 9 additions & 1 deletion test/imputation/ts/test_locf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy as np
import impyute as impy
from impyute.util.testing import return_na_check
from impyute.util.errors import BadInputError

SHAPE = (5, 5)

Expand Down Expand Up @@ -32,4 +33,11 @@ def test_na_at_i_end(test_data):
data = test_data(SHAPE, last_i, 3)
actual = impy.locf(data, axis=1)
data[last_i, 3] = data[last_i - 1, 3]
assert np.array_equal(actual, data)
assert np.array_equal(actual, data)


def test_out_of_bounds(test_data):
"""Check out of bounds error, should throw BadInputError for any axis outside [0,1]"""
data = test_data(SHAPE)
with np.testing.assert_raises(BadInputError):
impy.locf(data, axis=3)

0 comments on commit 1ac92ed

Please sign in to comment.