Skip to content

Commit 2c775e4

Browse files
authored
Add pandas 3x, legacy xfails, and samples API key (#221)
* Add pandas 3x, legacy xfails, and samples API key * Ruff fixes * Remove qwdata example and NADP path fix * Update ruff CI and config
1 parent 5c9ac1f commit 2c775e4

26 files changed

Lines changed: 678 additions & 621 deletions

.github/workflows/python-package.yml

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,42 @@ on:
1010
branches: ['main']
1111

1212
jobs:
13-
build:
13+
lint:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Set up Python 3.14
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: "3.14"
21+
cache: "pip"
22+
- name: Install ruff
23+
run: pip install ruff
24+
- name: Lint with ruff
25+
run: |
26+
ruff check . --output-format=github
27+
ruff format --check .
28+
29+
test:
30+
needs: lint
1431
runs-on: ${{ matrix.os }}
1532
strategy:
1633
fail-fast: false
1734
matrix:
1835
os: [ubuntu-latest, windows-latest]
19-
python-version: [3.9, 3.13, 3.14]
36+
python-version: ["3.9", "3.13", "3.14"]
2037

2138
steps:
22-
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871
39+
- uses: actions/checkout@v4
2340
- name: Set up Python ${{ matrix.python-version }}
24-
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3
41+
uses: actions/setup-python@v5
2542
with:
2643
python-version: ${{ matrix.python-version }}
44+
cache: "pip"
2745
- name: Install dependencies
2846
run: |
2947
python -m pip install --upgrade pip
3048
pip install .[test,nldi]
31-
- name: Lint with flake8
32-
run: |
33-
# stop the build if there are Python syntax errors or undefined names
34-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
35-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
36-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
3749
- name: Test with pytest and report coverage
3850
run: |
3951
coverage run -m pytest tests/

.github/workflows/python-publish.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ jobs:
2121
runs-on: ubuntu-latest
2222

2323
steps:
24-
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871
24+
- uses: actions/checkout@v4
2525
- name: Set up Python
26-
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3
26+
uses: actions/setup-python@v5
2727
with:
2828
python-version: '3.x'
29+
cache: 'pip'
2930
- name: Install dependencies
3031
run: |
3132
python -m pip install --upgrade pip
3233
pip install build
33-
pip install setuptools setuptools-scm wheel twine check-manifest
3434
- name: Build package
3535
run: python -m build
3636
- name: Publish package
37-
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
37+
uses: pypa/gh-action-pypi-publish@release/v1
3838
with:
3939
user: __token__
4040
password: ${{ secrets.PYPI_API_TOKEN }}

.github/workflows/sphinx-docs.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Checkout
14-
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871
14+
uses: actions/checkout@v4
1515
with:
1616
persist-credentials: false
17+
- name: Set up Python
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: "3.13"
21+
cache: "pip"
1722
- name: Install dataretrieval, dependencies, and Sphinx then build docs
1823
shell: bash -l {0}
1924
run: |
@@ -30,7 +35,7 @@ jobs:
3035
echo ${{ github.ref == 'refs/heads/main' }}
3136
echo ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
3237
- name: Deploy to GitHub Pages
33-
uses: JamesIves/github-pages-deploy-action@881db5376404c5c8d621010bcbec0310b58d5e29
38+
uses: JamesIves/github-pages-deploy-action@v4
3439
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
3540
with:
3641
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

dataretrieval/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
except PackageNotFoundError:
66
__version__ = "version-unknown"
77

8-
from dataretrieval.nadp import * # noqa: F403
9-
from dataretrieval.nwis import * # noqa: F403
10-
from dataretrieval.samples import * # noqa: F403
11-
from dataretrieval.streamstats import * # noqa: F403
12-
from dataretrieval.utils import * # noqa: F403
13-
from dataretrieval.waterdata import * # noqa: F403
14-
from dataretrieval.waterwatch import * # noqa: F403
15-
from dataretrieval.wqp import * # noqa: F403
8+
from dataretrieval.nadp import *
9+
from dataretrieval.nwis import *
10+
from dataretrieval.samples import *
11+
from dataretrieval.streamstats import *
12+
from dataretrieval.utils import *
13+
from dataretrieval.waterdata import *
14+
from dataretrieval.waterwatch import *
15+
from dataretrieval.wqp import *

dataretrieval/codes/__init__.py

100755100644
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
from .states import * # noqa: F403
2-
from .timezones import * # noqa: F403
1+
from .states import *
2+
from .timezones import *

dataretrieval/nadp.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@
3030
"""
3131

3232
import io
33-
import os
3433
import re
3534
import zipfile
36-
from os.path import basename
3735

3836
import requests
3937

@@ -118,7 +116,7 @@ def get_annual_MDN_map(measurement_type, year, path):
118116
if path:
119117
z.extractall(path)
120118

121-
return f"{path}{os.sep}{basename(filename)}"
119+
return str(path)
122120

123121

124122
def get_annual_NTN_map(measurement_type, measurement=None, year=None, path="."):
@@ -174,7 +172,7 @@ def get_annual_NTN_map(measurement_type, measurement=None, year=None, path="."):
174172
if path:
175173
z.extractall(path)
176174

177-
return f"{path}{os.sep}{basename(filename)}"
175+
return str(path)
178176

179177

180178
def get_zip(url, filename):

dataretrieval/nldi.py

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from __future__ import annotations
2+
13
from json import JSONDecodeError
2-
from typing import Literal, Optional, Union
4+
from typing import Literal
35

46
from dataretrieval.utils import query
57

@@ -32,13 +34,13 @@ def _query_nldi(url, query_params, error_message):
3234
def get_flowlines(
3335
navigation_mode: str,
3436
distance: int = 5,
35-
feature_source: Optional[str] = None,
36-
feature_id: Optional[str] = None,
37-
comid: Optional[int] = None,
38-
stop_comid: Optional[int] = None,
37+
feature_source: str | None = None,
38+
feature_id: str | None = None,
39+
comid: int | None = None,
40+
stop_comid: int | None = None,
3941
trim_start: bool = False,
4042
as_json: bool = False,
41-
) -> Union[gpd.GeoDataFrame, dict]:
43+
) -> gpd.GeoDataFrame | dict:
4244
"""Gets the flowlines for the specified navigation either by comid or feature
4345
source in WGS84 lat/long coordinates as GeoDataFrame containing a polyline geometry.
4446
@@ -116,7 +118,7 @@ def get_basin(
116118
simplified: bool = True,
117119
split_catchment: bool = False,
118120
as_json: bool = False,
119-
) -> Union[gpd.GeoDataFrame, dict]:
121+
) -> gpd.GeoDataFrame | dict:
120122
"""Gets the aggregated basin for the specified feature in WGS84 lat/lon
121123
as GeoDataFrame or as JSON conatining a polygon geometry.
122124
@@ -164,17 +166,17 @@ def get_basin(
164166

165167

166168
def get_features(
167-
data_source: Optional[str] = None,
168-
navigation_mode: Optional[str] = None,
169+
data_source: str | None = None,
170+
navigation_mode: str | None = None,
169171
distance: int = 50,
170-
feature_source: Optional[str] = None,
171-
feature_id: Optional[str] = None,
172-
comid: Optional[int] = None,
173-
lat: Optional[float] = None,
174-
long: Optional[float] = None,
175-
stop_comid: Optional[int] = None,
172+
feature_source: str | None = None,
173+
feature_id: str | None = None,
174+
comid: int | None = None,
175+
lat: float | None = None,
176+
long: float | None = None,
177+
stop_comid: int | None = None,
176178
as_json: bool = False,
177-
) -> Union[gpd.GeoDataFrame, dict]:
179+
) -> gpd.GeoDataFrame | dict:
178180
"""Gets all features found along the specified navigation either by
179181
comid or feature source as points in WGS84 lat/long coordinates - a GeoDataFrame
180182
containing a point geometry.
@@ -247,11 +249,10 @@ def get_features(
247249
)
248250

249251
if not lat:
250-
if comid or data_source:
251-
if navigation_mode is None:
252-
raise ValueError(
253-
"navigation_mode is required if comid or data_source is provided"
254-
)
252+
if (comid or data_source) and navigation_mode is None:
253+
raise ValueError(
254+
"navigation_mode is required if comid or data_source is provided"
255+
)
255256
# validate the feature source and comid
256257
_validate_feature_source_comid(feature_source, feature_id, comid)
257258
# validate the data source
@@ -334,14 +335,14 @@ def get_features_by_data_source(data_source: str) -> gpd.GeoDataFrame:
334335

335336

336337
def search(
337-
feature_source: Optional[str] = None,
338-
feature_id: Optional[str] = None,
339-
navigation_mode: Optional[str] = None,
340-
data_source: Optional[str] = None,
338+
feature_source: str | None = None,
339+
feature_id: str | None = None,
340+
navigation_mode: str | None = None,
341+
data_source: str | None = None,
341342
find: Literal["basin", "flowlines", "features"] = "features",
342-
comid: Optional[int] = None,
343-
lat: Optional[float] = None,
344-
long: Optional[float] = None,
343+
comid: int | None = None,
344+
lat: float | None = None,
345+
long: float | None = None,
345346
distance: int = 50,
346347
) -> dict:
347348
"""Searches for the specified feature in NLDI and returns the results
@@ -489,7 +490,7 @@ def _validate_navigation_mode(navigation_mode: str):
489490

490491

491492
def _validate_feature_source_comid(
492-
feature_source: Optional[str], feature_id: Optional[str], comid: Optional[int]
493+
feature_source: str | None, feature_id: str | None, comid: int | None
493494
):
494495
if feature_source is not None and feature_id is None:
495496
raise ValueError("feature_id is required if feature_source is provided")

0 commit comments

Comments
 (0)