Skip to content
Snippets Groups Projects
Commit b6e6a4c3 authored by Tiago de Freitas Pereira's avatar Tiago de Freitas Pereira
Browse files

Created a method that emulates isinsntace for aggregation

parent c63f78a3
No related branches found
No related tags found
1 merge request!32Created a method that emulates isinsntace for aggregation
Pipeline #40513 passed
...@@ -189,7 +189,7 @@ def vstack_features(reader, paths, same_size=False, dtype=None): ...@@ -189,7 +189,7 @@ def vstack_features(reader, paths, same_size=False, dtype=None):
return np.reshape(all_features, shape, order="C") return np.reshape(all_features, shape, order="C")
def isinstance_nested(instance, method, isinstance_of): def isinstance_nested(instance, attribute, isinstance_of):
""" """
Check if an object and its nested objects is an instance of a class. Check if an object and its nested objects is an instance of a class.
...@@ -201,20 +201,20 @@ def isinstance_nested(instance, method, isinstance_of): ...@@ -201,20 +201,20 @@ def isinstance_nested(instance, method, isinstance_of):
instance: instance:
Object to be searched Object to be searched
method: attribute:
Method name Attribute name to be recursively searched
isinstance_of: isinstance_of:
Instance class to be searched Instance class to be searched
""" """
if method not in instance.__dict__: if not hasattr(instance, attribute):
return False return False
# Checking the current object and its immediate nested # Checking the current object and its immediate nested
if isinstance(instance,isinstance_of) or isinstance(instance.__dict__[method],isinstance_of): if isinstance(instance,isinstance_of) or isinstance(getattr(instance, attribute), isinstance_of):
return True return True
else: else:
# Recursive search # Recursive search
return isinstance_nested(instance.__dict__[method], method, isinstance_of) return isinstance_nested(getattr(instance, attribute), attribute, isinstance_of)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment