Skip to content

TST: fix checking for less_precise in floats #6990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: python
env:
global:
# scatterci API key
- secure: "Bx5umgo6WjuGY+5XFa004xjCiX/vq0CyMZ/ETzcs7EIBI1BE/0fIDXOoWhoxbY9HPfdPGlDnDgB9nGqr5wArO2s+BavyKBWg6osZ3dmkfuJPMOWeyCa92EeP+sfKw8e5HSU5MizW9e319wHWOF/xkzdHR7T67Qd5erhv91x4DnQ="
#- secure: "Bx5umgo6WjuGY+5XFa004xjCiX/vq0CyMZ/ETzcs7EIBI1BE/0fIDXOoWhoxbY9HPfdPGlDnDgB9nGqr5wArO2s+BavyKBWg6osZ3dmkfuJPMOWeyCa92EeP+sfKw8e5HSU5MizW9e319wHWOF/xkzdHR7T67Qd5erhv91x4DnQ="
# ironcache API key
- secure: "e4eEFn9nDQc3Xa5BWYkzfX37jaWVq89XidVX+rcCNEr5OlOImvveeXnF1IzbRXznH4Sv0YsLwUd8RGUWOmyCvkONq/VJeqCHWtTMyfaCIdqSyhIP9Odz8r9ahch+Y0XFepBey92AJHmlnTh+2GjCDgIiqq4fzglojnp56Vg1ojA="
- secure: "CjmYmY5qEu3KrvMtel6zWFEtMq8ORBeS1S1odJHnjQpbwT1KY2YFZRVlLphfyDQXSz6svKUdeRrCNp65baBzs3DQNA8lIuXGIBYFeJxqVGtYAZZs6+TzBPfJJK798sGOj5RshrOJkFG2rdlWNuTq/XphI0JOrN3nPUkRrdQRpAw="
Expand Down Expand Up @@ -51,13 +51,15 @@ matrix:
- JOB_NAME: "27_numpy_master"
- JOB_TAG=_NUMPY_DEV_master
- NUMPY_BUILD=master
- PANDAS_TESTING_MODE="numpy_deprecate"
allow_failures:
- python: 2.7
env:
- NOSE_ARGS="not slow and not network and not disabled"
- JOB_NAME: "27_numpy_master"
- JOB_TAG=_NUMPY_DEV_master
- NUMPY_BUILD=master
- PANDAS_TESTING_MODE="numpy_deprecate"

# allow importing from site-packages,
# so apt-get python-x works for system pythons
Expand Down
7 changes: 3 additions & 4 deletions ci/after_script.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

wget https://raw.github.com/y-p/ScatterCI-CLI/master/scatter_cli.py
chmod u+x scatter_cli.py
#wget https://raw.github.com/y-p/ScatterCI-CLI/master/scatter_cli.py
#chmod u+x scatter_cli.py

pip install -I requests==2.1.0
echo "${TRAVIS_PYTHON_VERSION:0:4}"
Expand All @@ -12,7 +12,6 @@ fi
# ScatterCI accepts a build log, but currently does nothing with it.
echo '' > /tmp/build.log

# These should be in the environment, but not in source control
# nore exposed in the build logs
#export SCATTERCI_ACCESS_KEY=
#export SCATTERCI_HOST=
Expand All @@ -22,6 +21,6 @@ ci/print_versions.py -j /tmp/env.json

# nose ran using "--with-xunit --xunit-file nosetest.xml" and generated /tmp/nosetest.xml
# Will timeout if server not available, and should not fail the build
python scatter_cli.py --xunit-file /tmp/nosetests.xml --log-file /tmp/build.log --env-file /tmp/env.json --build-name "$JOB_NAME" --succeed
#python scatter_cli.py --xunit-file /tmp/nosetests.xml --log-file /tmp/build.log --env-file /tmp/env.json --build-name "$JOB_NAME" --succeed

true # never fail because bad things happened here
7 changes: 0 additions & 7 deletions ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ fi
"$TRAVIS_BUILD_DIR"/ci/build_docs.sh 2>&1 > /tmp/doc.log &
# doc build log will be shown after tests

# export the testing mode
if [ -n "$NUMPY_BUILD" ]; then

export PANDAS_TESTING_MODE="numpy_deprecate"

fi

echo nosetests --exe -w /tmp -A "$NOSE_ARGS" pandas --with-xunit --xunit-file=/tmp/nosetests.xml
nosetests --exe -w /tmp -A "$NOSE_ARGS" pandas --with-xunit --xunit-file=/tmp/nosetests.xml

Expand Down
9 changes: 3 additions & 6 deletions pandas/src/testing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,7 @@ cpdef assert_almost_equal(a, b, bint check_less_precise=False):

# deal with differing dtypes
if check_less_precise:
dtype_a = np.dtype(type(a))
dtype_b = np.dtype(type(b))
if dtype_a.kind == 'f' and dtype_b == 'f':
decimal = 3
decimal = 3

if np.isinf(a):
assert np.isinf(b), "First object is inf, second isn't"
Expand All @@ -132,11 +129,11 @@ cpdef assert_almost_equal(a, b, bint check_less_precise=False):
if abs(fa) < 1e-5:
if not decimal_almost_equal(fa, fb, decimal):
assert False, (
'(very low values) expected %.5f but got %.5f' % (b, a)
'(very low values) expected %.5f but got %.5f, with decimal %d' % (fb, fa, decimal)
)
else:
if not decimal_almost_equal(1, fb / fa, decimal):
assert False, 'expected %.5f but got %.5f' % (b, a)
assert False, 'expected %.5f but got %.5f, with decimal %d' % (fb, fa, decimal)

else:
assert a == b, "%r != %r" % (a, b)
Expand Down
19 changes: 19 additions & 0 deletions pandas/tests/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,25 @@ def test_not_equal(self):
# ATM meta data is not checked in assert_series_equal
# self._assert_not_equal(Series(range(3)),Series(range(3),name='foo'),check_names=True)

def test_less_precise(self):
s1 = Series([0.12345],dtype='float64')
s2 = Series([0.12346],dtype='float64')

self.assertRaises(AssertionError, assert_series_equal, s1, s2)
self._assert_equal(s1,s2,check_less_precise=True)

s1 = Series([0.12345],dtype='float32')
s2 = Series([0.12346],dtype='float32')

self.assertRaises(AssertionError, assert_series_equal, s1, s2)
self._assert_equal(s1,s2,check_less_precise=True)

# even less than less precise
s1 = Series([0.1235],dtype='float32')
s2 = Series([0.1236],dtype='float32')

self.assertRaises(AssertionError, assert_series_equal, s1, s2)
self.assertRaises(AssertionError, assert_series_equal, s1, s2, True)

class TestRNGContext(unittest.TestCase):

Expand Down