@@ -2,21 +2,20 @@ use std::{
22 collections:: HashMap ,
33 fmt,
44 ops:: { Deref , DerefMut } ,
5- sync:: Arc ,
65} ;
76
87use anndata:: {
98 backend:: DataType ,
109 container:: { Axis , Dim } ,
11- data:: { DataFrameIndex , DynArray , DynCscMatrix , DynCsrMatrix , SelectInfoElem , Shape } ,
12- ArrayData , ArrayOp , Data , HasShape , WriteData ,
10+ data:: { DataFrameIndex , DynArray , DynCscMatrix , DynCsrMatrix , Element , SelectInfoElem , Shape } ,
11+ ArrayData , Data , HasShape , Selectable ,
1312} ;
14- use anyhow:: { anyhow , bail} ;
13+ use anyhow:: bail;
1514
1615use ndarray:: Array2 ;
1716use polars:: {
1817 frame:: DataFrame ,
19- prelude:: { IdxCa , NamedFrom } ,
18+ prelude:: { Column , IdxCa , NamedFrom } ,
2019 series:: Series ,
2120} ;
2221
@@ -68,14 +67,14 @@ impl IMArrayElement {
6867 pub fn convert_matrix_format ( & self ) -> anyhow:: Result < ( ) > {
6968 let mut write_guard = self . 0 . write_inner ( ) ;
7069 let d = write_guard. deref_mut ( ) ;
71-
70+
7271 // Create a placeholder that we can swap with - use an empty dense array as it's likely the smallest
7372 let ddata: Array2 < f64 > = Array2 :: zeros ( ( 0 , 0 ) ) ;
7473 let placeholder = ArrayData :: Array ( DynArray :: from ( ddata) ) ;
75-
74+
7675 // Take ownership using replace
7776 let matrix_data = std:: mem:: replace ( d, placeholder) ;
78-
77+
7978 let converted = match matrix_data {
8079 ArrayData :: CsrMatrix ( dyn_csr_matrix) => {
8180 let csc = match dyn_csr_matrix {
@@ -91,7 +90,6 @@ impl IMArrayElement {
9190 DynCsrMatrix :: U8 ( m) => DynCscMatrix :: U8 ( m. transpose_as_csc ( ) ) ,
9291 DynCsrMatrix :: Bool ( m) => DynCscMatrix :: Bool ( m. transpose_as_csc ( ) ) ,
9392 DynCsrMatrix :: String ( m) => DynCscMatrix :: String ( m. transpose_as_csc ( ) ) ,
94- DynCsrMatrix :: Usize ( m) => DynCscMatrix :: Usize ( m. transpose_as_csc ( ) ) ,
9593 } ;
9694 ArrayData :: CscMatrix ( csc)
9795 }
@@ -109,7 +107,6 @@ impl IMArrayElement {
109107 DynCscMatrix :: U8 ( m) => DynCsrMatrix :: U8 ( m. transpose_as_csr ( ) ) ,
110108 DynCscMatrix :: Bool ( m) => DynCsrMatrix :: Bool ( m. transpose_as_csr ( ) ) ,
111109 DynCscMatrix :: String ( m) => DynCsrMatrix :: String ( m. transpose_as_csr ( ) ) ,
112- DynCscMatrix :: Usize ( m) => DynCsrMatrix :: Usize ( m. transpose_as_csr ( ) ) ,
113110 } ;
114111 ArrayData :: CsrMatrix ( csr)
115112 }
@@ -119,7 +116,7 @@ impl IMArrayElement {
119116 bail ! ( "This datatype is not supported, only CSC and CSR matrices are supported." )
120117 }
121118 } ;
122-
119+
123120 * d = converted;
124121 Ok ( ( ) )
125122 }
@@ -182,7 +179,8 @@ impl IMDataFrameElement {
182179 pub fn new ( df : DataFrame , index : DataFrameIndex ) -> Self {
183180 if df. height ( ) == 0 {
184181 let tmp_df =
185- DataFrame :: new ( vec ! [ Series :: new( "index" , & index. clone( ) . into_vec( ) ) ] ) . unwrap ( ) ;
182+ DataFrame :: new ( vec ! [ Column :: new( "index" . into( ) , & index. clone( ) . into_vec( ) ) ] )
183+ . unwrap ( ) ;
186184 return IMDataFrameElement ( RwSlot :: new ( InnerIMDataFrame { df : tmp_df, index } ) ) ;
187185 }
188186 if df. height ( ) != index. len ( ) {
@@ -282,12 +280,12 @@ impl IMDataFrameElement {
282280 }
283281 }
284282
285- pub fn get_column_from_df ( & self , column_name : & str ) -> anyhow:: Result < Series > {
283+ pub fn get_column_from_df ( & self , column_name : & str ) -> anyhow:: Result < Column > {
286284 let read_guard = self . 0 . lock_read ( ) ;
287285 let d = read_guard. as_ref ( ) ;
288286 match d {
289287 Some ( data) => match data. df . column ( column_name) {
290- Ok ( series ) => Ok ( series . clone ( ) ) ,
288+ Ok ( column ) => Ok ( column . clone ( ) ) ,
291289 Err ( e) => Err ( anyhow:: anyhow!( "Column not found: {}" , e) ) ,
292290 } ,
293291 None => Err ( anyhow:: anyhow!( "DataFrame is not initialized" ) ) ,
@@ -311,7 +309,7 @@ impl IMDataFrameElement {
311309 let d = read_guard. as_ref ( ) . unwrap ( ) ;
312310 let indices = crate :: utils:: select_info_elem_to_indices ( s, d. index . len ( ) ) ?;
313311 let indices_u32: Vec < u32 > = indices. iter ( ) . map ( |& i| i as u32 ) . collect ( ) ;
314- let idx = IdxCa :: new ( "idx" , & indices_u32) ;
312+ let idx = IdxCa :: new ( "idx" . into ( ) , & indices_u32) ;
315313 let ind = d. index . clone ( ) . into_vec ( ) ;
316314 let ind_subset: Vec < String > = indices. iter ( ) . map ( |& i| ind[ i] . clone ( ) ) . collect ( ) ;
317315 let df_subset = d. df . take ( & idx) ?;
@@ -324,7 +322,7 @@ impl IMDataFrameElement {
324322 let d = read_guard. as_ref ( ) . unwrap ( ) ;
325323 let indices = crate :: utils:: select_info_elem_to_indices ( s, d. index . len ( ) ) ?;
326324 let indices_u32: Vec < u32 > = indices. iter ( ) . map ( |& i| i as u32 ) . collect ( ) ;
327- let idx = IdxCa :: new ( "idx" , & indices_u32) ;
325+ let idx = IdxCa :: new ( "idx" . into ( ) , & indices_u32) ;
328326 let ind = d. index . clone ( ) . into_vec ( ) ;
329327 let ind_subset: Vec < String > = indices. iter ( ) . map ( |& i| ind[ i] . clone ( ) ) . collect ( ) ;
330328 let df_subset = d. df . take ( & idx) ?;
@@ -620,29 +618,29 @@ impl IMAxisArrays {
620618 }
621619}
622620
623- pub struct Element ( pub RwSlot < Data > ) ;
621+ pub struct IMElement ( pub RwSlot < Data > ) ;
624622
625623impl DeepClone for Data {
626624 fn deep_clone ( & self ) -> Self {
627625 self . clone ( )
628626 }
629627}
630628
631- impl DeepClone for Element {
629+ impl DeepClone for IMElement {
632630 fn deep_clone ( & self ) -> Self {
633- Element ( self . 0 . deep_clone ( ) )
631+ IMElement ( self . 0 . deep_clone ( ) )
634632 }
635633}
636634
637- impl Clone for Element {
635+ impl Clone for IMElement {
638636 fn clone ( & self ) -> Self {
639- Element ( self . 0 . clone ( ) )
637+ IMElement ( self . 0 . clone ( ) )
640638 }
641639}
642640
643- impl Element {
641+ impl IMElement {
644642 pub fn new ( data : Data ) -> Self {
645- Element ( RwSlot :: new ( data) )
643+ IMElement ( RwSlot :: new ( data) )
646644 }
647645
648646 pub fn get_data ( & self ) -> anyhow:: Result < Data > {
@@ -657,7 +655,7 @@ impl Element {
657655 }
658656}
659657
660- pub struct IMElementCollection ( pub RwSlot < HashMap < String , Element > > ) ;
658+ pub struct IMElementCollection ( pub RwSlot < HashMap < String , IMElement > > ) ;
661659
662660impl DeepClone for IMElementCollection {
663661 fn deep_clone ( & self ) -> Self {
@@ -682,7 +680,7 @@ impl IMElementCollection {
682680 IMElementCollection ( RwSlot :: new ( HashMap :: new ( ) ) )
683681 }
684682
685- pub fn add_data ( & self , key : String , element : Element ) -> anyhow:: Result < ( ) > {
683+ pub fn add_data ( & self , key : String , element : IMElement ) -> anyhow:: Result < ( ) > {
686684 let mut write_guard = self . 0 . write_inner ( ) ;
687685 let collection = write_guard. deref_mut ( ) ;
688686 if collection. contains_key ( & key) {
@@ -692,22 +690,22 @@ impl IMElementCollection {
692690 Ok ( ( ) )
693691 }
694692
695- pub fn remove_data ( & self , key : & str ) -> anyhow:: Result < Element > {
693+ pub fn remove_data ( & self , key : & str ) -> anyhow:: Result < IMElement > {
696694 let mut write_guard = self . 0 . write_inner ( ) ;
697695 write_guard
698696 . remove ( key)
699697 . ok_or_else ( || anyhow:: anyhow!( "Key not found" ) )
700698 }
701699
702- pub fn get_data ( & self , key : & str ) -> anyhow:: Result < Element > {
700+ pub fn get_data ( & self , key : & str ) -> anyhow:: Result < IMElement > {
703701 let read_guard = self . 0 . read_inner ( ) ;
704702 read_guard
705703 . get ( key)
706704 . cloned ( )
707705 . ok_or_else ( || anyhow:: anyhow!( "Key not found" ) )
708706 }
709707
710- pub fn get_data_deep ( & self , key : & str ) -> anyhow:: Result < Element > {
708+ pub fn get_data_deep ( & self , key : & str ) -> anyhow:: Result < IMElement > {
711709 let read_guard = self . 0 . read_inner ( ) ;
712710 read_guard
713711 . get ( key)
0 commit comments