@@ -125,13 +125,13 @@ impl GraphFrame {
125
125
/// `vertices` and `edges` DataFrames. If any of the required columns (`Id`, `Src`,
126
126
/// `Dst`) are missing in the DataFrames, the function returns an `Error`.
127
127
pub fn new ( vertices : DataFrame , edges : DataFrame ) -> Result < Self > {
128
- if !vertices. get_column_names ( ) . contains ( & VertexId . as_ref ( ) ) {
128
+ if !vertices. get_column_names_str ( ) . contains ( & VertexId . as_ref ( ) ) {
129
129
return Err ( GraphFrameError :: MissingColumn ( MissingColumnError :: VertexId ) ) ;
130
130
}
131
- if !edges. get_column_names ( ) . contains ( & Subject . as_ref ( ) ) {
131
+ if !edges. get_column_names_str ( ) . contains ( & Subject . as_ref ( ) ) {
132
132
return Err ( GraphFrameError :: MissingColumn ( MissingColumnError :: Subject ) ) ;
133
133
}
134
- if !edges. get_column_names ( ) . contains ( & Object . as_ref ( ) ) {
134
+ if !edges. get_column_names_str ( ) . contains ( & Object . as_ref ( ) ) {
135
135
return Err ( GraphFrameError :: MissingColumn ( MissingColumnError :: Object ) ) ;
136
136
}
137
137
@@ -161,7 +161,7 @@ impl GraphFrame {
161
161
. clone ( ) // this is because cloning a DataFrame is cheap
162
162
. lazy ( )
163
163
. select ( [ col ( Object . as_ref ( ) ) . alias ( VertexId . as_ref ( ) ) ] ) ;
164
- let vertices = concat ( [ subjects, objects] , true , true ) ?
164
+ let vertices = concat ( [ subjects, objects] , Default :: default ( ) ) ?
165
165
. unique (
166
166
Some ( vec ! [ VertexId . as_ref( ) . to_string( ) ] ) ,
167
167
UniqueKeepStrategy :: First ,
@@ -185,8 +185,10 @@ impl GraphFrame {
185
185
pub fn out_degrees ( self ) -> PolarsResult < DataFrame > {
186
186
self . edges
187
187
. lazy ( )
188
- . groupby ( [ col ( Subject . as_ref ( ) ) . alias ( VertexId . as_ref ( ) ) ] )
189
- . agg ( [ count ( ) . alias ( Custom ( "out_degree" ) . as_ref ( ) ) ] )
188
+ . group_by ( [ col ( Subject . as_ref ( ) ) . alias ( VertexId . as_ref ( ) ) ] )
189
+ . agg ( [ col ( Object . as_ref ( ) )
190
+ . count ( )
191
+ . alias ( Custom ( "out_degree" ) . as_ref ( ) ) ] )
190
192
. collect ( )
191
193
}
192
194
@@ -204,8 +206,10 @@ impl GraphFrame {
204
206
pub fn in_degrees ( self ) -> PolarsResult < DataFrame > {
205
207
self . edges
206
208
. lazy ( )
207
- . groupby ( [ col ( Object . as_ref ( ) ) ] )
208
- . agg ( [ count ( ) . alias ( Custom ( "in_degree" ) . as_ref ( ) ) ] )
209
+ . group_by ( [ col ( Object . as_ref ( ) ) ] )
210
+ . agg ( [ col ( Subject . as_ref ( ) )
211
+ . count ( )
212
+ . alias ( Custom ( "in_degree" ) . as_ref ( ) ) ] )
209
213
. collect ( )
210
214
}
211
215
}
@@ -232,8 +236,16 @@ mod tests {
232
236
use polars:: prelude:: * ;
233
237
234
238
fn graph ( ) -> Result < GraphFrame , GraphFrameError > {
235
- let subjects = Series :: new ( Column :: Subject . as_ref ( ) , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ) ;
236
- let objects = Series :: new ( Column :: Object . as_ref ( ) , [ 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 1 ] ) ;
239
+ let subjects = Series :: new (
240
+ Column :: Subject . as_ref ( ) . into ( ) ,
241
+ [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ,
242
+ )
243
+ . into ( ) ;
244
+ let objects = Series :: new (
245
+ Column :: Object . as_ref ( ) . into ( ) ,
246
+ [ 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 1 ] ,
247
+ )
248
+ . into ( ) ;
237
249
GraphFrame :: from_edges ( DataFrame :: new ( vec ! [ subjects, objects] ) . unwrap ( ) )
238
250
}
239
251
@@ -278,9 +290,10 @@ mod tests {
278
290
279
291
#[ test]
280
292
fn test_new_missing_vertex_id_column ( ) {
281
- let vertices = DataFrame :: new ( vec ! [ Series :: new( "not_vertex_id" , [ 1 , 2 , 3 ] ) ] ) . unwrap ( ) ;
282
- let subjects = Series :: new ( Column :: Subject . as_ref ( ) , [ 1 , 2 , 3 ] ) ;
283
- let objects = Series :: new ( Column :: Object . as_ref ( ) , [ 2 , 3 , 4 ] ) ;
293
+ let vertices =
294
+ DataFrame :: new ( vec ! [ Series :: new( "not_vertex_id" . into( ) , [ 1 , 2 , 3 ] ) . into( ) ] ) . unwrap ( ) ;
295
+ let subjects = Series :: new ( Column :: Subject . as_ref ( ) . into ( ) , [ 1 , 2 , 3 ] ) . into ( ) ;
296
+ let objects = Series :: new ( Column :: Object . as_ref ( ) . into ( ) , [ 2 , 3 , 4 ] ) . into ( ) ;
284
297
let edges = DataFrame :: new ( vec ! [ subjects, objects] ) . unwrap ( ) ;
285
298
match GraphFrame :: new ( vertices, edges) {
286
299
Ok ( _) => panic ! ( "Should have failed" ) ,
@@ -290,10 +303,14 @@ mod tests {
290
303
291
304
#[ test]
292
305
fn test_new_missing_subject_column ( ) {
293
- let vertices =
294
- DataFrame :: new ( vec ! [ Series :: new( Column :: VertexId . as_ref( ) , [ 1 , 2 , 3 ] ) ] ) . unwrap ( ) ;
295
- let subjects = Series :: new ( "not_src" , [ 1 , 2 , 3 ] ) ;
296
- let objects = Series :: new ( Column :: Object . as_ref ( ) , [ 2 , 3 , 4 ] ) ;
306
+ let vertices = DataFrame :: new ( vec ! [ Series :: new(
307
+ Column :: VertexId . as_ref( ) . into( ) ,
308
+ [ 1 , 2 , 3 ] ,
309
+ )
310
+ . into( ) ] )
311
+ . unwrap ( ) ;
312
+ let subjects = Series :: new ( "not_src" . into ( ) , [ 1 , 2 , 3 ] ) . into ( ) ;
313
+ let objects = Series :: new ( Column :: Object . as_ref ( ) . into ( ) , [ 2 , 3 , 4 ] ) . into ( ) ;
297
314
let edges = DataFrame :: new ( vec ! [ subjects, objects] ) . unwrap ( ) ;
298
315
match GraphFrame :: new ( vertices, edges) {
299
316
Ok ( _) => panic ! ( "Should have failed" ) ,
@@ -303,10 +320,14 @@ mod tests {
303
320
304
321
#[ test]
305
322
fn test_new_missing_object_column ( ) {
306
- let vertices =
307
- DataFrame :: new ( vec ! [ Series :: new( Column :: VertexId . as_ref( ) , [ 1 , 2 , 3 ] ) ] ) . unwrap ( ) ;
308
- let subjects = Series :: new ( Column :: Subject . as_ref ( ) , [ 1 , 2 , 3 ] ) ;
309
- let objects = Series :: new ( "not_dst" , [ 2 , 3 , 4 ] ) ;
323
+ let vertices = DataFrame :: new ( vec ! [ Series :: new(
324
+ Column :: VertexId . as_ref( ) . into( ) ,
325
+ [ 1 , 2 , 3 ] ,
326
+ )
327
+ . into( ) ] )
328
+ . unwrap ( ) ;
329
+ let subjects = Series :: new ( Column :: Subject . as_ref ( ) . into ( ) , [ 1 , 2 , 3 ] ) . into ( ) ;
330
+ let objects = Series :: new ( "not_dst" . into ( ) , [ 2 , 3 , 4 ] ) . into ( ) ;
310
331
let edges = DataFrame :: new ( vec ! [ subjects, objects] ) . unwrap ( ) ;
311
332
match GraphFrame :: new ( vertices, edges) {
312
333
Ok ( _) => panic ! ( "Should have failed" ) ,
0 commit comments