Skip to content

Commit

Permalink
add more type definitions to pd.read_csv to avoid reading errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jgriesfeller committed Aug 25, 2023
1 parent 7a0d763 commit 8fa9884
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pyaerocom/io/read_airnow.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def _read_file(self, file):
encoding=encoding,
on_bad_lines="skip",
# dtype={0: str, 1: str, 2: str, 3: str, 4: float, 5: str, 6: str, 7: float, 8: str},
dtype={2: str, 4: float},
dtype={2: str, 4: float, 7: float},
)
except UnicodeDecodeError:
encoding = "cp863"
Expand All @@ -315,7 +315,7 @@ def _read_file(self, file):
encoding=encoding,
on_bad_lines="skip",
# dtype={0: str, 1: str, 2: str, 3: str, 4: float, 5: str, 6: str, 7: float, 8: str},
dtype={2: str, 4: float},
dtype={2: str, 4: float, 7: float},
)
except:
encoding = self.get_file_encoding(file)
Expand All @@ -326,7 +326,11 @@ def _read_file(self, file):
encoding=encoding,
on_bad_lines="skip",
# dtype={0: str, 1: str, 2: str, 3: str, 4: float, 5: str, 6: str, 7: float, 8: str},
dtype={2: str, 4: float},
dtype={
2: str,
4: float,
7: float,
},
)
return df

Expand Down Expand Up @@ -364,7 +368,7 @@ def _read_files(self, files, vars_to_retrieve):
unique_stat_ids = None
for i in tqdm(range(len(files))):
fp = files[i]
# print(fp)
print(fp)
if read_flag == 1:
filedata = self._read_file(fp)
for i, filevar in enumerate(file_vars_to_retrieve):
Expand Down

0 comments on commit 8fa9884

Please sign in to comment.