class_docstr: Test behaviour of the learn_dynamic_structure of `from_pandas_dynamic`
class_docstr_tok: ["Test","behaviour","of","the","learn_dynamic_structure","of","`","from_pandas_dynamic","`"]
docstr: Given a small data set with p=1, find all the intra-slice edges and the majority of the inter-slice ones
docstr_tok: ["Given","a","small","data","set","with","p=1",",","find","all","the","intra-slice","edges","and","the","majority","of","the","inter-slice","ones"]
code: def test_expected_structure_learned_p1(self, data_dynotears_p1):
      """
      Given a small data set with p=1, find all the intra-slice edges and the majority of the inter-slice ones
      """
      df = pd.DataFrame(
          data_dynotears_p1["X"], columns=["a", "b", "c", "d", "e"]
      )
      df.loc[-1, :] = data_dynotears_p1["Y"][0, :]
      df = df.sort_index()
  
      sm = from_pandas_dynamic(
          df,
          p=1,
          w_threshold=0.2,
      )
      map_ = dict(zip(range(5), ["a", "b", "c", "d", "e"]))
      w_edges = [
          (f"{map_[i]}_lag0", f"{map_[j]}_lag0")
          for i in range(5)
          for j in range(5)
          if data_dynotears_p1["W"][i, j] != 0
      ]
      a_edges = [
          (
              f"{map_[i % 5]}_lag{1 + i // 5}",
              f"{map_[j]}_lag0",
          )
          for i in range(5)
          for j in range(5)
          if data_dynotears_p1["A"][i, j] != 0
      ]
  
      edges_in_sm_and_a = [el for el in sm.edges if el in a_edges]
      sm_inter_edges = [el for el in sm.edges if "lag0" not in el[0]]
      assert sorted(el for el in sm.edges if "lag0" in el[0]) == sorted(
          w_edges
      )
      assert len(edges_in_sm_and_a) / len(a_edges) > 0.6
      assert len(edges_in_sm_and_a) / len(sm_inter_edges) > 0.9
  
imports: import re
  import networkx
  import numpy
  import pandas
  import pytest
  from causalnex.structure.dynotears import from_numpy_dynamic, from_pandas_dynamic
label_desc: Use image node_id 5 for calling the TestFromPandasDynotears obj's underlying member method code with example usage: obj.test_expected_structure_learned_p1(data_dynotears_p1) without return types