2929import ifcopenshell .util .element
3030import ifcopenshell .util .schema
3131from statistics import mean
32+ from typing import Optional , Union
3233
3334try :
3435 from odf .namespaces import OFFICENS
@@ -269,7 +270,7 @@ def natural_sort(value):
269270 elif not include_global_id :
270271 self .results = sorted (self .results , key = lambda x : x [0 ])
271272
272- def export_csv (self , output , delimiter = None ):
273+ def export_csv (self , output : str , delimiter : Optional [ str ] = None ) -> None :
273274 with open (output , "w" , newline = "" , encoding = "utf-8" ) as f :
274275 writer = csv .writer (f , delimiter = delimiter )
275276 writer .writerow (self .headers )
@@ -387,8 +388,16 @@ def Import(
387388 self .import_xlsx (ifc_file , table , attributes , null , empty , bool_true , bool_false )
388389
389390 def import_csv (
390- self , ifc_file , table , attributes = None , delimiter = "," , null = "-" , empty = "" , bool_true = "YES" , bool_false = "NO"
391- ):
391+ self ,
392+ ifc_file : ifcopenshell .file ,
393+ table : str ,
394+ attributes : Optional [list [Union [str , None ]]] = None ,
395+ delimiter : str = "," ,
396+ null : str = "-" ,
397+ empty : str = "" ,
398+ bool_true : str = "YES" ,
399+ bool_false : str = "NO" ,
400+ ) -> None :
392401 with open (table , newline = "" , encoding = "utf-8" ) as f :
393402 reader = csv .reader (f , delimiter = delimiter )
394403 headers = []
@@ -421,7 +430,17 @@ def import_pd(self, ifc_file, df, attributes=None, null="-", empty="", bool_true
421430 for _ , row in df .iterrows ():
422431 self .process_row (ifc_file , row .tolist (), headers , attributes , null , empty , bool_true , bool_false )
423432
424- def process_row (self , ifc_file , row , headers , attributes , null , empty , bool_true , bool_false ):
433+ def process_row (
434+ self ,
435+ ifc_file : ifcopenshell .file ,
436+ row : list [str ],
437+ headers : list [str ],
438+ attributes : list [Union [str , None ]],
439+ null : str ,
440+ empty : str ,
441+ bool_true : str ,
442+ bool_false : str ,
443+ ) -> None :
425444 try :
426445 element = ifc_file .by_guid (row [0 ])
427446 except :
@@ -448,9 +467,7 @@ def process_row(self, ifc_file, row, headers, attributes, null, empty, bool_true
448467 parser .add_argument ("-s" , "--spreadsheet" , type = str , default = "data.csv" , help = "The spreadsheet file" )
449468 parser .add_argument ("-f" , "--format" , type = str , default = "csv" , help = "The format, chosen from csv, ods, or xlsx" )
450469 parser .add_argument ("-d" , "--delimiter" , type = str , default = "," , help = "The delimiter in CSV. Defaults to a comma." )
451- parser .add_argument (
452- "-n" , "--null" , type = str , default = "N/A" , help = "How to represent null values. Defaults to N/A."
453- )
470+ parser .add_argument ("-n" , "--null" , type = str , default = "N/A" , help = "How to represent null values. Defaults to N/A." )
454471 parser .add_argument (
455472 "-e" , "--empty" , type = str , default = "-" , help = "How to represent empty strings. Defaults to a hyphen."
456473 )
0 commit comments