-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to check if a type is/is_not parent of another type ? #160
Comments
Hey @ttpro1995 - there's a short and a long answer to your question. Short Answer: Type relations are not defined on the types inheritance hierarchy (all types inherit from VisionsBaseType), rather they can be accessed from the Long Answer: Only nodes in a typeset have actual children. The So, children only really exist on a TypeSet but it's pretty easy to get these as well. I'm going to use the Under the hood
So in order to get all possible children of a node in a Typeset we just have to use the networkx API and the Typesets typeset = StandardTypeset()
test_type = Categorical
child_types = typeset.relation_graph[test_type] Technically def is_child(typeset, A, B)
"""Determines if B is a child of A for a given typeset"""
return B in typeset.relation_graph[A] Technically this will only check a single level deep in the tree (i.e. the children), judging from your example you're actually interested in evaluating all possible descendants of a node which can be similarly achieved by import networkx as nx
def is_descendant(typeset, A, B)
"""Determines if B is a descendant of A for a given typeset"""
return B in nx.descendants(typeset.relation_graph, A) EDIT: It occurred to me you may simply be interested in determining whether your data is Numeric or Categorical - there's an even easier way to do this than checking the parent relations which is just to create a new typeset i.e. new_typeset = Generic + Numeric + Category
new_typeset.infer_type(df) |
If you're interested in making a PR to include some of this functionality by default we would be more than happy to help you get those through! In the meantime, I've marked this as an enhancement request. |
Follow the example of "Problem type inference".
From one dataframe, I already make a list of type for each column. Here is the type_list:
type(type_list[0])
givevisions.types.type.VisionsBaseTypeMeta
Now, I want to check if each type either have parent type of Categorical or Numeric.
How should I implement
is_type_parent_of_categorical
?My workaround seem to work because string comparision:
The text was updated successfully, but these errors were encountered: