Skip to content

Commit c1d8db8

Browse files
committed
mypy: more checks with pandas-stubs
1 parent 76ec941 commit c1d8db8

File tree

6 files changed

+20
-20
lines changed

6 files changed

+20
-20
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ module = [
6161
"h5py.*",
6262
"matplotlib.*",
6363
"mpl_toolkits.*",
64-
"pandas.*",
6564
"pytest.*",
6665
"scipy.*",
6766
]

stagpy/_step.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ def _rprofs(self) -> DataFrame:
501501
def __getitem__(self, name: str) -> Rprof:
502502
step = self.step
503503
if name in self._rprofs.columns:
504-
rprof = self._rprofs[name].values
504+
rprof = self._rprofs[name].to_numpy()
505505
rad = self.centers
506506
if name in phyvars.RPROF:
507507
meta = phyvars.RPROF[name]
@@ -533,7 +533,7 @@ def stepstr(self) -> str:
533533
@cached_property
534534
def centers(self) -> ndarray:
535535
"""Radial position of cell centers."""
536-
return self._rprofs["r"].values + self.bounds[0]
536+
return self._rprofs["r"].to_numpy() + self.bounds[0]
537537

538538
@cached_property
539539
def walls(self) -> ndarray:

stagpy/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def info_cmd() -> None:
7171
pandas.Series(data=dimensions, index=series.index, name="dim"),
7272
],
7373
axis=1,
74-
)
74+
) # type: ignore
7575
print(indent(series.to_string(header=False), " "))
7676
print()
7777

stagpy/stagyydata.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def _tseries(self) -> DataFrame:
257257

258258
def __getitem__(self, name: str) -> Tseries:
259259
if name in self._tseries.columns:
260-
series = self._tseries[name].values
260+
series = self._tseries[name].to_numpy()
261261
time = self.time
262262
if name in phyvars.TIME:
263263
meta = phyvars.TIME[name]
@@ -308,7 +308,7 @@ def tslice(
308308
@property
309309
def time(self) -> ndarray:
310310
"""Time vector."""
311-
return self._tseries["t"].values
311+
return self._tseries["t"].to_numpy()
312312

313313
@property
314314
def isteps(self) -> ndarray:
@@ -320,7 +320,7 @@ def isteps(self) -> ndarray:
320320

321321
def at_step(self, istep: int) -> Series:
322322
"""Time series output for a given step."""
323-
return self._tseries.loc[istep]
323+
return self._tseries.loc[istep] # type: ignore
324324

325325

326326
class _RprofsAveraged(_step._Rprofs):
@@ -816,7 +816,7 @@ def _rprof_and_times(self) -> Tuple[Dict[int, DataFrame], Optional[DataFrame]]:
816816
return stagyyparsers.rprof(rproffile, list(phyvars.RPROF.keys()))
817817

818818
@property
819-
def rtimes(self) -> DataFrame:
819+
def rtimes(self) -> Optional[DataFrame]:
820820
"""Radial profiles times."""
821821
return self._rprof_and_times[1]
822822

stagpy/stagyyparsers.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def time_series(timefile: Path, colnames: List[str]) -> Optional[DataFrame]:
8080
memory_map=True,
8181
on_bad_lines="skip",
8282
)
83-
data = data.apply(pd.to_numeric, raw=True, errors="coerce")
83+
data = data.apply(pd.to_numeric, raw=True, errors="coerce") # type: ignore
8484

8585
# detect useless lines produced when run is restarted
8686
rows_to_del = []
@@ -97,7 +97,7 @@ def time_series(timefile: Path, colnames: List[str]) -> Optional[DataFrame]:
9797

9898
ncols = data.shape[1]
9999
_tidy_names(colnames, ncols)
100-
data.columns = colnames
100+
data.columns = pd.Index(colnames)
101101

102102
return data
103103

@@ -126,7 +126,7 @@ def time_series_h5(timefile: Path, colnames: List[str]) -> Optional[DataFrame]:
126126
h5names = h5f["names"].asstr()[len(colnames) + 1 :]
127127
_tidy_names(colnames, ncols, h5names)
128128
data = dset[()]
129-
pdf = pd.DataFrame(data[:, 1:], index=np.int_(data[:, 0]), columns=colnames)
129+
pdf = pd.DataFrame(data[:, 1:], index=data[:, 0].astype(np.int64), columns=colnames)
130130
# remove duplicated lines in case of restart
131131
return pdf.loc[~pdf.index.duplicated(keep="last")]
132132

@@ -198,22 +198,22 @@ def rprof(
198198
memory_map=True,
199199
on_bad_lines="skip",
200200
)
201-
data = data.apply(pd.to_numeric, raw=True, errors="coerce")
201+
data = data.apply(pd.to_numeric, raw=True, errors="coerce") # type: ignore
202202

203203
isteps = _extract_rsnap_isteps(rproffile, data)
204204

205-
data = {}
205+
all_data = {}
206206
for istep, _, step_df in isteps:
207-
step_df.index = range(step_df.shape[0]) # check whether necessary
207+
step_df.index = pd.RangeIndex(step_df.shape[0]) # check whether necessary
208208
step_cols = list(colnames)
209209
_tidy_names(step_cols, step_df.shape[1])
210-
step_df.columns = step_cols
211-
data[istep] = step_df
210+
step_df.columns = pd.Index(step_cols)
211+
all_data[istep] = step_df
212212

213213
df_times = pd.DataFrame(
214-
list(map(itemgetter(1), isteps)), index=map(itemgetter(0), isteps)
214+
list(map(itemgetter(1), isteps)), index=pd.Index(map(itemgetter(0), isteps))
215215
)
216-
return data, df_times
216+
return all_data, df_times
217217

218218

219219
def rprof_h5(
@@ -250,7 +250,7 @@ def rprof_h5(
250250
isteps.append((istep, dset.attrs["time"]))
251251

252252
df_times = pd.DataFrame(
253-
list(map(itemgetter(1), isteps)), index=map(itemgetter(0), isteps)
253+
list(map(itemgetter(1), isteps)), index=pd.Index(map(itemgetter(0), isteps))
254254
)
255255
return data, df_times
256256

@@ -297,7 +297,7 @@ def refstate(
297297
memory_map=True,
298298
on_bad_lines="skip",
299299
)
300-
data = data.apply(pd.to_numeric, raw=True, errors="coerce")
300+
data = data.apply(pd.to_numeric, raw=True, errors="coerce") # type: ignore
301301
# drop lines corresponding to metadata
302302
data.dropna(subset=[0], inplace=True)
303303
isystem = -1

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ setenv = STAGPY_ISOLATED=True
2222
[testenv:mypy]
2323
deps =
2424
mypy>=1.9.0
25+
pandas-stubs>=2.0.3.230814
2526
commands=
2627
mypy --install-types --non-interactive stagpy/ tests/
2728

0 commit comments

Comments
 (0)