Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,42 @@ on:
branches: ['main']

jobs:
build:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.14
uses: actions/setup-python@v5
with:
python-version: "3.14"
cache: "pip"
- name: Install ruff
run: pip install ruff
- name: Lint with ruff
run: |
ruff check . --output-format=github
ruff format --check .

test:
needs: lint
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
python-version: [3.9, 3.13, 3.14]
python-version: ["3.9", "3.13", "3.14"]

steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[test,nldi]
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest and report coverage
run: |
coverage run -m pytest tests/
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3
uses: actions/setup-python@v5
with:
python-version: '3.x'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
pip install setuptools setuptools-scm wheel twine check-manifest
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
9 changes: 7 additions & 2 deletions .github/workflows/sphinx-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
cache: "pip"
- name: Install dataretrieval, dependencies, and Sphinx then build docs
shell: bash -l {0}
run: |
Expand All @@ -30,7 +35,7 @@ jobs:
echo ${{ github.ref == 'refs/heads/main' }}
echo ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
- name: Deploy to GitHub Pages
uses: JamesIves/github-pages-deploy-action@881db5376404c5c8d621010bcbec0310b58d5e29
uses: JamesIves/github-pages-deploy-action@v4
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
16 changes: 8 additions & 8 deletions dataretrieval/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
except PackageNotFoundError:
__version__ = "version-unknown"

from dataretrieval.nadp import * # noqa: F403
from dataretrieval.nwis import * # noqa: F403
from dataretrieval.samples import * # noqa: F403
from dataretrieval.streamstats import * # noqa: F403
from dataretrieval.utils import * # noqa: F403
from dataretrieval.waterdata import * # noqa: F403
from dataretrieval.waterwatch import * # noqa: F403
from dataretrieval.wqp import * # noqa: F403
from dataretrieval.nadp import *
from dataretrieval.nwis import *
from dataretrieval.samples import *
from dataretrieval.streamstats import *
from dataretrieval.utils import *
from dataretrieval.waterdata import *
from dataretrieval.waterwatch import *
from dataretrieval.wqp import *
4 changes: 2 additions & 2 deletions dataretrieval/codes/__init__.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .states import * # noqa: F403
from .timezones import * # noqa: F403
from .states import *
from .timezones import *
6 changes: 2 additions & 4 deletions dataretrieval/nadp.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@
"""

import io
import os
import re
import zipfile
from os.path import basename

import requests

Expand Down Expand Up @@ -118,7 +116,7 @@ def get_annual_MDN_map(measurement_type, year, path):
if path:
z.extractall(path)

return f"{path}{os.sep}{basename(filename)}"
return str(path)


def get_annual_NTN_map(measurement_type, measurement=None, year=None, path="."):
Expand Down Expand Up @@ -174,7 +172,7 @@ def get_annual_NTN_map(measurement_type, measurement=None, year=None, path="."):
if path:
z.extractall(path)

return f"{path}{os.sep}{basename(filename)}"
return str(path)


def get_zip(url, filename):
Expand Down
59 changes: 30 additions & 29 deletions dataretrieval/nldi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from json import JSONDecodeError
from typing import Literal, Optional, Union
from typing import Literal

from dataretrieval.utils import query

Expand Down Expand Up @@ -32,13 +34,13 @@ def _query_nldi(url, query_params, error_message):
def get_flowlines(
navigation_mode: str,
distance: int = 5,
feature_source: Optional[str] = None,
feature_id: Optional[str] = None,
comid: Optional[int] = None,
stop_comid: Optional[int] = None,
feature_source: str | None = None,
feature_id: str | None = None,
comid: int | None = None,
stop_comid: int | None = None,
trim_start: bool = False,
as_json: bool = False,
) -> Union[gpd.GeoDataFrame, dict]:
) -> gpd.GeoDataFrame | dict:
"""Gets the flowlines for the specified navigation either by comid or feature
source in WGS84 lat/long coordinates as GeoDataFrame containing a polyline geometry.

Expand Down Expand Up @@ -116,7 +118,7 @@ def get_basin(
simplified: bool = True,
split_catchment: bool = False,
as_json: bool = False,
) -> Union[gpd.GeoDataFrame, dict]:
) -> gpd.GeoDataFrame | dict:
"""Gets the aggregated basin for the specified feature in WGS84 lat/lon
as GeoDataFrame or as JSON conatining a polygon geometry.

Expand Down Expand Up @@ -164,17 +166,17 @@ def get_basin(


def get_features(
data_source: Optional[str] = None,
navigation_mode: Optional[str] = None,
data_source: str | None = None,
navigation_mode: str | None = None,
distance: int = 50,
feature_source: Optional[str] = None,
feature_id: Optional[str] = None,
comid: Optional[int] = None,
lat: Optional[float] = None,
long: Optional[float] = None,
stop_comid: Optional[int] = None,
feature_source: str | None = None,
feature_id: str | None = None,
comid: int | None = None,
lat: float | None = None,
long: float | None = None,
stop_comid: int | None = None,
as_json: bool = False,
) -> Union[gpd.GeoDataFrame, dict]:
) -> gpd.GeoDataFrame | dict:
"""Gets all features found along the specified navigation either by
comid or feature source as points in WGS84 lat/long coordinates - a GeoDataFrame
containing a point geometry.
Expand Down Expand Up @@ -247,11 +249,10 @@ def get_features(
)

if not lat:
if comid or data_source:
if navigation_mode is None:
raise ValueError(
"navigation_mode is required if comid or data_source is provided"
)
if (comid or data_source) and navigation_mode is None:
raise ValueError(
"navigation_mode is required if comid or data_source is provided"
)
# validate the feature source and comid
_validate_feature_source_comid(feature_source, feature_id, comid)
# validate the data source
Expand Down Expand Up @@ -334,14 +335,14 @@ def get_features_by_data_source(data_source: str) -> gpd.GeoDataFrame:


def search(
feature_source: Optional[str] = None,
feature_id: Optional[str] = None,
navigation_mode: Optional[str] = None,
data_source: Optional[str] = None,
feature_source: str | None = None,
feature_id: str | None = None,
navigation_mode: str | None = None,
data_source: str | None = None,
find: Literal["basin", "flowlines", "features"] = "features",
comid: Optional[int] = None,
lat: Optional[float] = None,
long: Optional[float] = None,
comid: int | None = None,
lat: float | None = None,
long: float | None = None,
distance: int = 50,
) -> dict:
"""Searches for the specified feature in NLDI and returns the results
Expand Down Expand Up @@ -489,7 +490,7 @@ def _validate_navigation_mode(navigation_mode: str):


def _validate_feature_source_comid(
feature_source: Optional[str], feature_id: Optional[str], comid: Optional[int]
feature_source: str | None, feature_id: str | None, comid: int | None
):
if feature_source is not None and feature_id is None:
raise ValueError("feature_id is required if feature_source is provided")
Expand Down
Loading
Loading