Skip to content

Commit

Permalink
Merge pull request #91 from mroberge/update-ci
Browse files Browse the repository at this point in the history
Update from Travis-CI to Github Actions
  • Loading branch information
mroberge committed May 22, 2021
2 parents 16dd705 + ce35ce5 commit 962fc73
Show file tree
Hide file tree
Showing 22 changed files with 160 additions and 361 deletions.
20 changes: 0 additions & 20 deletions .github/workflows/build.yml

This file was deleted.

36 changes: 36 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Run test suite

on: [push]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest pytest-cov
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- 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
run: |
pytest --cov=./
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
fail_ci_if_error: true
Binary file removed .spyderproject
Binary file not shown.
74 changes: 0 additions & 74 deletions .travis.yml

This file was deleted.

5 changes: 4 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
include LICENSE
include README.rst
include pypi_readme.rst
include requirements.txt

recursive-include tests *
recursive-exclude * __pycache__
recursive-exclude * *.py[co]

recursive-include docs *.rst conf.py Makefile make.bat *.jpg *.png *.gif *.svg
recursive-include docs *.rst conf.py Makefile make.bat *.jpg *.png *.gif *.svg *.css
recursive-include docs/notebooks *.ipynb *.parquet *.json.gz
recursive-include _static *
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ HydroFunctions
:target: https://pypi.python.org/pypi/hydrofunctions
:alt: Visit Hydrofunctions on PyPI

.. image:: https://img.shields.io/travis/mroberge/hydrofunctions.svg
:target: https://travis-ci.org/mroberge/hydrofunctions
.. image:: https://github.com/mroberge/hydrofunctions/actions/workflows/test.yaml/badge.svg
:target: https://github.com/mroberge/hydrofunctions/actions/workflows/test.yaml
:alt: Unit Testing Status

.. image:: https://codecov.io/gh/mroberge/hydrofunctions/branch/master/graph/badge.svg
Expand Down
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@
"github_type": "watch",
"github_count": True,
"github_banner": True,
"travis_button": True,
"fixed_sidebar": False,
"sidebar_width": "230px",
"show_related": True,
Expand Down
4 changes: 2 additions & 2 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Submitting a pull request
- **Submit your Pull Request early**, while you are just starting to get started! This will:
- open up a forum in GitHub where people can add comments
- set up a checklist of things to get done
- enables automatic commit testing with TravisCI.
- enables automatic unit testing.
- all your subsequent commits get added to the pull request automatically.
- Don't apologize for mistakes or not being done yet!

Expand All @@ -40,7 +40,7 @@ Standards for the ideal pull request
- Use `Google-style docstrings <https://google.github.io/styleguide/pyguide.html?showone=Comments#Comments>`_
, described `here <https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html>`_.
- Add tests! Lots of tests! Make sure you test your code!
- Your code should work for Python 3.6, 3.7, & 3.8. This gets tested in `TravisCI <https://travis-ci.org/mroberge/hydrofunctions/pull_requests>`_
- Your code should work for Python 3.6, 3.7, 3.8, & 3.9. This gets tested by the `CI <https://github.com/mroberge/hydrofunctions/actions/workflows/test.yaml>`_


A detailed guide to contributing new code
Expand Down
5 changes: 5 additions & 0 deletions docs/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,9 @@ History
* hf.data_catalog(site) retrieves history of data collected at site.
* Dropped Python 3.4 & 3.5 support, added 3.8.

0.2.1 (2021-05-xx)
------------------

* Moved from TravisCI to Github Actions.
* Added Python 3.9 support.
*
10 changes: 5 additions & 5 deletions hydrofunctions/charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
-----
"""
from __future__ import absolute_import, print_function, division, unicode_literals
import matplotlib

# Recommended that I use this line to avoid errors in TravisCI
# See https://matplotlib.org/faq/howto_faq.html
# Basically, matplotlib usually uses an 'X11 connection' by default; Travis CI
# does not have this configured, so you need to set your backend explicitly.
from __future__ import absolute_import, print_function, division, unicode_literals
import matplotlib

matplotlib.use("Agg")
import matplotlib.pyplot as plt
from matplotlib.ticker import NullFormatter
Expand Down Expand Up @@ -200,8 +200,8 @@ def cycleplot(
Qseries = Qseries.loc[:, Qseries.select_dtypes(include="number").columns[0]]
if not isinstance(Qseries, pd.Series):
raise ValueError(
f"Cycleplot only accepts a single series of data as "
" an argument. You supplied a {type(Qseries).}"
"Cycleplot only accepts a single series of data as "
f" an argument. You supplied a {type(Qseries)}."
)

if cycle == "annual":
Expand Down
18 changes: 9 additions & 9 deletions hydrofunctions/hydrofunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,8 @@ def read_parquet(filename):
filename (str): A string with the filename and extension.
Returns:
* dataframe (pd.DataFrame): a pandas dataframe.
* meta (dict): a dictionary with the metadata for the NWIS data request, if it exists.
dataframe (pd.DataFrame): a pandas dataframe.
meta (dict): a dictionary with the metadata for the NWIS data request, if it exists.
"""
pa_table = pq.read_table(filename)
dataframe = pa_table.to_pandas()
Expand Down Expand Up @@ -739,8 +739,8 @@ def save_parquet(filename, dataframe, hf_meta):
dataframe (pd.DataFrame): a pandas dataframe.
hf_meta (dict): a dictionary with the metadata for the NWIS data request, if it exists.
"""
if (len(filename.split('.'))==1):
filename = filename + '.gz.parquet'
if len(filename.split(".")) == 1:
filename = filename + ".gz.parquet"

table = pa.Table.from_pandas(dataframe, preserve_index=True)
meta_dict = table.schema.metadata
Expand All @@ -764,7 +764,7 @@ def read_json_gzip(filename):
Returns:
a dictionary of the file contents.
"""
with gzip.open(filename, 'rb') as zip_file:
with gzip.open(filename, "rb") as zip_file:
zip_dict = json.loads(zip_file.read())
return zip_dict

Expand All @@ -780,8 +780,8 @@ def save_json_gzip(filename, json_dict):
filename (str): A string with the filename and extension.
json_dict (dict): A dictionary representing the json content.
"""
if (len(filename.split('.'))==1):
filename = filename + 'json.gz'
if len(filename.split(".")) == 1:
filename = filename + "json.gz"

with gzip.open(filename, 'wt', encoding="ascii") as zip_file:
json.dump(json_dict, zip_file)
with gzip.open(filename, "wt", encoding="ascii") as zip_file:
json.dump(json_dict, zip_file)
33 changes: 19 additions & 14 deletions hydrofunctions/station.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __init__(

self.ok = False
if file:
if (len(file.split(".")) == 1):
if len(file.split(".")) == 1:
file = file + ".json.gz"
try:
self.read(file)
Expand All @@ -125,7 +125,7 @@ def __init__(
# File does not exist yet, we'll make it later.
pass

if self.ok == False:
if not self.ok:
self.response = hf.get_nwis(
site,
service,
Expand Down Expand Up @@ -197,9 +197,9 @@ def df(self, *args):
str 'stage': Gauge height columns ('00065') will be returned.
int any five digit number: any matching parameter columns will be returned. '00065' returns stage, for example.
str any five digit number: any matching parameter columns will be returned. '00065' returns stage, for example.
int any eight to twelve digit number: any matching stations will be returned.
str any eight to twelve digit number: any matching stations will be returned.
"""
all_cols = self._dataframe.columns != "" # all true
no_cols = ~all_cols # all false
Expand Down Expand Up @@ -292,20 +292,23 @@ def save(self, file):
the filename to save to.
"""
extension = file.split(".")[-1]
if (extension == "parquet"):
if extension == "parquet":
hf.save_parquet(file, self._dataframe, self.meta)
elif (extension == "gz"):
elif extension == "gz":
try:
hf.save_json_gzip(file, self.json)
except AttributeError as err:
print("Hydrofunctions can only save NWIS objects using gzip if the NWIS"
" object still has its original WaterML JSON. You might be able to fix "
"this problem if you call NWIS using the 'file' parameter so that the"
"JSON is saved immediately after the request is made."
print(
"Hydrofunctions can only save NWIS objects using gzip if the NWIS"
" object still has its original WaterML JSON. You might be able "
"to fix this problem if you call NWIS using the 'file' parameter "
"so that the JSON is saved immediately after the request is made."
)
raise err
else:
raise OSError(f"The file type extension '.{extension}' in the file name {file} is not recognized by HydroFunctions.")
raise OSError(
f"The file type extension '.{extension}' in the file name {file} is not recognized by HydroFunctions."
)
return self

def read(self, file):
Expand All @@ -317,10 +320,12 @@ def read(self, file):
the filename to read from.
"""
extension = file.split(".")[-1]
if (extension == "parquet"):
if extension == "parquet":
self._dataframe, self.meta = hf.read_parquet(file)
elif (extension == "gz"):
elif extension == "gz":
self._dataframe, self.meta = hf.extract_nwis_df(hf.read_json_gzip(file))
else:
raise OSError(f"The file type extension '.{extension}' in the file name {file} is not recognized by HydroFunctions.")
raise OSError(
f"The file type extension '.{extension}' in the file name {file} is not recognized by HydroFunctions."
)
return self

0 comments on commit 962fc73

Please sign in to comment.