Skip to content

Commit 45babc6

Browse files
resolve MyPy type errors to satisfy CI checks
1 parent 10a514f commit 45babc6

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

malariagen_data/anoph/frq_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def plot_frequencies_heatmap(
210210

211211
# Indexing.
212212
if index is None:
213-
index = list(df.index.names)
213+
index = [str(name) for name in df.index.names]
214214
df = df.reset_index().copy()
215215
if isinstance(index, list):
216216
index_col = (

malariagen_data/anoph/sample_metadata.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __init__(
3939
# data resources, and so column names and dtype need to be
4040
# passed in as parameters.
4141
self._aim_metadata_columns: Optional[List[str]] = None
42-
self._aim_metadata_dtype: Dict[str, Any] = dict()
42+
self._aim_metadata_dtype: Dict[str, Union[str, type, np.dtype]] = dict()
4343
if isinstance(aim_metadata_dtype, Mapping):
4444
self._aim_metadata_columns = list(aim_metadata_dtype.keys())
4545
self._aim_metadata_dtype.update(aim_metadata_dtype)
@@ -140,6 +140,16 @@ def _parse_general_metadata(
140140
"longitude": "float64",
141141
"sex_call": "object",
142142
}
143+
# Mapping of string dtypes to actual dtypes
144+
dtype_map = {
145+
"object": str,
146+
"int64": np.int64,
147+
"float64": np.float64,
148+
}
149+
150+
# Convert string dtypes to actual dtypes
151+
dtype = {col: dtype_map.get(dtype[col], str) for col in dtype}
152+
143153
df = pd.read_csv(io.BytesIO(data), dtype=dtype, na_values="")
144154

145155
# Ensure all column names are lower case.

tests/anoph/test_snp_frq.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def test_snp_effects(fixture, api: AnophelesSnpFrequencyAnalysis):
153153

154154
# Check some values.
155155
assert np.all(df["contig"] == transcript["contig"])
156-
position = df["position"].values
156+
position = df["position"].to_numpy()
157157
assert np.all(position >= transcript["start"])
158158
assert np.all(position <= transcript["end"])
159159
assert np.all(position[1:] >= position[:-1])

0 commit comments

Comments
 (0)