Skip to content

Commit

Permalink
hotfix bug in feature-cover-injector
Browse files Browse the repository at this point in the history
  • Loading branch information
Anmol-Srivastava committed May 5, 2023
1 parent e1559f3 commit 1da1efd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ _build
*.coverage
*.DS_Store
.idea/
tmp

# Images

Expand Down
3 changes: 2 additions & 1 deletion menelaus/injection/feature_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ def __call__(self, data, col, sample_size, random_state=None):
ret, (col,) = self._preprocess(data, col, return_df=True)

# hide and reorder
ret = ret.groupby(col).sample(n=sample_size, random_state=random_state)
n = sample_size // len(ret[col].unique())
ret = ret.groupby(col).sample(n=n, random_state=random_state)
ret = ret.drop(columns=[col]).reset_index(drop=True)

# handle type and return
Expand Down
5 changes: 2 additions & 3 deletions tests/menelaus/injection/test_feature_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ def test_feature_cover_1():
data = np.array([[0,2], [0,2], [0,2], [1,3], [1,3], [1,3]])
i = FeatureCoverInjector()
copy = i(data, col=0, sample_size=2, random_state=0)
assert copy.shape == (4,1)
assert np.array_equal(np.where(copy[:,0]==2)[0], [0,1])
assert np.array_equal(np.where(copy[:,0]==3)[0], [2,3])
assert copy.shape == (2,1)
assert np.array_equal(copy, [[2], [3]])

def test_feature_shift_1():
''' Check correct feature cover behavior '''
Expand Down

0 comments on commit 1da1efd

Please sign in to comment.