Skip to content

Commit dc01cd3

Browse files
Apply suggestions from code review
Co-authored-by: nabenabe0928 <[email protected]>
1 parent 80f1c1e commit dc01cd3

File tree

2 files changed

+28
-36
lines changed

2 files changed

+28
-36
lines changed

autoPyTorch/pipeline/components/setup/network_backbone/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def shake_get_alpha_beta(
100100
"""
101101
The methods used in this function have been introduced in 'ShakeShake Regularisation'
102102
https://arxiv.org/abs/1705.07485. The names have been taken from the paper as well.
103-
Currently, this function supports `even-even`, `shake-even` and `shake-shake`
103+
Currently, this function supports `even-even`, `shake-even`, `shake-shake` and `M3`.
104104
"""
105105
if not is_training:
106106
result = (torch.FloatTensor([0.5]), torch.FloatTensor([0.5]))

test/test_data/test_feature_validator.py

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,23 @@ def test_featurevalidator_get_columns_to_encode():
317317
assert feature_types == ['numerical', 'numerical', 'categorical', 'categorical']
318318

319319

320-
def test_featurevalidator_remove_nan_catcolumns():
320+
def feature_validator_remove_nan_catcolumns(df_train: pd.DataFrame, df_test: pd.DataFrame,
321+
ans_train: np.ndarray, ans_test: np.ndarray) -> None:
322+
validator = TabularFeatureValidator()
323+
validator.fit(df_train)
324+
transformed_df_train = validator.transform(df_train)
325+
transformed_df_test = validator.transform(df_test)
326+
327+
assert np.array_equal(transformed_df_train, ans_train)
328+
assert np.array_equal(transformed_df_test, ans_test)
329+
330+
331+
def test_feature_validator_remove_nan_catcolumns():
321332
"""
322333
Make sure categorical columns that have only nan values are removed.
323334
"""
324-
# First case, there exist null columns in the train set
325-
# and the same columns are not all null for the test set.
326-
validator = TabularFeatureValidator()
327-
335+
# First case, there exist null columns (B and C) in the train set
336+
# and a same column (C) are not all null for the test set.
328337
df_train = pd.DataFrame(
329338
[
330339
{'A': 1, 'B': np.nan, 'C': np.nan},
@@ -333,6 +342,7 @@ def test_featurevalidator_remove_nan_catcolumns():
333342
],
334343
dtype='category',
335344
)
345+
ans_train = np.array([[0, 1], [1, 0], [0, 1]], dtype=np.float64)
336346
df_test = pd.DataFrame(
337347
[
338348
{'A': np.nan, 'B': np.nan, 'C': 5},
@@ -341,18 +351,11 @@ def test_featurevalidator_remove_nan_catcolumns():
341351
],
342352
dtype='category',
343353
)
354+
ans_test = np.array([[1, 0], [1, 0], [0, 1]], dtype=np.float64)
355+
feature_validator_remove_nan_catcolumns(df_train, df_test, ans_train, ans_test)
344356

345-
validator.fit(df_train)
346-
transformed_df_train = validator.transform(df_train)
347-
transformed_df_test = validator.transform(df_test)
348-
349-
assert np.array_equal(transformed_df_train, np.array([[0, 1], [1, 0], [0, 1]], dtype=float))
350-
assert np.array_equal(transformed_df_test, np.array([[1, 0], [1, 0], [0, 1]], dtype=float))
351-
352-
# Second case, there exist null columns in the training set and the same
353-
# are null in the test set.
354-
validator = TabularFeatureValidator()
355-
357+
# Second case, there exist null columns (B and C) in the training set and
358+
# the same columns (B and C) are null in the test set.
356359
df_train = pd.DataFrame(
357360
[
358361
{'A': 1, 'B': np.nan, 'C': np.nan},
@@ -361,6 +364,7 @@ def test_featurevalidator_remove_nan_catcolumns():
361364
],
362365
dtype='category',
363366
)
367+
ans_train = np.array([[0, 1], [1, 0], [0, 1]], dtype=np.float64)
364368
df_test = pd.DataFrame(
365369
[
366370
{'A': np.nan, 'B': np.nan, 'C': np.nan},
@@ -369,40 +373,28 @@ def test_featurevalidator_remove_nan_catcolumns():
369373
],
370374
dtype='category',
371375
)
376+
ans_test = np.array([[1, 0], [1, 0], [0, 1]], dtype=np.float64)
377+
feature_validator_remove_nan_catcolumns(df_train, df_test, ans_train, ans_test)
372378

373-
validator.fit(df_train)
374-
transformed_df_train = validator.transform(df_train)
375-
transformed_df_test = validator.transform(df_test)
376-
377-
assert np.array_equal(transformed_df_train, np.array([[0, 1], [1, 0], [0, 1]], dtype=float))
378-
assert np.array_equal(transformed_df_test, np.array([[1, 0], [1, 0], [0, 1]], dtype=float))
379-
380-
# Third case, there exist no null columns in the training set and a
381-
# few null columns exist in the test set.
382-
validator = TabularFeatureValidator()
383-
379+
# Third case, there exist no null columns in the training set and
380+
# null columns exist in the test set.
384381
df_train = pd.DataFrame(
385382
[
386383
{'A': 1, 'B': 1},
387384
{'A': 2, 'B': 2}
388385
],
389386
dtype='category',
390387
)
388+
ans_train = np.array([[1, 0, 1, 0], [0, 1, 0, 1]], dtype=np.float64)
391389
df_test = pd.DataFrame(
392390
[
393391
{'A': np.nan, 'B': np.nan},
394392
{'A': np.nan, 'B': np.nan}
395393
],
396394
dtype='category',
397395
)
398-
399-
validator.fit(df_train)
400-
transformed_df_train = validator.transform(df_train)
401-
transformed_df_test = validator.transform(df_test)
402-
403-
assert np.array_equal(transformed_df_train, np.array([[1, 0, 1, 0], [0, 1, 0, 1]], dtype=float))
404-
assert np.array_equal(transformed_df_test, np.array([[0, 0, 0, 0], [0, 0, 0, 0]], dtype=float))
405-
396+
ans_test = np.array([[0, 0, 0, 0], [0, 0, 0, 0]], dtype=np.float64)
397+
feature_validator_remove_nan_catcolumns(df_train, df_test, ans_train, ans_test)
406398

407399
def test_features_unsupported_calls_are_raised():
408400
"""

0 commit comments

Comments
 (0)