Skip to content

Commit

Permalink
Merge pull request #46 from astrofrog/infrastructure
Browse files Browse the repository at this point in the history
Update infratructure and fix compatibility with latest version of Hypothesis
  • Loading branch information
astrofrog authored Jan 7, 2020
2 parents ace4f24 + f8f6679 commit 4dbb898
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 215 deletions.
75 changes: 0 additions & 75 deletions .circleci/config.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@ htmlcov

# PyCharm
.idea

.tox
.tmp
fast_histogram/version.py
31 changes: 0 additions & 31 deletions .travis.yml

This file was deleted.

3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
0.8 (unreleased)
----------------

- No changes yet.
- Fixed compatibility of test suite with latest version of the
hypothesis package. [#40]

0.7 (2019-01-09)
----------------
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include LICENSE
include README.rst
include CHANGES.rst
include pyproject.toml
41 changes: 0 additions & 41 deletions appveyor.yml

This file was deleted.

44 changes: 44 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
resources:
repositories:
- repository: OpenAstronomy
type: github
endpoint: astrofrog
name: OpenAstronomy/azure-pipelines-templates
ref: master

jobs:

- template: run-tox-env.yml@OpenAstronomy
parameters:

coverage: codecov

envs:

- linux32: py36-test-numpy113
- linux32: py36-test-numpy114
- linux32: py36-test-numpy115
- linux32: py37-test-numpy116
- linux32: py37-test-numpy117
# - linux32: py38-test-numpy118

- linux: py36-test-numpy113
- linux: py36-test-numpy114
- linux: py36-test-numpy115
- linux: py37-test-numpy116
- linux: py37-test-numpy117
- linux: py38-test-numpy118

- macos: py36-test-numpy113
- macos: py36-test-numpy114
- macos: py36-test-numpy115
- macos: py37-test-numpy116
- macos: py37-test-numpy117
- macos: py38-test-numpy118

- windows: py36-test-numpy113
- windows: py36-test-numpy114
- windows: py36-test-numpy115
- windows: py37-test-numpy116
- windows: py37-test-numpy117
- windows: py38-test-numpy118
3 changes: 1 addition & 2 deletions fast_histogram/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from .histogram import *

__version__ = "0.8.dev0"
from .version import version as __version__
67 changes: 43 additions & 24 deletions fast_histogram/tests/test_histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from hypothesis import given, settings, example, assume
from hypothesis import given, settings, assume
from hypothesis import strategies as st
from hypothesis.extra.numpy import arrays

Expand All @@ -14,27 +14,34 @@
# comparing to Numpy) test cases.


@given(size=st.integers(0, 100),
@given(values=arrays(dtype='<f8', shape=st.integers(0, 200),
elements=st.floats(-1000, 1000), unique=True),
nx=st.integers(1, 10),
xmin=st.floats(-1e10, 1e10), xmax=st.floats(-1e10, 1e10),
xmin=st.floats(-1e10, 1e10),
xmax=st.floats(-1e10, 1e10),
weights=st.booleans(),
dtype=st.sampled_from(['>f4', '<f4', '>f8', '<f8']))
@settings(max_examples=5000)
def test_1d_compare_with_numpy(size, nx, xmin, xmax, weights, dtype):
@settings(max_examples=500)
def test_1d_compare_with_numpy(values, nx, xmin, xmax, weights, dtype):

if xmax <= xmin:
return

x = arrays(dtype, size, elements=st.floats(-1000, 1000)).example()
values = values.astype(dtype)

size = len(values) // 2

if weights:
w = arrays(dtype, size, elements=st.floats(-1000, 1000)).example()
w = values[:size]
else:
w = None

x = values[size:size * 2]

try:
reference = np.histogram(x, bins=nx, weights=w, range=(xmin, xmax))[0]
except ValueError:
if 'f4' in dtype:
if 'f4' in str(x.dtype):
# Numpy has a bug in certain corner cases
# https://github.com/numpy/numpy/issues/11586
return
Expand All @@ -43,7 +50,8 @@ def test_1d_compare_with_numpy(size, nx, xmin, xmax, weights, dtype):

# First, check the Numpy result because it sometimes doesn't make sense. See
# bug report https://github.com/numpy/numpy/issues/9435
inside = (x <= xmax) & (x >= xmin)
# FIXME: for now use < since that's what our algorithm does
inside = (x < xmax) & (x >= xmin)
if weights:
assume(np.allclose(np.sum(w[inside]), np.sum(reference)))
else:
Expand All @@ -56,35 +64,40 @@ def test_1d_compare_with_numpy(size, nx, xmin, xmax, weights, dtype):
# for 1D arrays. Since this is a summation variable it makes sense to
# return 64-bit, so rather than changing the behavior of histogram1d, we
# cast to 32-bit float here.
if 'f4' in dtype:
fast = fast.astype(np.float32)
if x.dtype.kind == 'f' and x.dtype.itemsize == 4:
rtol = 1e-7
else:
rtol = 1e-14

np.testing.assert_equal(fast, reference)
np.testing.assert_allclose(fast, reference, rtol=rtol)


@given(size=st.integers(0, 100),
@given(values=arrays(dtype='<f8', shape=st.integers(0, 300),
elements=st.floats(-1000, 1000), unique=True),
nx=st.integers(1, 10),
xmin=st.floats(-1e10, 1e10), xmax=st.floats(-1e10, 1e10),
ny=st.integers(1, 10),
ymin=st.floats(-1e10, 1e10), ymax=st.floats(-1e10, 1e10),
weights=st.booleans(),
dtype=st.sampled_from(['>f4', '<f4', '>f8', '<f8']))
@settings(max_examples=5000)
@example(size=5, nx=1, xmin=0.0, xmax=84.17833763374462, ny=1, ymin=-999999999.9999989, ymax=0.0, weights=False, dtype='<f8')
@example(size=1, nx=1, xmin=-2.2204460492503135e-06, xmax=0.0, ny=1, ymin=0.0, ymax=1.1102230246251567e-05, weights=False, dtype='<f8')
@example(size=3, nx=1, xmin=0.0, xmax=841.7833941010146, ny=1, ymin=-135.92383885097095, ymax=0.0, weights=True, dtype='>f8')
def test_2d_compare_with_numpy(size, nx, xmin, xmax, ny, ymin, ymax, weights, dtype):
@settings(max_examples=500)
def test_2d_compare_with_numpy(values, nx, xmin, xmax, ny, ymin, ymax, weights, dtype):

if xmax <= xmin or ymax <= ymin:
return

x = arrays(dtype, size, elements=st.floats(-1000, 1000)).example()
y = arrays(dtype, size, elements=st.floats(-1000, 1000)).example()
values = values.astype(dtype)

size = len(values) // 3

if weights:
w = arrays(dtype, size, elements=st.floats(-1000, 1000)).example()
w = values[:size]
else:
w = None

x = values[size:size * 2]
y = values[size * 2:size * 3]

try:
reference = np.histogram2d(x, y, bins=(nx, ny), weights=w,
range=((xmin, xmax), (ymin, ymax)))[0]
Expand All @@ -93,8 +106,9 @@ def test_2d_compare_with_numpy(size, nx, xmin, xmax, ny, ymin, ymax, weights, dt
return

# First, check the Numpy result because it sometimes doesn't make sense. See
# bug report https://github.com/numpy/numpy/issues/9435
inside = (x <= xmax) & (x >= xmin) & (y <= ymax) & (y >= ymin)
# bug report https://github.com/numpy/numpy/issues/9435.
# FIXME: for now use < since that's what our algorithm does
inside = (x < xmax) & (x >= xmin) & (y < ymax) & (y >= ymin)
if weights:
assume(np.allclose(np.sum(w[inside]), np.sum(reference)))
else:
Expand All @@ -104,7 +118,12 @@ def test_2d_compare_with_numpy(size, nx, xmin, xmax, ny, ymin, ymax, weights, dt
fast = histogram2d(x, y, bins=(nx, ny), weights=w,
range=((xmin, xmax), (ymin, ymax)))

np.testing.assert_equal(fast, reference)
if x.dtype.kind == 'f' and x.dtype.itemsize == 4:
rtol = 1e-7
else:
rtol = 1e-14

np.testing.assert_allclose(fast, reference, rtol=rtol)


def test_nd_arrays():
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[build-system]
requires = ["setuptools",
"setuptools_scm",
"wheel",
"oldest-supported-numpy"]
build-backend = 'setuptools.build_meta'
23 changes: 23 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[metadata]
name = fast-histogram
url = https://github.com/astrofrog/fast-histogram
author = Thomas Robitaille
author_email = [email protected]
license = BSD
description = Fast simple 1D and 2D histograms
long_description = file: README.rst

[options]
zip_safe = False
packages = find:
setup_requires =
setuptools_scm
install_requires =
numpy
python_requires = >=3.6

[options.extras_require]
test =
pytest
pytest-cov
hypothesis[numpy]
Loading

0 comments on commit 4dbb898

Please sign in to comment.