pub struct GraphFrame {
    pub vertices: DataFrame,
    pub edges: DataFrame,
}
Expand description

The GraphFrame type is a struct containing two DataFrame fields, vertices and edges.

Properties:

  • vertices: The vertices property is a DataFrame that represents the nodes in a graph. It must contain a column named Id.

  • edges: The edges property is a DataFrame that represents the edges of a graph. It must contain – at least – two columns: Src and Dst.

Fields§

§vertices: DataFrame

The vertices property is a DataFrame that represents the nodes in a graph.

§edges: DataFrame

The edges property is a DataFrame that represents the edges of a graph.

Implementations§

source§

impl GraphFrame

source

pub fn new( vertices: DataFrame, edges: DataFrame ) -> Result<Self, GraphFrameError>

The function creates a new GraphFrame object with given vertices and edges DataFrames, checking for required columns.

Arguments:

  • vertices: A DataFrame containing information about the vertices of the graph, such as their IDs and attributes.

  • edges: A DataFrame containing information about the edges in the graph. It should have columns named “src” and “dst” to represent the source and destination vertices of each edge.

Returns:

a Result<Self> where Self is the GraphFrame struct. The Ok variant of the Result contains an instance of GraphFrame initialized with the provided vertices and edges DataFrames. If any of the required columns (Id, Src, Dst) are missing in the DataFrames, the function returns an Error.

Examples found in repository?
examples/maximum_value.rs (line 26)
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
fn main() -> Result<(), Box<dyn Error>> {
    let edges = df![
        Subject.as_ref() => [0, 1, 1, 2, 2, 3],
        Object.as_ref() => [1, 0, 3, 1, 3, 2],
    ]?;

    let vertices = df![
        VertexId.as_ref() => [0, 1, 2, 3],
        Custom("value").as_ref() => [3, 6, 2, 1],
    ]?;

    let pregel = PregelBuilder::new(GraphFrame::new(vertices, edges)?)
        .max_iterations(4)
        .with_vertex_column(Custom("max_value"))
        .initial_message(col(Custom("value").as_ref()))
        .send_messages(
            MessageReceiver::Object,
            Column::subject(Custom("max_value")),
        )
        .aggregate_messages(Column::msg(None).max())
        .v_prog(max_exprs([
            col(Custom("max_value").as_ref()),
            Column::msg(None),
        ]))
        .build();

    Ok(println!("{}", pregel.run()?))
}
More examples
Hide additional examples
examples/pagerank.rs (line 25)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
fn main() -> Result<(), Box<dyn Error>> {
    let edges = df![
        Subject.as_ref() => [0, 0, 1, 2, 3, 4, 4, 4],
        Object.as_ref() => [1, 2, 2, 3, 3, 1, 2, 3],
    ]?;

    let vertices = GraphFrame::from_edges(edges.clone())?.out_degrees()?;

    let damping_factor = 0.85;
    let num_vertices: f64 = vertices.column(VertexId.as_ref())?.len() as f64;

    let pregel = PregelBuilder::new(GraphFrame::new(vertices, edges)?)
        .max_iterations(4)
        .with_vertex_column(Custom("rank"))
        .initial_message(lit(1.0 / num_vertices))
        .send_messages(
            MessageReceiver::Subject,
            Column::subject(Column::Custom("rank")) / Column::subject(Column::Custom("out_degree")),
        )
        .send_messages(
            MessageReceiver::Object,
            Column::subject(Custom("rank")) / Column::subject(Custom("out_degree")),
        )
        .aggregate_messages(Column::msg(None).sum())
        .v_prog(
            Column::msg(None) * lit(damping_factor) + lit((1.0 - damping_factor) / num_vertices),
        )
        .build();

    Ok(println!("{}", pregel.run()?))
}
source

pub fn from_edges(edges: DataFrame) -> Result<Self, GraphFrameError>

This function creates a new GraphFrame from a given set of edges by selecting source and destination vertices and concatenating them into a unique set of vertices.

Arguments:

  • edges: A DataFrame containing the edges of a graph, with at least two columns named “src” and “dst” representing the source and destination vertices of each edge.

Returns:

The from_edges function returns a Result<Self> where Self is the GraphFrame struct.

Examples found in repository?
examples/pagerank.rs (line 20)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
fn main() -> Result<(), Box<dyn Error>> {
    let edges = df![
        Subject.as_ref() => [0, 0, 1, 2, 3, 4, 4, 4],
        Object.as_ref() => [1, 2, 2, 3, 3, 1, 2, 3],
    ]?;

    let vertices = GraphFrame::from_edges(edges.clone())?.out_degrees()?;

    let damping_factor = 0.85;
    let num_vertices: f64 = vertices.column(VertexId.as_ref())?.len() as f64;

    let pregel = PregelBuilder::new(GraphFrame::new(vertices, edges)?)
        .max_iterations(4)
        .with_vertex_column(Custom("rank"))
        .initial_message(lit(1.0 / num_vertices))
        .send_messages(
            MessageReceiver::Subject,
            Column::subject(Column::Custom("rank")) / Column::subject(Column::Custom("out_degree")),
        )
        .send_messages(
            MessageReceiver::Object,
            Column::subject(Custom("rank")) / Column::subject(Custom("out_degree")),
        )
        .aggregate_messages(Column::msg(None).sum())
        .v_prog(
            Column::msg(None) * lit(damping_factor) + lit((1.0 - damping_factor) / num_vertices),
        )
        .build();

    Ok(println!("{}", pregel.run()?))
}
source

pub fn out_degrees(self) -> PolarsResult<DataFrame>

This function calculates the out-degree of each node in a graph represented by its edges. The out-degree of a node is defined as the number of out-going edges; that is, edges that have as a source the actual node, and as a destination any other node in a directed-graph.

Returns:

This function returns a Result containing a DataFrame. The DataFrame contains the out-degree of each node in the graph represented by the Graph object. The original DataFrame is preserved; that is, we extend it with the out-degrees of each node.

Examples found in repository?
examples/pagerank.rs (line 20)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
fn main() -> Result<(), Box<dyn Error>> {
    let edges = df![
        Subject.as_ref() => [0, 0, 1, 2, 3, 4, 4, 4],
        Object.as_ref() => [1, 2, 2, 3, 3, 1, 2, 3],
    ]?;

    let vertices = GraphFrame::from_edges(edges.clone())?.out_degrees()?;

    let damping_factor = 0.85;
    let num_vertices: f64 = vertices.column(VertexId.as_ref())?.len() as f64;

    let pregel = PregelBuilder::new(GraphFrame::new(vertices, edges)?)
        .max_iterations(4)
        .with_vertex_column(Custom("rank"))
        .initial_message(lit(1.0 / num_vertices))
        .send_messages(
            MessageReceiver::Subject,
            Column::subject(Column::Custom("rank")) / Column::subject(Column::Custom("out_degree")),
        )
        .send_messages(
            MessageReceiver::Object,
            Column::subject(Custom("rank")) / Column::subject(Custom("out_degree")),
        )
        .aggregate_messages(Column::msg(None).sum())
        .v_prog(
            Column::msg(None) * lit(damping_factor) + lit((1.0 - damping_factor) / num_vertices),
        )
        .build();

    Ok(println!("{}", pregel.run()?))
}
source

pub fn in_degrees(self) -> PolarsResult<DataFrame>

This function calculates the in-degree of each node in a graph represented by its edges. The out-degree of a node is defined as the number of incoming edges; that is, edges that have as a source any node, and as a destination the node itself in a directed-graph.

Returns:

This function returns a Result containing a DataFrame. The DataFrame contains the in-degree of each node in the graph represented by the Graph object. The original DataFrame is preserved; that is, we extend it with the in-degrees of each node.

Trait Implementations§

source§

impl Clone for GraphFrame

source§

fn clone(&self) -> GraphFrame

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Display for GraphFrame

This is the implementation of the Display trait for a GraphFrame struct. This allows instances of the GraphFrame struct to be printed in a formatted way using the println! macro or other formatting macros. The fmt method is defined to format the output as a string that includes the vertices and edges of the graph.

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> DynClone for Twhere T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V