diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..226f8ea --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,36 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Python application + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest + pip install . + - 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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..77e4dbf --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +build +dist +*.egg-info +*.pyc diff --git a/build/lib/numpyencoder/__init__.py b/build/lib/numpyencoder/__init__.py deleted file mode 100644 index 3e5c56b..0000000 --- a/build/lib/numpyencoder/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .numpyencoder import NumpyEncoder diff --git a/build/lib/numpyencoder/numpyencoder.py b/build/lib/numpyencoder/numpyencoder.py deleted file mode 100644 index b39f9c6..0000000 --- a/build/lib/numpyencoder/numpyencoder.py +++ /dev/null @@ -1,33 +0,0 @@ -import json -import numpy as np - - -class NumpyEncoder(json.JSONEncoder): - """ Custom encoder for numpy data types """ - def default(self, obj): - if isinstance(obj, (np.int_, np.intc, np.intp, np.int8, - np.int16, np.int32, np.int64, np.uint8, - np.uint16, np.uint32, np.uint64)): - - return int(obj) - - elif isinstance(obj, (np.float_, np.float16, np.float32, np.float64)): - return float(obj) - - elif isinstance(obj, (np.complex_, np.complex64, np.complex128)): - return {'real': obj.real, 'imag': obj.imag} - - elif isinstance(obj, (np.ndarray,)): - return obj.tolist() - - elif isinstance(obj, (np.bool_)): - return bool(obj) - - elif isinstance(obj, (np.void)): - return None - - return json.JSONEncoder.default(self, obj) - - -if __name__ == '__main__': - numpy_encoder = NumpyEncoder() diff --git a/dist/numpyencoder-0.2.0-py3-none-any.whl b/dist/numpyencoder-0.2.0-py3-none-any.whl deleted file mode 100644 index 873dad2..0000000 Binary files a/dist/numpyencoder-0.2.0-py3-none-any.whl and /dev/null differ diff --git a/dist/numpyencoder-0.2.0.tar.gz b/dist/numpyencoder-0.2.0.tar.gz deleted file mode 100644 index ca394af..0000000 Binary files a/dist/numpyencoder-0.2.0.tar.gz and /dev/null differ diff --git a/numpyencoder.egg-info/PKG-INFO b/numpyencoder.egg-info/PKG-INFO deleted file mode 100644 index c70879a..0000000 --- a/numpyencoder.egg-info/PKG-INFO +++ /dev/null @@ -1,31 +0,0 @@ -Metadata-Version: 2.1 -Name: numpyencoder -Version: 0.2.0 -Summary: Python JSON encoder for handling Numpy data types. -Home-page: https://github.com/hmallen/numpyencoder -Author: Hunter M. Allen -Author-email: allenhm@gmail.com -License: MIT -Description: # numpyencoder - - Custom Python JSON encoder for handling Numpy data types. - - **Example Use:** - - ```python - from numpyencoder import NumpyEncoder - - numpy_data = np.array([0, 1, 2, 3]) - - with open(json_file, 'w') as file: - json.dump(numpy_data, file, indent=4, sort_keys=True, - separators=(', ', ': '), ensure_ascii=False, - cls=NumpyEncoder) - ``` - -Keywords: numpy,json,encoder -Platform: UNKNOWN -Classifier: Programming Language :: Python :: 3 -Classifier: License :: OSI Approved :: MIT License -Classifier: Operating System :: OS Independent -Description-Content-Type: text/markdown diff --git a/numpyencoder.egg-info/SOURCES.txt b/numpyencoder.egg-info/SOURCES.txt deleted file mode 100644 index fe9bfc4..0000000 --- a/numpyencoder.egg-info/SOURCES.txt +++ /dev/null @@ -1,9 +0,0 @@ -README.md -setup.py -numpyencoder/__init__.py -numpyencoder/numpyencoder.py -numpyencoder.egg-info/PKG-INFO -numpyencoder.egg-info/SOURCES.txt -numpyencoder.egg-info/dependency_links.txt -numpyencoder.egg-info/requires.txt -numpyencoder.egg-info/top_level.txt \ No newline at end of file diff --git a/numpyencoder.egg-info/dependency_links.txt b/numpyencoder.egg-info/dependency_links.txt deleted file mode 100644 index 8b13789..0000000 --- a/numpyencoder.egg-info/dependency_links.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/numpyencoder.egg-info/requires.txt b/numpyencoder.egg-info/requires.txt deleted file mode 100644 index 03de7e7..0000000 --- a/numpyencoder.egg-info/requires.txt +++ /dev/null @@ -1 +0,0 @@ -numpy>=1.14.3 diff --git a/numpyencoder.egg-info/top_level.txt b/numpyencoder.egg-info/top_level.txt deleted file mode 100644 index 5f1168c..0000000 --- a/numpyencoder.egg-info/top_level.txt +++ /dev/null @@ -1 +0,0 @@ -numpyencoder diff --git a/numpyencoder/__init__.pyc b/numpyencoder/__init__.pyc deleted file mode 100644 index 1d92c7c..0000000 Binary files a/numpyencoder/__init__.pyc and /dev/null differ diff --git a/numpyencoder/numpyencoder.pyc b/numpyencoder/numpyencoder.pyc deleted file mode 100644 index d54e3a4..0000000 Binary files a/numpyencoder/numpyencoder.pyc and /dev/null differ diff --git a/tests/test_example.py b/tests/test_example.py new file mode 100644 index 0000000..37ba263 --- /dev/null +++ b/tests/test_example.py @@ -0,0 +1,13 @@ +def test_array_of_int(): + import json + import numpy as np + from numpyencoder import NumpyEncoder + + numpy_data = np.array([np.int64(0), np.int32(1), 2, 3]) + baseline_data = [0, 1, 2, 3] + + j_np = json.dumps(numpy_data, sort_keys=True, + separators=(', ', ': '), ensure_ascii=False, + cls=NumpyEncoder) + + assert json.dumps(baseline_data, sort_keys=True) == j_np