@@ -28,15 +28,12 @@ fn _parse_cell_text(cell_str: &str) -> String {
2828fn _get_header_rows ( sheet : & spreadsheet_ods:: Sheet ) -> Vec < String > {
2929 let mut header: Vec < String > = Vec :: new ( ) ;
3030 let mut col_idx = 0 ;
31- loop {
32- if let Some ( cell) = sheet. cell ( 0 , col_idx) {
33- let cell_str = format ! ( "{:?}" , cell) ;
34- let name = _parse_cell_text ( & cell_str) ;
35- header. push ( name) ;
36- col_idx += 1 ;
37- } else {
38- break ;
39- }
31+
32+ while let Some ( cell) = sheet. cell ( 0 , col_idx) {
33+ let cell_str = format ! ( "{cell:?}" ) ;
34+ let name = _parse_cell_text ( & cell_str) ;
35+ header. push ( name) ;
36+ col_idx += 1 ;
4037 }
4138
4239 header
@@ -57,7 +54,7 @@ pub fn get_indices_names_hashmap(
5754 let header = _get_header_rows ( sheet) ;
5855
5956 // Always include the first column (index 0)
60- if let Some ( first_col_name) = header. get ( 0 ) {
57+ if let Some ( first_col_name) = header. first ( ) {
6158 indices. insert ( 0 , ( first_col_name. clone ( ) , first_col_name. clone ( ) ) ) ;
6259 }
6360
@@ -81,7 +78,7 @@ pub fn get_indices_names_hashmap(
8178 }
8279 if !found {
8380 return Err ( PolarsError :: ComputeError (
84- format ! ( "Column '{}' not found in sheet header" , col_name ) . into ( ) ,
81+ format ! ( "Column '{col_name }' not found in sheet header" ) . into ( ) ,
8582 ) ) ;
8683 }
8784 }
@@ -91,7 +88,7 @@ pub fn get_indices_names_hashmap(
9188
9289pub fn get_sheet_by_name ( sheet_name : & str ) -> PolarsResult < Sheet > {
9390 let doc = read_ods ( "src/assumptions/assumptions.ods" )
94- . map_err ( |e| PolarsError :: ComputeError ( format ! ( "Failed to read ODS file: {}" , e ) . into ( ) ) ) ?;
91+ . map_err ( |e| PolarsError :: ComputeError ( format ! ( "Failed to read ODS file: {e}" ) . into ( ) ) ) ?;
9592
9693 for idx in 0 ..doc. num_sheets ( ) {
9794 let wsh = doc. sheet ( idx) ;
@@ -101,7 +98,7 @@ pub fn get_sheet_by_name(sheet_name: &str) -> PolarsResult<Sheet> {
10198 }
10299
103100 Err ( PolarsError :: ComputeError (
104- format ! ( "Sheet '{}' not found" , sheet_name ) . into ( ) ,
101+ format ! ( "Sheet '{sheet_name }' not found" ) . into ( ) ,
105102 ) )
106103}
107104
@@ -115,23 +112,21 @@ pub fn parse_col_by_index_to_f64(
115112 let mut row_idx = 1 ; // Skip header
116113
117114 let mut col_data = Vec :: new ( ) ;
118- loop {
119- if let Some ( cell_content) = sheet. cell ( row_idx, col_idx as u32 ) {
120- let cell_str = format ! ( "{:?}" , cell_content) ;
121-
122- let val = if cell_str. contains ( "Number(" ) {
123- let start = cell_str. find ( "Number(" ) . unwrap_or ( 0 ) + 7 ;
124- let end = cell_str. rfind ( ")" ) . unwrap_or ( cell_str. len ( ) ) ;
125- cell_str[ start..end] . parse :: < f64 > ( ) . unwrap_or ( 0.0 )
126- } else {
127- 0.0
128- } ;
129- col_data. push ( val) ;
130- row_idx += 1 ;
115+
116+ while let Some ( cell_content) = sheet. cell ( row_idx, col_idx as u32 ) {
117+ let cell_str = format ! ( "{cell_content:?}" ) ;
118+
119+ let val = if cell_str. contains ( "Number(" ) {
120+ let start = cell_str. find ( "Number(" ) . unwrap_or ( 0 ) + 7 ;
121+ let end = cell_str. rfind ( ")" ) . unwrap_or ( cell_str. len ( ) ) ;
122+ cell_str[ start..end] . parse :: < f64 > ( ) . unwrap_or ( 0.0 )
131123 } else {
132- break ;
133- }
124+ 0.0
125+ } ;
126+ col_data. push ( val) ;
127+ row_idx += 1 ;
134128 }
129+
135130 Ok ( col_data)
136131}
137132
@@ -146,36 +141,34 @@ pub fn parse_col_by_index_to_string(sheet: &Sheet, col_idx: usize) -> PolarsResu
146141 let mut row_idx = 1 ; // Skip header
147142
148143 let mut col_data = Vec :: new ( ) ;
149- loop {
150- if let Some ( cell_content) = sheet. cell ( row_idx, col_idx as u32 ) {
151- let cell_str = format ! ( "{:?}" , cell_content) ;
152144
153- // Extract the text value from the cell string
154- let val = if cell_str. contains ( "Text(" ) {
155- let start = cell_str. find ( "Text(" ) . unwrap_or ( 0 ) + 5 ;
145+ while let Some ( cell_content) = sheet. cell ( row_idx, col_idx as u32 ) {
146+ let cell_str = format ! ( "{cell_content:?}" ) ;
156147
157- let end = if let Some ( style_pos) = cell_str. find ( "), style:" ) {
158- style_pos
159- } else {
160- cell_str. rfind ( ")" ) . unwrap_or ( cell_str. len ( ) )
161- } ;
162-
163- let extracted = & cell_str[ start..end] ;
148+ // Extract the text value from the cell string
149+ let val = if cell_str. contains ( "Text(" ) {
150+ let start = cell_str. find ( "Text(" ) . unwrap_or ( 0 ) + 5 ;
164151
165- // Remove quotes if present
166- if extracted. starts_with ( '"' ) && extracted. ends_with ( '"' ) {
167- extracted[ 1 ..extracted. len ( ) - 1 ] . to_string ( )
168- } else {
169- extracted. to_string ( )
170- }
152+ let end = if let Some ( style_pos) = cell_str. find ( "), style:" ) {
153+ style_pos
171154 } else {
172- cell_str
155+ cell_str. rfind ( ")" ) . unwrap_or ( cell_str . len ( ) )
173156 } ;
174- col_data. push ( val) ;
175- row_idx += 1 ;
157+
158+ let extracted = & cell_str[ start..end] ;
159+
160+ // Remove quotes if present
161+ if extracted. starts_with ( '"' ) && extracted. ends_with ( '"' ) {
162+ extracted[ 1 ..extracted. len ( ) - 1 ] . to_string ( )
163+ } else {
164+ extracted. to_string ( )
165+ }
176166 } else {
177- break ;
178- }
167+ cell_str
168+ } ;
169+ col_data. push ( val) ;
170+ row_idx += 1 ;
179171 }
172+
180173 Ok ( col_data)
181174}
0 commit comments