22
33import logging
44import pathlib
5+ import typing
56
67import pandas as pd
78
@@ -133,7 +134,7 @@ def read_file(self) -> pd.DataFrame:
133134 try :
134135 df = pd .read_fwf (
135136 self .filename ,
136- colspecs = self .column_limits ,
137+ colspecs = typing . cast ( typing . Sequence [ tuple [ int , int ]], self .column_limits ), # appease mypy
137138 names = self ._column_names (),
138139 na_values = self ._na_values (),
139140 keep_default_na = False ,
@@ -155,16 +156,13 @@ def read_file(self) -> pd.DataFrame:
155156 df = df .drop (columns = ["State" , "IsomerEnergy" , "IsomerEnergyError" ])
156157
157158 # Convert stable isotopes into ones with enormous lifetimes with zero error so we can cast
158- df .loc [df ["HalfLifeValue" ] == "stbl" , ["HalfLifeValue" , "HalfLifeUnit" , "HalfLifeError" ]] = [
159- 99.99 ,
160- "Zy" ,
161- 0.0 ,
162- ]
159+ mask = df ["HalfLifeValue" ] == "stbl"
160+ df .loc [mask , ["HalfLifeValue" , "HalfLifeUnit" , "HalfLifeError" ]] = (99.99 , "Zy" , 0.0 )
163161
164162 df ["HalfLifeValue" ] = df ["HalfLifeValue" ].astype ("string" ).str .replace (r"[<>?~]" , "" , regex = True )
165163 # We'll be lazy here and remove any characters in this column. Future us will parse this properly
166164 df ["HalfLifeError" ] = df ["HalfLifeError" ].astype ("string" ).str .replace (r"[<>?~a-z]" , "" , regex = True )
167-
168- return df .astype (self ._data_types ())
169165 except ValueError as e :
170166 print (f"Parsing error: { e } " )
167+
168+ return df .astype (self ._data_types ())
0 commit comments