Skip to content

Commit

Permalink
Fix to unify type comparison methods (#311)
Browse files Browse the repository at this point in the history
* Use isinstance

Signed-off-by: Daiki Katsuragawa <50144563+daikikatsuragawa@users.noreply.github.com>

* Use isinstance for multiple types

Signed-off-by: Daiki Katsuragawa <50144563+daikikatsuragawa@users.noreply.github.com>

* Fix issues reported by flake8

Signed-off-by: Daiki Katsuragawa <50144563+daikikatsuragawa@users.noreply.github.com>

Signed-off-by: Daiki Katsuragawa <50144563+daikikatsuragawa@users.noreply.github.com>
  • Loading branch information
daikikatsuragawa authored Oct 7, 2022
1 parent 391bfc7 commit 7a98a0e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dice_ml/data_interfaces/base_data_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def _validate_and_set_outcome_name(self, params):
if 'outcome_name' not in params:
raise ValueError("should provide the name of outcome feature")

if type(params['outcome_name']) is str:
if isinstance(params['outcome_name'], str):
self.outcome_name = params['outcome_name']
else:
raise ValueError("should provide the name of outcome feature as a string")
Expand Down
6 changes: 3 additions & 3 deletions dice_ml/data_interfaces/private_data_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def __init__(self, params):
Default MAD value is 1 for all features.
:param data_name (optional): Dataset name
"""
if sys.version_info > (3, 6, 0) and type(params['features']) in [dict, collections.OrderedDict]:
if sys.version_info > (3, 6, 0) and isinstance(params['features'], (dict, collections.OrderedDict)):
features_dict = params['features']
elif sys.version_info <= (3, 6, 0) and type(params['features']) is collections.OrderedDict:
elif sys.version_info <= (3, 6, 0) and isinstance(params['features'], collections.OrderedDict):
features_dict = params['features']
else:
raise ValueError(
Expand All @@ -52,7 +52,7 @@ def __init__(self, params):
self.categorical_levels = {}

for feature in features_dict:
if type(features_dict[feature][0]) is int: # continuous feature
if isinstance(features_dict[feature][0], int): # continuous feature
self.continuous_feature_names.append(feature)
else:
self.categorical_feature_names.append(feature)
Expand Down
2 changes: 1 addition & 1 deletion dice_ml/data_interfaces/public_data_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _validate_and_set_continuous_features(self, params):
if 'continuous_features' not in params:
raise ValueError('continuous_features should be provided')

if type(params['continuous_features']) is list:
if isinstance(params['continuous_features'], list):
self.continuous_feature_names = params['continuous_features']
else:
raise ValueError(
Expand Down

0 comments on commit 7a98a0e

Please sign in to comment.