Skip to content

Commit a55a492

Browse files
committed
version 0.0.10
1 parent d41a7c0 commit a55a492

File tree

6 files changed

+116
-120
lines changed

6 files changed

+116
-120
lines changed

Cargo.toml

+1-7
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,4 @@ keywords = ["pregel", "graph", "pagerank", "polars", "algorithms"]
1212
categories = ["algorithms", "database", "mathematics", "science"]
1313

1414
[dependencies]
15-
polars = { version = "0.29.0", features = ["lazy", "streaming", "parquet", "performant", "chunked_ids"] }
16-
17-
[package.metadata.docs.rs]
18-
features = []
19-
all-features = false
20-
no-default-features = true
21-
default-target = "x86_64-unknown-linux-gnu"
15+
polars = { version = "0.30.0", features = ["lazy", "streaming", "parquet", "performant", "chunked_ids"] }

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ of your project. You can add the following line to your `Cargo.toml` file:
6363

6464
```toml
6565
[dependencies]
66-
pregel-rs = "0.0.9"
66+
pregel-rs = "0.0.10"
6767
```
6868

6969
4. _Implement your graph algorithm_: Now you can start implementing your graph

examples/maximum_value.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use polars::prelude::*;
22
use pregel_rs::graph_frame::GraphFrame;
3-
use pregel_rs::pregel::Column::{Custom, Dst, Id, Src};
3+
use pregel_rs::pregel::Column::{Custom, Object, Subject, VertexId};
44
use pregel_rs::pregel::{Column, MessageReceiver, PregelBuilder};
55
use std::error::Error;
66

@@ -14,12 +14,12 @@ use std::error::Error;
1414
/// print the result of the `pregel.run()` method call to the console.
1515
fn main() -> Result<(), Box<dyn Error>> {
1616
let edges = df![
17-
Src.as_ref() => [0, 1, 1, 2, 2, 3],
18-
Dst.as_ref() => [1, 0, 3, 1, 3, 2],
17+
Subject.as_ref() => [0, 1, 1, 2, 2, 3],
18+
Object.as_ref() => [1, 0, 3, 1, 3, 2],
1919
]?;
2020

2121
let vertices = df![
22-
Id.as_ref() => [0, 1, 2, 3],
22+
VertexId.as_ref() => [0, 1, 2, 3],
2323
Custom("value").as_ref() => [3, 6, 2, 1],
2424
]?;
2525

examples/pagerank.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use polars::prelude::*;
22
use pregel_rs::graph_frame::GraphFrame;
3-
use pregel_rs::pregel::Column::{Custom, Dst, Id, Src};
3+
use pregel_rs::pregel::Column::{Custom, Object, Subject, VertexId};
44
use pregel_rs::pregel::{Column, MessageReceiver, PregelBuilder};
55
use std::error::Error;
66

@@ -13,14 +13,14 @@ use std::error::Error;
1313
/// result of the `pregel.run()` method call to the console.
1414
fn main() -> Result<(), Box<dyn Error>> {
1515
let edges = df![
16-
Src.as_ref() => [0, 0, 1, 2, 3, 4, 4, 4],
17-
Dst.as_ref() => [1, 2, 2, 3, 3, 1, 2, 3],
16+
Subject.as_ref() => [0, 0, 1, 2, 3, 4, 4, 4],
17+
Object.as_ref() => [1, 2, 2, 3, 3, 1, 2, 3],
1818
]?;
1919

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

2222
let damping_factor = 0.85;
23-
let num_vertices: f64 = vertices.column(Id.as_ref())?.len() as f64;
23+
let num_vertices: f64 = vertices.column(VertexId.as_ref())?.len() as f64;
2424

2525
let pregel = PregelBuilder::new(GraphFrame::new(vertices, edges)?)
2626
.max_iterations(4)

src/graph_frame.rs

+57-59
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::pregel::Column::{Custom, Dst, Id, Src};
1+
use crate::pregel::Column::{Custom, Object, Subject, VertexId};
22
use polars::prelude::*;
33
use std::fmt::{Debug, Display, Formatter};
44
use std::{error, fmt};
@@ -76,24 +76,24 @@ impl error::Error for GraphFrameError {
7676
#[derive(Debug)]
7777
pub enum MissingColumnError {
7878
/// `Id` is a variant of `MissingColumnError` that represents the error that
79-
/// occurs when the `Id` column is missing from a DataFrame.
80-
Id,
79+
/// occurs when the `VertexId` column is missing from a DataFrame.
80+
VertexId,
8181
/// `Src` is a variant of `MissingColumnError` that represents the error that
82-
/// occurs when the `Src` column is missing from a DataFrame.
83-
Src,
82+
/// occurs when the `Subject` column is missing from a DataFrame.
83+
Subject,
8484
/// `Dst` is a variant of `MissingColumnError` that represents the error that
85-
/// occurs when the `Dst` column is missing from a DataFrame.
86-
Dst,
85+
/// occurs when the `Object` column is missing from a DataFrame.
86+
Object,
8787
}
8888

8989
impl Display for MissingColumnError {
9090
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
9191
let message = |df, column: &str| format!("Missing column {} in {}", column, df);
9292

9393
match self {
94-
MissingColumnError::Id => write!(f, "{}", message("vertices", Id.as_ref())),
95-
MissingColumnError::Src => write!(f, "{}", message("edges", Src.as_ref())),
96-
MissingColumnError::Dst => write!(f, "{}", message("edges", Dst.as_ref())),
94+
MissingColumnError::VertexId => write!(f, "{}", message("vertices", VertexId.as_ref())),
95+
MissingColumnError::Subject => write!(f, "{}", message("edges", Subject.as_ref())),
96+
MissingColumnError::Object => write!(f, "{}", message("edges", Object.as_ref())),
9797
}
9898
}
9999
}
@@ -124,14 +124,14 @@ impl GraphFrame {
124124
/// `vertices` and `edges` DataFrames. If any of the required columns (`Id`, `Src`,
125125
/// `Dst`) are missing in the DataFrames, the function returns an `Error`.
126126
pub fn new(vertices: DataFrame, edges: DataFrame) -> Result<Self> {
127-
if !vertices.get_column_names().contains(&Id.as_ref()) {
128-
return Err(GraphFrameError::MissingColumn(MissingColumnError::Id));
127+
if !vertices.get_column_names().contains(&VertexId.as_ref()) {
128+
return Err(GraphFrameError::MissingColumn(MissingColumnError::VertexId));
129129
}
130-
if !edges.get_column_names().contains(&Src.as_ref()) {
131-
return Err(GraphFrameError::MissingColumn(MissingColumnError::Src));
130+
if !edges.get_column_names().contains(&Subject.as_ref()) {
131+
return Err(GraphFrameError::MissingColumn(MissingColumnError::Subject));
132132
}
133-
if !edges.get_column_names().contains(&Dst.as_ref()) {
134-
return Err(GraphFrameError::MissingColumn(MissingColumnError::Dst));
133+
if !edges.get_column_names().contains(&Object.as_ref()) {
134+
return Err(GraphFrameError::MissingColumn(MissingColumnError::Object));
135135
}
136136

137137
Ok(GraphFrame { vertices, edges })
@@ -152,17 +152,17 @@ impl GraphFrame {
152152
/// The `from_edges` function returns a `Result<Self>` where `Self` is the
153153
/// `GraphFrame` struct.
154154
pub fn from_edges(edges: DataFrame) -> Result<Self> {
155-
let srcs = edges
155+
let subjects = edges
156156
.clone() // this is because cloning a DataFrame is cheap
157157
.lazy()
158-
.select([col(Src.as_ref()).alias(Id.as_ref())]);
159-
let dsts = edges
158+
.select([col(Subject.as_ref()).alias(VertexId.as_ref())]);
159+
let objects = edges
160160
.clone() // this is because cloning a DataFrame is cheap
161161
.lazy()
162-
.select([col(Dst.as_ref()).alias(Id.as_ref())]);
163-
let vertices = concat([srcs, dsts], true, true)?
162+
.select([col(Object.as_ref()).alias(VertexId.as_ref())]);
163+
let vertices = concat([subjects, objects], true, true)?
164164
.unique(
165-
Some(vec![Id.as_ref().to_string()]),
165+
Some(vec![VertexId.as_ref().to_string()]),
166166
UniqueKeepStrategy::First,
167167
)
168168
.collect()?;
@@ -184,7 +184,7 @@ impl GraphFrame {
184184
pub fn out_degrees(self) -> PolarsResult<DataFrame> {
185185
self.edges
186186
.lazy()
187-
.groupby([col(Src.as_ref()).alias(Id.as_ref())])
187+
.groupby([col(Subject.as_ref()).alias(VertexId.as_ref())])
188188
.agg([count().alias(Custom("out_degree").as_ref())])
189189
.collect()
190190
}
@@ -203,7 +203,7 @@ impl GraphFrame {
203203
pub fn in_degrees(self) -> PolarsResult<DataFrame> {
204204
self.edges
205205
.lazy()
206-
.groupby([col(Dst.as_ref())])
206+
.groupby([col(Object.as_ref())])
207207
.agg([count().alias(Custom("in_degree").as_ref())])
208208
.collect()
209209
}
@@ -226,26 +226,26 @@ impl Display for GraphFrame {
226226

227227
#[cfg(test)]
228228
mod tests {
229-
use crate::graph_frame::GraphFrame;
229+
use crate::graph_frame::{GraphFrame, GraphFrameError};
230+
use crate::pregel::Column;
230231
use polars::prelude::*;
231232

233+
fn graph() -> Result<GraphFrame, GraphFrameError> {
234+
let subjects = Series::new(Column::Subject.as_ref(), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
235+
let objects = Series::new(Column::Object.as_ref(), [2, 3, 4, 5, 6, 7, 8, 9, 10, 1]);
236+
GraphFrame::from_edges(DataFrame::new(vec![subjects, objects]).unwrap())
237+
}
238+
232239
#[test]
233240
fn test_from_edges() {
234-
let srcs = Series::new("src", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
235-
let dsts = Series::new("dst", [2, 3, 4, 5, 6, 7, 8, 9, 10, 1]);
236-
let edges = DataFrame::new(vec![srcs, dsts]).unwrap();
237-
let graphframe = GraphFrame::from_edges(edges).unwrap();
238-
assert_eq!(graphframe.vertices.height(), 10);
239-
assert_eq!(graphframe.edges.height(), 10);
241+
let graph = graph().unwrap();
242+
assert_eq!(graph.vertices.height(), 10);
243+
assert_eq!(graph.edges.height(), 10);
240244
}
241245

242246
#[test]
243247
fn test_in_degree() {
244-
let srcs = Series::new("src", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
245-
let dsts = Series::new("dst", [2, 3, 4, 5, 6, 7, 8, 9, 10, 1]);
246-
let edges = DataFrame::new(vec![srcs, dsts]).unwrap();
247-
let graphframe = GraphFrame::from_edges(edges).unwrap();
248-
let in_degree = graphframe.in_degrees().unwrap();
248+
let in_degree = graph().unwrap().in_degrees().unwrap();
249249
assert_eq!(in_degree.height(), 10);
250250
assert_eq!(
251251
in_degree
@@ -261,11 +261,7 @@ mod tests {
261261

262262
#[test]
263263
fn test_out_degree() {
264-
let srcs = Series::new("src", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
265-
let dsts = Series::new("dst", [2, 3, 4, 5, 6, 7, 8, 9, 10, 1]);
266-
let edges = DataFrame::new(vec![srcs, dsts]).unwrap();
267-
let graphframe = GraphFrame::from_edges(edges).unwrap();
268-
let out_degree = graphframe.out_degrees().unwrap();
264+
let out_degree = graph().unwrap().out_degrees().unwrap();
269265
assert_eq!(out_degree.height(), 10);
270266
assert_eq!(
271267
out_degree
@@ -280,38 +276,40 @@ mod tests {
280276
}
281277

282278
#[test]
283-
fn test_new_missing_id_column() {
284-
let vertices = DataFrame::new(vec![Series::new("its_not_id", [1, 2, 3])]).unwrap();
285-
let srcs = Series::new("src", [1, 2, 3]);
286-
let dsts = Series::new("dst", [2, 3, 4]);
287-
let edges = DataFrame::new(vec![srcs, dsts]).unwrap();
279+
fn test_new_missing_vertex_id_column() {
280+
let vertices = DataFrame::new(vec![Series::new("not_vertex_id", [1, 2, 3])]).unwrap();
281+
let subjects = Series::new(Column::Subject.as_ref(), [1, 2, 3]);
282+
let objects = Series::new(Column::Object.as_ref(), [2, 3, 4]);
283+
let edges = DataFrame::new(vec![subjects, objects]).unwrap();
288284
match GraphFrame::new(vertices, edges) {
289285
Ok(_) => panic!("Should have failed"),
290-
Err(e) => assert_eq!(e.to_string(), "Missing column id in vertices"),
286+
Err(e) => assert_eq!(e.to_string(), "Missing column vertex_id in vertices"),
291287
}
292288
}
293289

294290
#[test]
295-
fn test_new_missing_src_column() {
296-
let vertices = DataFrame::new(vec![Series::new("id", [1, 2, 3])]).unwrap();
297-
let srcs = Series::new("its_not_src", [1, 2, 3]);
298-
let dsts = Series::new("dst", [2, 3, 4]);
299-
let edges = DataFrame::new(vec![srcs, dsts]).unwrap();
291+
fn test_new_missing_subject_column() {
292+
let vertices =
293+
DataFrame::new(vec![Series::new(Column::VertexId.as_ref(), [1, 2, 3])]).unwrap();
294+
let subjects = Series::new("not_src", [1, 2, 3]);
295+
let objects = Series::new(Column::Object.as_ref(), [2, 3, 4]);
296+
let edges = DataFrame::new(vec![subjects, objects]).unwrap();
300297
match GraphFrame::new(vertices, edges) {
301298
Ok(_) => panic!("Should have failed"),
302-
Err(e) => assert_eq!(e.to_string(), "Missing column src in edges"),
299+
Err(e) => assert_eq!(e.to_string(), "Missing column subject in edges"),
303300
}
304301
}
305302

306303
#[test]
307-
fn test_new_missing_dst_column() {
308-
let vertices = DataFrame::new(vec![Series::new("id", [1, 2, 3])]).unwrap();
309-
let srcs = Series::new("src", [1, 2, 3]);
310-
let dsts = Series::new("its_not_dst", [2, 3, 4]);
311-
let edges = DataFrame::new(vec![srcs, dsts]).unwrap();
304+
fn test_new_missing_object_column() {
305+
let vertices =
306+
DataFrame::new(vec![Series::new(Column::VertexId.as_ref(), [1, 2, 3])]).unwrap();
307+
let subjects = Series::new(Column::Subject.as_ref(), [1, 2, 3]);
308+
let objects = Series::new("not_dst", [2, 3, 4]);
309+
let edges = DataFrame::new(vec![subjects, objects]).unwrap();
312310
match GraphFrame::new(vertices, edges) {
313311
Ok(_) => panic!("Should have failed"),
314-
Err(e) => assert_eq!(e.to_string(), "Missing column dst in edges"),
312+
Err(e) => assert_eq!(e.to_string(), "Missing column object in edges"),
315313
}
316314
}
317315
}

0 commit comments

Comments
 (0)