Skip to content
Prev Previous commit
Next Next commit
Test writable arrays with parameters
  • Loading branch information
xhochy committed Jul 7, 2018
commit e0b709824c6a7c11019fd244c70c4fbb99eae2c2
15 changes: 9 additions & 6 deletions pandas/tests/test_algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1077,19 +1077,21 @@ class TestGroupVarFloat32(GroupVarTestMixin):

class TestHashTable(object):

def test_lookup_nan(self):
@pytest.mark.parametrize('writable', [True, False])
def test_lookup_nan(self, writable):
xs = np.array([2.718, 3.14, np.nan, -7, 5, 2, 3])
# GH 21688 ensure we can deal with readonly memory views
xs.setflags(write=False)
xs.setflags(write=writable)
m = ht.Float64HashTable()
m.map_locations(xs)
tm.assert_numpy_array_equal(m.lookup(xs), np.arange(len(xs),
dtype=np.int64))

def test_lookup_overflow(self):
@pytest.mark.parametrize('writable', [True, False])
def test_lookup_overflow(self, writable):
xs = np.array([1, 2, 2**63], dtype=np.uint64)
# GH 21688 ensure we can deal with readonly memory views
xs.setflags(write=False)
xs.setflags(write=writable)
m = ht.UInt64HashTable()
m.map_locations(xs)
tm.assert_numpy_array_equal(m.lookup(xs), np.arange(len(xs),
Expand All @@ -1100,14 +1102,15 @@ def test_get_unique(self):
exp = np.array([1, 2, 2**63], dtype=np.uint64)
tm.assert_numpy_array_equal(s.unique(), exp)

def test_vector_resize(self):
@pytest.mark.parametrize('writable', [True, False])
def test_vector_resize(self, writable):
# Test for memory errors after internal vector
# reallocations (pull request #7157)

def _test_vector_resize(htable, uniques, dtype, nvals, safely_resizes):
vals = np.array(np.random.randn(1000), dtype=dtype)
# GH 21688 ensure we can deal with readonly memory views
vals.setflags(write=False)
vals.setflags(write=writable)
# get_labels may append to uniques
htable.get_labels(vals[:nvals], uniques, 0, -1)
# to_array() set an external_view_exists flag on uniques.
Expand Down