Skip to content

Commit

Permalink
Merge pull request #292 from ocefpaf/fix_optional_deps
Browse files Browse the repository at this point in the history
Fix optional deps
  • Loading branch information
ocefpaf authored Dec 8, 2022
2 parents 2f3921d + f75af42 commit f11ad16
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 32 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Tests
name: Full Tests

on:
pull_request:
Expand All @@ -10,7 +10,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
os: [windows-latest, ubuntu-latest, macos-latest]
fail-fast: false

Expand All @@ -24,12 +24,12 @@ jobs:

- name: Python ${{ matrix.python-version }}
shell: bash -l {0}
run: |
run: >
micromamba create --name TEST python=${{ matrix.python-version }} --file requirements.txt --file requirements-dev.txt --channel conda-forge
micromamba activate TEST
python -m pip install -e . --no-deps --force-reinstall
&& micromamba activate TEST
&& python -m pip install -e . --no-deps --force-reinstall
- name: Tests
- name: Full Tests
shell: bash -l {0}
run: |
micromamba activate TEST
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/tests_core.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Core Tests

on:
pull_request:
push:
branches: [main]

defaults:
run:
shell: bash

jobs:
packages:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"

- name: Install
run: >
python -m pip install .
&& python -m pip install pytest
- name: Core Tests
run: python -m pytest -rxs tests/test_erddapy.py
18 changes: 12 additions & 6 deletions erddapy/core/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
This module takes an URL or the bytes response of a request and converts it to Pandas,
XArray, Iris, etc. objects.
"""
from typing import TYPE_CHECKING

import iris
import pandas as pd
import xarray as xr
from netCDF4 import Dataset

from erddapy.core.netcdf import _nc_dataset, _tempnc
from erddapy.core.url import urlopen

if TYPE_CHECKING:
import xarray as xr
from netCDF4 import Dataset

def to_pandas(url: str, requests_kwargs=None, **kw) -> pd.DataFrame:

def to_pandas(url: str, requests_kwargs=None, **kw) -> "pd.DataFrame":
"""Convert a URL to Pandas DataFrame."""
if requests_kwargs is None:
requests_kwargs = {}
Expand All @@ -25,7 +27,7 @@ def to_pandas(url: str, requests_kwargs=None, **kw) -> pd.DataFrame:
raise ValueError(f"Could not read url {url} with Pandas.read_csv.") from e


def to_ncCF(url: str, protocol: str = None, **kw) -> Dataset:
def to_ncCF(url: str, protocol: str = None, **kw) -> "Dataset":
"""Convert a URL to a netCDF4 Dataset."""
if protocol == "griddap":
raise ValueError(
Expand All @@ -35,8 +37,10 @@ def to_ncCF(url: str, protocol: str = None, **kw) -> Dataset:
return _nc_dataset(url, auth=auth, **kw)


def to_xarray(url: str, response="opendap", **kw) -> xr.Dataset:
def to_xarray(url: str, response="opendap", **kw) -> "xr.Dataset":
"""Convert a URL to an xarray dataset."""
import xarray as xr

auth = kw.pop("auth", None)
if response == "opendap":
return xr.open_dataset(url, **kw)
Expand All @@ -47,6 +51,8 @@ def to_xarray(url: str, response="opendap", **kw) -> xr.Dataset:

def to_iris(url: str, **kw):
"""Convert a URL to an iris CubeList."""
import iris

data = urlopen(url, **kw)
with _tempnc(data) as tmp:
cubes = iris.load_raw(tmp, **kw)
Expand Down
3 changes: 1 addition & 2 deletions erddapy/core/netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

from contextlib import contextmanager
from pathlib import Path
from typing import Dict, Generator
from typing.io import BinaryIO
from typing import BinaryIO, Dict, Generator
from urllib.parse import urlparse

from erddapy.core.url import urlopen
Expand Down
3 changes: 1 addition & 2 deletions erddapy/core/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import functools
import io
from datetime import datetime
from typing import Dict, List, Optional, Tuple, Union
from typing.io import BinaryIO
from typing import BinaryIO, Dict, List, Optional, Tuple, Union
from urllib.parse import quote_plus

import httpx
Expand Down
2 changes: 0 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
black
cartopy>=0.21
check-manifest
doctr
doctr-versions-menu
flake8
flake8-builtins
flake8-comprehensions
Expand Down
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ classifiers =
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Topic :: Scientific/Engineering

[options]
zip_safe = True
include_package_data = True
install_requires =
pandas >=1
requests
httpx
python_requires = >=3.7
packages = find:

Expand Down
13 changes: 0 additions & 13 deletions tests/test_erddapy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from datetime import datetime

import httpx
import pendulum
import pytest
import pytz

Expand All @@ -28,24 +27,12 @@ def test_parse_dates_utc_datetime():
assert parse_dates(d) == 0


def test_parse_dates_utc_pendulum():
"""UTC timestamp at 1970-1-1 must be 0."""
d = pendulum.datetime(1970, 1, 1, 0, 0, 0, tz="UTC")
assert parse_dates(d) == 0


def test_parse_dates_nonutc_datetime():
"""Non-UTC timestamp at 1970-1-1 must have the zone offset."""
d = datetime(1970, 1, 1, tzinfo=pytz.timezone("US/Eastern"))
assert parse_dates(d) == abs(d.utcoffset().total_seconds())


def test_parse_dates_nonutc_pendulum():
"""Non-UTC timestamp at 1970-1-1 must have the zone offset."""
d = pendulum.datetime(1970, 1, 1, 0, 0, 0, tz="America/Vancouver")
assert parse_dates(d) == abs(d.utcoffset().total_seconds())


def test_parse_dates_from_string():
"""Test if parse_dates can take string input."""
assert parse_dates("1970-01-01T00:00:00") == 0
Expand Down

0 comments on commit f11ad16

Please sign in to comment.