11"""Contains class for saving and loading spreadsheet data."""
2+
23from io import BytesIO , StringIO
3- from typing import Any , Dict , List , Optional , Union
4+ from typing import Any , Optional , Union
45
56import fastavro
67
@@ -20,7 +21,7 @@ def __init__(
2021 self ,
2122 input_file_path : Optional [str ] = None ,
2223 data : Optional [Any ] = None ,
23- options : Optional [Dict ] = None ,
24+ options : Optional [dict ] = None ,
2425 ) -> None :
2526 """
2627 Initialize Data class for loading datasets of type AVRO.
@@ -60,22 +61,22 @@ def file_encoding(self, value: Any) -> None:
6061 """
6162 pass
6263
63- def _load_data_from_file (self , input_file_path : str ) -> List :
64+ def _load_data_from_file (self , input_file_path : str ) -> list :
6465 """Load data from file."""
6566 with FileOrBufferHandler (input_file_path , "rb" ) as input_file :
6667 # Currently, string reading with 'r' option has the unicode issue,
6768 # even when the option encoding='utf-8' is added. It may come from
6869 # some special compression codec, e.g., snappy. Then, binary mode
6970 # reading is currently used to get the dict-formatted lines.
7071 df_reader = fastavro .reader (input_file )
71- lines : List = list ()
72+ lines : list = list ()
7273 for line in df_reader :
7374 lines .append (line )
7475 return lines
7576
7677 @classmethod
7778 def is_match (
78- cls , file_path : Union [str , StringIO , BytesIO ], options : Optional [Dict ] = None
79+ cls , file_path : Union [str , StringIO , BytesIO ], options : Optional [dict ] = None
7980 ) -> bool :
8081 """
8182 Test the given file to check if the file has valid AVRO format or not.
@@ -103,7 +104,7 @@ def is_match(
103104 return is_valid_avro
104105
105106 @classmethod
106- def _get_nested_key (cls , dict_line : Dict , nested_key : Dict ) -> Dict :
107+ def _get_nested_key (cls , dict_line : dict , nested_key : dict ) -> dict :
107108 """
108109 Update nested keys from a dictionary and the current nested key.
109110
@@ -131,7 +132,7 @@ def _get_nested_key(cls, dict_line: Dict, nested_key: Dict) -> Dict:
131132 return nested_key
132133
133134 @classmethod
134- def _get_nested_keys_from_dicts (cls , dicts : List [ Dict ]) -> Dict :
135+ def _get_nested_keys_from_dicts (cls , dicts : list [ dict ]) -> dict :
135136 """
136137 Extract nested keys from a list of dictionaries.
137138
@@ -143,13 +144,13 @@ def _get_nested_keys_from_dicts(cls, dicts: List[Dict]) -> Dict:
143144 :type dicts: list(dict)
144145 :return: a dictionary containing nested keys
145146 """
146- nested_keys : Dict = {}
147+ nested_keys : dict = {}
147148 for dict_line in dicts :
148149 nested_keys = cls ._get_nested_key (dict_line , nested_keys )
149150 return nested_keys
150151
151152 @classmethod
152- def _get_schema_avro (cls , nested_keys : Dict , schema_avro : Dict ) -> Dict :
153+ def _get_schema_avro (cls , nested_keys : dict , schema_avro : dict ) -> dict :
153154 """
154155 Update avro schema from the nested keys and the current avro schema.
155156
@@ -190,7 +191,7 @@ def _get_schema_avro(cls, nested_keys: Dict, schema_avro: Dict) -> Dict:
190191 if type (value ) is dict :
191192 # here, the null option to specify keys not required
192193 # for every lines
193- schema_avro_temp : Dict [str , Any ] = {
194+ schema_avro_temp : dict [str , Any ] = {
194195 "name" : key ,
195196 "type" : [{"name" : key , "type" : "record" , "fields" : []}, "null" ],
196197 }
0 commit comments