Skip to content

Commit

Permalink
Merge pull request #326 from jenshnielsen/pandas_stubs
Browse files Browse the repository at this point in the history
Drop python 3.7 support and Typecheck with Pandas stubs
  • Loading branch information
jenshnielsen committed Sep 21, 2022
2 parents 52e6d48 + fc75ee6 commit a17b024
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, "3.10"]
python-version: ["3.8", "3.9", "3.10"]
env:
DISPLAY: ':99.0'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4.2.0
with:
python-version: '3.7'
python-version: '3.9'
- uses: ./.github/actions/install-dependencies-and-plottr
- name: Install build deps
run: pip install --upgrade build
Expand Down
20 changes: 13 additions & 7 deletions plottr/apps/inspectr.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import sys
import argparse
import logging
from typing import Optional, Sequence, List, Dict, Iterable, Union, cast, Tuple
from typing import Optional, Sequence, List, Dict, Iterable, Union, cast, Tuple, Mapping

from typing_extensions import TypedDict

Expand Down Expand Up @@ -190,7 +190,7 @@ def addRun(self, runId: int, **vals: str) -> None:
item = SortableTreeWidgetItem(lst)
self.addTopLevelItem(item)

def setRuns(self, selection: Dict[int, Dict[str, str]], show_only_star: bool, show_also_cross: bool) -> None:
def setRuns(self, selection: Mapping[int, Mapping[str, str]], show_only_star: bool, show_also_cross: bool) -> None:
self.clear()

# disable sorting before inserting values to avoid performance hit
Expand All @@ -208,7 +208,7 @@ def setRuns(self, selection: Dict[int, Dict[str, str]], show_only_star: bool, sh
for i in range(len(self.cols)):
self.resizeColumnToContents(i)

def updateRuns(self, selection: Dict[int, Dict[str, str]]) -> None:
def updateRuns(self, selection: Mapping[int, Mapping[str, str]]) -> None:

run_added = False
for runId, record in selection.items():
Expand Down Expand Up @@ -494,7 +494,7 @@ def loadFullDB(self, path: Optional[str] = None) -> None:
self.loadDBProcess.setPath(self.filepath)

def DBLoaded(self, dbdf: pandas.DataFrame) -> None:
if dbdf.equals(self.dbdf):
if self.dbdf is not None and dbdf.equals(self.dbdf):
logger().debug('DB reloaded with no changes. Skipping update')
return None
self.dbdf = dbdf
Expand Down Expand Up @@ -553,7 +553,10 @@ def updateRunList(self) -> None:
selection = self.dbdf.loc[self.dbdf['started_date'].isin(self._selected_dates)].sort_index(ascending=False)
show_only_star = self.showOnlyStarAction.isChecked()
show_also_cross = self.showAlsoCrossAction.isChecked()
self.runList.setRuns(selection.to_dict(orient='index'), show_only_star, show_also_cross)
# Pandas types cannot infer that this dataframe will be
# using int as index and Dict[str, str] as keys
selection_dict = cast(Dict[int, Dict[str,str]], selection.to_dict(orient='index'))
self.runList.setRuns(selection_dict, show_only_star, show_also_cross)

### handling user selections
@Slot(list)
Expand All @@ -562,12 +565,15 @@ def setDateSelection(self, dates: Sequence[str]) -> None:
assert self.dbdf is not None
selection = self.dbdf.loc[self.dbdf['started_date'].isin(dates)].sort_index(ascending=False)
old_dates = self._selected_dates
# Pandas types cannot infer that this dataframe will be
# using int as index and Dict[str, str] as keys
selection_dict = cast(Dict[int, Dict[str,str]], selection.to_dict(orient='index'))
if not all(date in old_dates for date in dates):
show_only_star = self.showOnlyStarAction.isChecked()
show_also_cross = self.showAlsoCrossAction.isChecked()
self.runList.setRuns(selection.to_dict(orient='index'), show_only_star, show_also_cross)
self.runList.setRuns(selection_dict, show_only_star, show_also_cross)
else:
self.runList.updateRuns(selection.to_dict(orient='index'))
self.runList.updateRuns(selection_dict)
self._selected_dates = tuple(dates)
else:
self._selected_dates = ()
Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ classifiers =
Intended Audience :: Science/Research
License :: OSI Approved :: MIT License
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Expand All @@ -24,7 +23,7 @@ project_urls =

[options]
packages = find:
python_requires = >=3.7
python_requires = >=3.8
install_requires =
pandas>=0.22
xarray
Expand Down
1 change: 1 addition & 0 deletions test_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pytest
pytest-qt
mypy==0.971
PyQt5-stubs==5.15.6.0
pandas-stubs

0 comments on commit a17b024

Please sign in to comment.