@@ -260,7 +260,7 @@ def add_metadata(
260260 self ,
261261 metadata : Union [str , pd .DataFrame ],
262262 index_col : Optional [Union [int , str ]] = 0 ,
263- delimiter : Optional [str ] = "\t " ,
263+ delimiter : Optional [str ] = ", " ,
264264 columns : Optional [List [str ]] = None ,
265265 tree_level : Optional [str ] = "parent" ,
266266 ignore_mismatch : Optional [bool ] = False ,
@@ -271,7 +271,7 @@ def add_metadata(
271271 Parameters
272272 ----------
273273 metadata : str or pandas.DataFrame
274- Path to a ``csv``, ``xls`` or ``xlsx`` file or a pandas DataFrame that contains the metadata information.
274+ Path to a ``csv`` (or similar) , ``xls`` or ``xlsx`` file or a pandas DataFrame that contains the metadata information.
275275 index_col : int or str, optional
276276 Column to use as the index when reading the file and converting into a panda.DataFrame.
277277 Accepts column indices or column names.
@@ -280,7 +280,7 @@ def add_metadata(
280280 Only used if a file path is provided as the ``metadata`` parameter.
281281 Ignored if ``columns`` parameter is passed.
282282 delimiter : str, optional
283- Delimiter used in the ``csv`` file, by default ``"\t "``.
283+ Delimiter used in the ``csv`` file, by default ``", "``.
284284
285285 Only used if a ``csv`` file path is provided as
286286 the ``metadata`` parameter.
@@ -323,31 +323,32 @@ def add_metadata(
323323
324324 else : #if not df
325325 if os .path .isfile (metadata ):
326- if metadata .endswith ('csv' ):
326+ if metadata .endswith (( 'xls' , 'xlsx' ) ):
327327 if columns :
328- metadata_df = pd .read_csv (
329- metadata , usecols = columns , delimiter = delimiter
328+ metadata_df = pd .read_excel (
329+ metadata , usecols = columns ,
330330 )
331331 else :
332- metadata_df = pd .read_csv (
333- metadata , index_col = index_col , delimiter = delimiter
332+ metadata_df = pd .read_excel (
333+ metadata , index_col = index_col ,
334334 )
335335 columns = list (metadata_df .columns )
336-
337- elif metadata .endswith (( 'xls' , 'xlsx' )):
336+
337+ elif metadata .endswith ('sv' ): #csv, tsv, etc
338338 if columns :
339- metadata_df = pd .read_excel (
340- metadata , usecols = columns ,
339+ metadata_df = pd .read_csv (
340+ metadata , usecols = columns , delimiter = delimiter
341341 )
342342 else :
343- metadata_df = pd .read_excel (
344- metadata , index_col = index_col ,
343+ metadata_df = pd .read_csv (
344+ metadata , index_col = index_col , delimiter = delimiter
345345 )
346346 columns = list (metadata_df .columns )
347+
347348
348349 else :
349350 raise ValueError (
350- "[ERROR] ``metadata`` should either be the path to a ``csv``, ``xls`` or ``xlsx`` file or a pandas DataFrame." # noqa
351+ "[ERROR] ``metadata`` should either be the path to a ``csv`` (or similar) , ``xls`` or ``xlsx`` file or a pandas DataFrame." # noqa
351352 )
352353
353354 # identify image_id column
@@ -1225,7 +1226,12 @@ def calc_pixel_stats(
12251226 # Calculate std pixel values
12261227 self .patches [patch ][f"std_pixel_{ band } " ] = img_std [i ] / 255
12271228
1228- def convert_images (self , save : Optional [bool ] = False , save_format : Optional [str ] = "csv" ) -> Tuple [pd .DataFrame , pd .DataFrame ]:
1229+ def convert_images (
1230+ self ,
1231+ save : Optional [bool ] = False ,
1232+ save_format : Optional [str ] = "csv" ,
1233+ delimiter : Optional [str ]= "," ,
1234+ ) -> Tuple [pd .DataFrame , pd .DataFrame ]:
12291235 """
12301236 Convert the ``MapImages`` instance's ``images`` dictionary into pandas
12311237 DataFrames for easy manipulation.
@@ -1239,6 +1245,8 @@ def convert_images(self, save: Optional[bool] = False, save_format: Optional[str
12391245 If ``save = True``, the file format to use when saving the dataframes.
12401246 Options of csv ("csv") or excel ("excel" or "xlsx").
12411247 By default, "csv".
1248+ delimiter : str, optional
1249+ The delimiter to use when saving the dataframe. By default ``","``.
12421250
12431251 Returns
12441252 -------
@@ -1255,9 +1263,9 @@ def convert_images(self, save: Optional[bool] = False, save_format: Optional[str
12551263 if save :
12561264
12571265 if save_format == "csv" :
1258- parent_df .to_csv ("parent_df.csv" , sep = " \t " )
1266+ parent_df .to_csv ("parent_df.csv" , sep = delimiter )
12591267 print ('[INFO] Saved parent dataframe as "parent_df.csv"' )
1260- patch_df .to_csv ("patch_df.csv" , sep = " \t " )
1268+ patch_df .to_csv ("patch_df.csv" , sep = delimiter )
12611269 print ('[INFO] Saved patch dataframe as "patch_df.csv"' )
12621270 elif save_format in ["excel" , "xlsx" ]:
12631271 parent_df .to_excel ("parent_df.xlsx" )
@@ -1872,6 +1880,7 @@ def load_csv(
18721880 clear_images : Optional [bool ] = False ,
18731881 index_col_patch : Optional [int ] = 0 ,
18741882 index_col_parent : Optional [int ] = 0 ,
1883+ delimiter : Optional [str ] = "," ,
18751884 ) -> None :
18761885 """
18771886 Load CSV files containing information about parent and patches,
@@ -1891,6 +1900,8 @@ def load_csv(
18911900 Column to set as index for the patch DataFrame, by default ``0``.
18921901 index_col_parent : int, optional
18931902 Column to set as index for the parent DataFrame, by default ``0``.
1903+ delimiter : str, optional
1904+ The delimiter to use when reading the dataframe. By default ``","``.
18941905
18951906 Returns
18961907 -------
@@ -1905,12 +1916,12 @@ def load_csv(
19051916 raise ValueError ("[ERROR] Please pass ``patch_path`` as string." )
19061917
19071918 if os .path .isfile (parent_path ):
1908- parent_df = pd .read_csv (parent_path , index_col = index_col_parent )
1919+ parent_df = pd .read_csv (parent_path , index_col = index_col_parent , sep = delimiter )
19091920 else :
19101921 raise ValueError (f"[ERROR] { parent_path } cannot be found." )
19111922
19121923 if os .path .isfile (patch_path ):
1913- patch_df = pd .read_csv (patch_path , index_col = index_col_patch )
1924+ patch_df = pd .read_csv (patch_path , index_col = index_col_patch , sep = delimiter )
19141925 else :
19151926 raise ValueError (f"[ERROR] { patch_path } cannot be found." )
19161927
0 commit comments