Skip to content

Commit

Permalink
Merge pull request #121 from ocefpaf/ruff_all
Browse files Browse the repository at this point in the history
Ruff all tests...
  • Loading branch information
ocefpaf authored Jun 19, 2024
2 parents 35a893b + c220e8b commit c61c6dd
Show file tree
Hide file tree
Showing 44 changed files with 2,471 additions and 1,184 deletions.
14 changes: 0 additions & 14 deletions .github/workflows/pre-commit.yml

This file was deleted.

26 changes: 23 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,34 @@ repos:
- id: trailing-whitespace
- id: check-ast
- id: debug-statements
- id: end-of-file-fixer
- id: check-docstring-first
- id: check-added-large-files
- id: requirements-txt-fixer
- id: file-contents-sorter
files: requirements-dev.txt

- repo: https://github.com/PyCQA/flake8
rev: 7.1.0
- repo: https://github.com/asottile/add-trailing-comma
rev: v3.1.0
hooks:
- id: flake8
- id: add-trailing-comma

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.9
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format

- repo: https://github.com/bdice/nb-strip-paths
rev: v0.1.0
hooks:
- id: nb-strip-paths

- repo: https://github.com/tox-dev/pyproject-fmt
rev: 2.1.3
hooks:
- id: pyproject-fmt

- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
Expand Down
2 changes: 0 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,3 @@ importance of writing tested and maintainable software.

* [How to Contribute to Open Source Guide](https://opensource.guide/how-to-contribute/)
* [Zen of Scientific Software Maintenance](https://jrleeman.github.io/ScientificSoftwareMaintenance/)


1 change: 0 additions & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,3 @@ Apache License
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

36 changes: 18 additions & 18 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
#
# ioos_qc documentation build configuration file, created by
# sphinx-quickstart on Thu Aug 18 10:56:41 2016.
# sphinx-quickstart on Mon Oct 9 21:28:42 2017.
#
# This file is execfile()d with the current directory set to its
# containing dir.
Expand All @@ -16,13 +16,10 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))

p = os.path.abspath(
os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
)
sys.path.insert(0, p)

# -- General configuration ------------------------------------------------

Expand Down Expand Up @@ -74,19 +71,20 @@
master_doc = "index"

# General information about the project.
import datetime

year = datetime.datetime.now(tz=datetime.timezone.utc).date().year
project = "ioos_qc"
copyright = "2022, IOOS"
copyright = f"2022-{year}, IOOS"
author = "IOOS"

# The version info for the project yo're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.

import ioos_qc # noqa
# The short X.Y version.
version = ioos_qc.__version__
# The full version, including alpha/beta/rc tags.
release = ioos_qc.__version__
import ioos_qc

version = release = ioos_qc.__version__

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down Expand Up @@ -274,15 +272,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -292,8 +287,13 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, "ioos_qc.tex", "ioos_qc Documentation",
"IOOS", "manual"),
(
master_doc,
"ioos_qc.tex",
"ioos_qc Documentation",
"IOOS",
"manual",
),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"The selected time period shows the tidal influence on salinity over a spring-neap time period.\n",
"Near the end of the selected period, there is a decrease in the range of salinity corresponding with biofouling.\n",
"\n",
"The data was downloaded from the [Center for Coastal Margin and Prediction (CMOP) Data Explorer](http://amb6400b.stccmop.org/ws/product/offeringplot_ctime.py?handlegaps=true&series=time,sandi.790.A.CTD.salt.PD0&width=8.54&height=2.92&starttime=2001-7-1%200:00&endtime=2001-09-5%2023:59)."
"The data was downloaded from the [Center for Coastal Margin and Prediction (CMOP) Data Explorer](https://amb6400b.stccmop.org/ws/product/offeringplot_ctime.py?handlegaps=true&series=time,sandi.790.A.CTD.salt.PD0&width=8.54&height=2.92&starttime=2001-7-1%200:00&endtime=2001-09-5%2023:59)."
]
},
{
Expand Down Expand Up @@ -531,7 +531,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.5"
"version": "3.12.4"
},
"nbsphinx": {
"orphan": true
Expand Down
4 changes: 2 additions & 2 deletions docs/source/examples/QartodTestExample_netCDF.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"outputs": [],
"source": [
"import xarray as xr\n",
"from erddapy.url_handling import urlopen\n",
"from erddapy.core.url import urlopen\n",
"from netCDF4 import Dataset\n",
"\n",
"\n",
Expand Down Expand Up @@ -549,7 +549,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.5"
"version": "3.12.4"
},
"nbsphinx": {
"orphan": true
Expand Down
2 changes: 1 addition & 1 deletion docs/source/examples/usage/Config.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@
]
}
]
}
}
2 changes: 1 addition & 1 deletion docs/source/examples/usage/ContextConfig.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@
]
}
]
}
}
2 changes: 1 addition & 1 deletion docs/source/examples/usage/NetcdfStream.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,4 @@
]
}
]
}
}
2 changes: 1 addition & 1 deletion docs/source/examples/usage/NumpyStream.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,4 @@
]
}
]
}
}
2 changes: 1 addition & 1 deletion docs/source/examples/usage/PandasStream.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,4 @@
]
}
]
}
}
2 changes: 1 addition & 1 deletion docs/source/examples/usage/XarrayStream.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,4 @@
]
}
]
}
}
1 change: 0 additions & 1 deletion docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ Installation
Install with `conda <https://docs.conda.io/en/latest/>`_::

$ conda install -c conda-forge ioos_qc

1 change: 0 additions & 1 deletion docs/source/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,3 @@ Specific changes to be aware of include:
####################

See https://github.com/ioos/qartod and https://ioos.github.io/qartod/

2 changes: 1 addition & 1 deletion ioos_qc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
"""IOOS QARTOD and other Quality Control tests implemented in Python."""

try:
from ._version import __version__
Expand Down
35 changes: 22 additions & 13 deletions ioos_qc/argo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
"""Tests based on the ARGO QC manual."""

import logging
import warnings
from numbers import Real as N
Expand All @@ -13,11 +14,13 @@
L = logging.getLogger(__name__)


@add_flag_metadata(stanard_name="pressure_increasing_test_quality_flag",
long_name="Pressure Increasing Test Quality Flag")
@add_flag_metadata(
stanard_name="pressure_increasing_test_quality_flag",
long_name="Pressure Increasing Test Quality Flag",
)
def pressure_increasing_test(inp):
"""Returns an array of flag values where each input is flagged with SUSPECT if
it does not monotonically increase
it does not monotonically increase.
Ref: ARGO QC Manual: 8. Pressure increasing test
Expand All @@ -44,14 +47,17 @@ def pressure_increasing_test(inp):
return flags


@add_flag_metadata(standard_name="speed_test_quality_flag",
long_name="Speed Test Quality Flag")
def speed_test(lon: Sequence[N],
lat: Sequence[N],
tinp: Sequence[N],
suspect_threshold: float,
fail_threshold: float,
) -> np.ma.core.MaskedArray:
@add_flag_metadata(
standard_name="speed_test_quality_flag",
long_name="Speed Test Quality Flag",
)
def speed_test(
lon: Sequence[N],
lat: Sequence[N],
tinp: Sequence[N],
suspect_threshold: float,
fail_threshold: float,
) -> np.ma.core.MaskedArray:
"""Checks that the calculated speed between two points is within reasonable bounds.
This test calculates a speed between subsequent points by
Expand Down Expand Up @@ -91,7 +97,8 @@ def speed_test(lon: Sequence[N],
tinp = mapdates(tinp)

if lon.shape != lat.shape or lon.shape != tinp.shape:
raise ValueError(f"Lon ({lon.shape}) and lat ({lat.shape}) and tinp ({tinp.shape}) must be the same shape")
msg = f"Lon ({lon.shape}) and lat ({lat.shape}) and tinp ({tinp.shape}) must be the same shape"
raise ValueError(msg)

# Save original shape
original_shape = lon.shape
Expand Down Expand Up @@ -120,7 +127,9 @@ def speed_test(lon: Sequence[N],

# calculate speed in m/s
speed = np.ma.zeros(tinp.size, dtype="float")
speed[1:] = np.abs(dist[1:] / np.diff(tinp).astype("timedelta64[s]").astype(float))
speed[1:] = np.abs(
dist[1:] / np.diff(tinp).astype("timedelta64[s]").astype(float),
)

with np.errstate(invalid="ignore"):
flag_arr[speed > suspect_threshold] = QartodFlags.SUSPECT
Expand Down
38 changes: 26 additions & 12 deletions ioos_qc/axds.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
"""Tests based on the IOOS QARTOD manuals."""

import logging
from collections import namedtuple
from typing import Sequence, Tuple
Expand All @@ -17,14 +18,17 @@
span = namedtuple("Span", "minv maxv")


@add_flag_metadata(standard_name="gross_range_test_quality_flag",
long_name="Gross Range Test Quality Flag")
def valid_range_test(inp : Sequence[any],
valid_span : Tuple[any, any],
dtype : np.dtype = None,
start_inclusive : bool = True,
end_inclusive : bool = False,
) -> np.ma.core.MaskedArray:
@add_flag_metadata(
standard_name="gross_range_test_quality_flag",
long_name="Gross Range Test Quality Flag",
)
def valid_range_test(
inp: Sequence[any],
valid_span: Tuple[any, any],
dtype: np.dtype = None,
start_inclusive: bool = True,
end_inclusive: bool = False,
) -> np.ma.core.MaskedArray:
"""Checks that values are within a min/max range. This is not unlike a `qartod.gross_range_test`
with fail and suspect bounds being equal, except that here we specify the inclusive range that
should pass instead of the exclusive bounds which should fail. This also supports datetime-like
Expand Down Expand Up @@ -60,14 +64,20 @@ def valid_range_test(inp : Sequence[any],
# This is required because we don't want to restrict a user from using a pd.Series
# directly with this function. If the data was coming from a Store, it would
# always be a numpy array.
elif dtype is None and hasattr(inp, "values") and hasattr(inp.values, "dtype"):
elif (
dtype is None
and hasattr(inp, "values")
and hasattr(inp.values, "dtype")
):
dtype = inp.values.dtype

# Save original shape
original_shape = inp.shape

if dtype is None:
L.warning("Trying to guess data input type, try specifying the dtype parameter")
L.warning(
"Trying to guess data input type, try specifying the dtype parameter",
)
# Try to figure out the dtype so masked values can be calculated
try:
# Try datetime-like objects
Expand All @@ -77,11 +87,15 @@ def valid_range_test(inp : Sequence[any],
try:
# Try floating point numbers
inp = np.ma.masked_invalid(np.array(inp).astype(np.floating))
valid_span = np.ma.masked_invalid(np.array(valid_span).astype(np.floating))
valid_span = np.ma.masked_invalid(
np.array(valid_span).astype(np.floating),
)
except BaseException:
# Well, we tried.
msg = "Could not determine the type of input, try using the dtype parameter"
raise ValueError(
"Could not determine the type of input, try using the dtype parameter")
msg,
)
else:
inp = np.ma.masked_invalid(np.array(inp, dtype=dtype))
valid_span = np.ma.masked_invalid(np.array(valid_span, dtype=dtype))
Expand Down
Loading

0 comments on commit c61c6dd

Please sign in to comment.