MCPcopy Create free account
hub / github.com/Pometry/Raphtory / to_df

Method to_df

raphtory/src/python/graph/node.rs:744–801  ·  view source on GitHub ↗
(
        &self,
        include_property_history: bool,
        convert_datetime: bool,
    )

Source from the content-addressed store, hash-verified

742 /// DataFrame: the view of the node data as a pandas Dataframe.
743 #[pyo3(signature = (include_property_history = false, convert_datetime = false))]
744 pub fn to_df(
745 &self,
746 include_property_history: bool,
747 convert_datetime: bool,
748 ) -> PyResult<Py<PyAny>> {
749 let mut column_names = vec![String::from("name"), String::from("type")];
750 let meta = self.nodes.graph().node_meta();
751 let is_prop_both_temp_and_const = get_column_names_from_props(&mut column_names, meta);
752
753 let node_tuples: Vec<_> = self
754 .nodes
755 .collect()
756 .into_par_iter()
757 .flat_map(|item| {
758 let mut properties_map: HashMap<String, Prop> = HashMap::new();
759 let mut prop_time_dict: HashMap<i64, HashMap<String, Prop>> = HashMap::new();
760 extract_properties(
761 include_property_history,
762 convert_datetime,
763 false,
764 &column_names,
765 &is_prop_both_temp_and_const,
766 &item.properties(),
767 &item.metadata(),
768 &mut properties_map,
769 &mut prop_time_dict,
770 item.start().map(|t| t.t()).unwrap_or(0),
771 );
772
773 let row_header: Vec<Prop> = vec![
774 Prop::from(item.name()),
775 Prop::from(item.node_type().unwrap_or_else(|| ArcStr::from(""))),
776 ];
777
778 let start_point = 2;
779 let history = item.history().t().collect();
780
781 create_row(
782 convert_datetime,
783 false,
784 &column_names,
785 properties_map,
786 prop_time_dict,
787 row_header,
788 start_point,
789 history,
790 )
791 })
792 .collect();
793
794 Python::attach(|py| {
795 let kwargs = PyDict::new(py);
796 kwargs.set_item("columns", column_names.clone())?;
797 let pandas = PyModule::import(py, "pandas")?;
798 let df_data = pandas.call_method("DataFrame", (node_tuples,), Some(&kwargs))?;
799 Ok(df_data.unbind())
800 })
801 }

Callers 3

build_to_dfFunction · 0.45
test_to_dfFunction · 0.45
export.pyFile · 0.45

Calls 14

extract_propertiesFunction · 0.85
create_rowFunction · 0.85
node_metaMethod · 0.45
graphMethod · 0.45
collectMethod · 0.45
into_par_iterMethod · 0.45
propertiesMethod · 0.45
metadataMethod · 0.45
mapMethod · 0.45
startMethod · 0.45
tMethod · 0.45

Tested by 2

build_to_dfFunction · 0.36
test_to_dfFunction · 0.36