Exemple #1
0
def test_unique_for_nan_objects_tuple():
    table = ht.PyObjectHashTable()
    keys = np.array(
        [1] + [(1.0, (float("nan"), 1.0)) for i in range(50)], dtype=np.object_
    )
    unique = table.unique(keys)
    assert len(unique) == 2
Exemple #2
0
 def test_nan_in_tuple(self):
     nan1 = (float("nan"),)
     nan2 = (float("nan"),)
     assert nan1[0] is not nan2[0]
     table = ht.PyObjectHashTable()
     table.set_item(nan1, 42)
     assert table.get_item(nan2) == 42
Exemple #3
0
 def test_nan_complex_both(self):
     nan1 = complex(float("nan"), float("nan"))
     nan2 = complex(float("nan"), float("nan"))
     assert nan1 is not nan2
     table = ht.PyObjectHashTable()
     table.set_item(nan1, 42)
     assert table.get_item(nan2) == 42
Exemple #4
0
 def test_nan_float(self):
     nan1 = float("nan")
     nan2 = float("nan")
     assert nan1 is not nan2
     table = ht.PyObjectHashTable()
     table.set_item(nan1, 42)
     assert table.get_item(nan2) == 42
Exemple #5
0
def unique1d(values):
    """
    Hash table-based unique
    """
    if np.issubdtype(values.dtype, np.floating):
        table = htable.Float64HashTable(len(values))
        uniques = np.array(table.unique(_ensure_float64(values)),
                           dtype=np.float64)
    elif np.issubdtype(values.dtype, np.datetime64):
        table = htable.Int64HashTable(len(values))
        uniques = table.unique(_ensure_int64(values))
        uniques = uniques.view('M8[ns]')
    elif np.issubdtype(values.dtype, np.timedelta64):
        table = htable.Int64HashTable(len(values))
        uniques = table.unique(_ensure_int64(values))
        uniques = uniques.view('m8[ns]')
    elif np.issubdtype(values.dtype, np.signedinteger):
        table = htable.Int64HashTable(len(values))
        uniques = table.unique(_ensure_int64(values))
    elif np.issubdtype(values.dtype, np.unsignedinteger):
        table = htable.UInt64HashTable(len(values))
        uniques = table.unique(_ensure_uint64(values))
    else:

        # its cheaper to use a String Hash Table than Object
        if lib.infer_dtype(values) in ['string']:
            table = htable.StringHashTable(len(values))
        else:
            table = htable.PyObjectHashTable(len(values))

        uniques = table.unique(_ensure_object(values))

    return uniques
Exemple #6
0
 def test_nan_in_nested_tuple(self):
     nan1 = (1, (2, (float("nan"),)))
     nan2 = (1, (2, (float("nan"),)))
     other = (1, 2)
     table = ht.PyObjectHashTable()
     table.set_item(nan1, 42)
     assert table.get_item(nan2) == 42
     with pytest.raises(KeyError, match=None) as error:
         table.get_item(other)
     assert str(error.value) == str(other)
Exemple #7
0
 def test_nan_complex_imag(self):
     nan1 = complex(1, float("nan"))
     nan2 = complex(1, float("nan"))
     other = complex(2, float("nan"))
     assert nan1 is not nan2
     table = ht.PyObjectHashTable()
     table.set_item(nan1, 42)
     assert table.get_item(nan2) == 42
     with pytest.raises(KeyError, match=None) as error:
         table.get_item(other)
     assert str(error.value) == str(other)
Exemple #8
0
def test_unique_for_nan_objects_floats():
    table = ht.PyObjectHashTable()
    keys = np.array([float("nan") for i in range(50)], dtype=np.object_)
    unique = table.unique(keys)
    assert len(unique) == 1