dowhy icon indicating copy to clipboard operation
dowhy copied to clipboard

KeyError: 'label' error message could be more clear

Open lgmoneda opened this issue 6 years ago • 4 comments

When you miss declaring a node in your causal graph, it's going to throw a KeyError: 'label' error. It could be more explicit to make debugging easier. I think it would be nice to inform what is the node hough used in the graph.

lgmoneda avatar Dec 03 '18 13:12 lgmoneda

Great suggestion. We might need a broader overhaul of logging and exception handling. What do you think @amit-sharma ?

akelleh avatar Mar 07 '19 00:03 akelleh

Is this error caused when calling the 'CausalModel()' when it internally creates the graph through the 'CausalGraph()' API or somewhere else? because I am not able to reproduce the error locally.

yemaedahrav avatar Jul 08 '22 04:07 yemaedahrav

I think this error is raised when you input your own graph as a string and forget to add all required nodes. So if you provide a dot graph with missing nodes, and then call CausalModel with that graph, it should throw this error.

amit-sharma avatar Jul 08 '22 06:07 amit-sharma

Hi! I'm unsure if it persists since I'm not currently using the library. But the point was that the error message didn't help as much as it could in identifying what the missing nodes were.

lgmoneda avatar Jul 12 '22 12:07 lgmoneda

Hey @amit-sharma! I would like to help out in fixing this bug. Can you let me know what kind of error message do you expect?

rahulbshrestha avatar Apr 07 '24 00:04 rahulbshrestha

thanks for contributing, @rahulbshrestha It will be nice to output an error message that describes the source of the bug. Something like, "Some nodes are missing in the graph: {node1name, node2name} "

amit-sharma avatar Apr 07 '24 16:04 amit-sharma

I can't seem to reproduce this issue, how can I provide a dot graph with missing nodes such that the KeyError appears?

Experimenting with this:

# With DOT string
model=CausalModel(
        data = df,
        treatment='X',
        outcome='Y',
        graph="digraph {Z -> X;Z -> Y;X -> Y;}"
        )
model.view_model()

where, df consists of X,Y and Z as columns.

I'm not sure if @lgmoneda meant in this case

# With GML string
model=CausalModel(
        data = df,
        treatment='X',
        outcome='Y',
        graph="""graph[directed 1 node[id "Z" label "Z"]
                    node[id "X" label "X"]
                    #node[id "Y" label "Y"]
                    edge[source "Z" target "X"]
                    edge[source "Z" target "Y"]
                    edge[source "X" target "Y"]]"""

        )
model.view_model()

where an NetworkXError: edge #1 has undefined target 'Y' error is thrown if we remove the node Y.

rahulbshrestha avatar Apr 16 '24 18:04 rahulbshrestha

Try this. Does the following code raise the error?

model=CausalModel( data = df, treatment='X', outcome='Y', graph="digraph {Z -> X;}" ) model.view_model()

amit-sharma avatar Apr 17 '24 07:04 amit-sharma

Nope, it works perfectly fine image

rahulbshrestha avatar Apr 19 '24 20:04 rahulbshrestha

Thanks for checking @rahulbshrestha Looks like this issue is resolved in the current version. We can close this issue.

amit-sharma avatar Apr 21 '24 06:04 amit-sharma