Python numpy.uint64() Examples
The following are 30
code examples of numpy.uint64().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example #1
Source File: test_hashing.py From recruit with Apache License 2.0 | 7 votes |
def test_hash_collisions(): # Hash collisions are bad. # # https://github.com/pandas-dev/pandas/issues/14711#issuecomment-264885726 hashes = ["Ingrid-9Z9fKIZmkO7i7Cn51Li34pJm44fgX6DYGBNj3VPlOH50m7HnBlPxfIwFMrcNJNMP6PSgLmwWnInciMWrCSAlLEvt7JkJl4IxiMrVbXSa8ZQoVaq5xoQPjltuJEfwdNlO6jo8qRRHvD8sBEBMQASrRa6TsdaPTPCBo3nwIBpE7YzzmyH0vMBhjQZLx1aCT7faSEx7PgFxQhHdKFWROcysamgy9iVj8DO2Fmwg1NNl93rIAqC3mdqfrCxrzfvIY8aJdzin2cHVzy3QUJxZgHvtUtOLxoqnUHsYbNTeq0xcLXpTZEZCxD4PGubIuCNf32c33M7HFsnjWSEjE2yVdWKhmSVodyF8hFYVmhYnMCztQnJrt3O8ZvVRXd5IKwlLexiSp4h888w7SzAIcKgc3g5XQJf6MlSMftDXm9lIsE1mJNiJEv6uY6pgvC3fUPhatlR5JPpVAHNSbSEE73MBzJrhCAbOLXQumyOXigZuPoME7QgJcBalliQol7YZ9", # noqa "Tim-b9MddTxOWW2AT1Py6vtVbZwGAmYCjbp89p8mxsiFoVX4FyDOF3wFiAkyQTUgwg9sVqVYOZo09Dh1AzhFHbgij52ylF0SEwgzjzHH8TGY8Lypart4p4onnDoDvVMBa0kdthVGKl6K0BDVGzyOXPXKpmnMF1H6rJzqHJ0HywfwS4XYpVwlAkoeNsiicHkJUFdUAhG229INzvIAiJuAHeJDUoyO4DCBqtoZ5TDend6TK7Y914yHlfH3g1WZu5LksKv68VQHJriWFYusW5e6ZZ6dKaMjTwEGuRgdT66iU5nqWTHRH8WSzpXoCFwGcTOwyuqPSe0fTe21DVtJn1FKj9F9nEnR9xOvJUO7E0piCIF4Ad9yAIDY4DBimpsTfKXCu1vdHpKYerzbndfuFe5AhfMduLYZJi5iAw8qKSwR5h86ttXV0Mc0QmXz8dsRvDgxjXSmupPxBggdlqUlC828hXiTPD7am0yETBV0F3bEtvPiNJfremszcV8NcqAoARMe"] # noqa # These should be different. result1 = hash_array(np.asarray(hashes[0:1], dtype=object), "utf8") expected1 = np.array([14963968704024874985], dtype=np.uint64) tm.assert_numpy_array_equal(result1, expected1) result2 = hash_array(np.asarray(hashes[1:2], dtype=object), "utf8") expected2 = np.array([16428432627716348016], dtype=np.uint64) tm.assert_numpy_array_equal(result2, expected2) result = hash_array(np.asarray(hashes, dtype=object), "utf8") tm.assert_numpy_array_equal(result, np.concatenate([expected1, expected2], axis=0))
Example #2
Source File: test_numeric.py From recruit with Apache License 2.0 | 6 votes |
def test_constructor(self): idx = UInt64Index([1, 2, 3]) res = Index([1, 2, 3], dtype=np.uint64) tm.assert_index_equal(res, idx) idx = UInt64Index([1, 2**63]) res = Index([1, 2**63], dtype=np.uint64) tm.assert_index_equal(res, idx) idx = UInt64Index([1, 2**63]) res = Index([1, 2**63]) tm.assert_index_equal(res, idx) idx = Index([-1, 2**63], dtype=object) res = Index(np.array([-1, 2**63], dtype=object)) tm.assert_index_equal(res, idx)
Example #3
Source File: multi.py From recruit with Apache License 2.0 | 6 votes |
def _engine(self): # Calculate the number of bits needed to represent labels in each # level, as log2 of their sizes (including -1 for NaN): sizes = np.ceil(np.log2([len(l) + 1 for l in self.levels])) # Sum bit counts, starting from the _right_.... lev_bits = np.cumsum(sizes[::-1])[::-1] # ... in order to obtain offsets such that sorting the combination of # shifted codes (one for each level, resulting in a unique integer) is # equivalent to sorting lexicographically the codes themselves. Notice # that each level needs to be shifted by the number of bits needed to # represent the _previous_ ones: offsets = np.concatenate([lev_bits[1:], [0]]).astype('uint64') # Check the total number of bits needed for our representation: if lev_bits[0] > 64: # The levels would overflow a 64 bit uint - use Python integers: return MultiIndexPyIntEngine(self.levels, self.codes, offsets) return MultiIndexUIntEngine(self.levels, self.codes, offsets)
Example #4
Source File: hci.py From pyscf with Apache License 2.0 | 6 votes |
def argunique_ctypes(strs): nstrs, nset = strs.shape sort_idx = numpy.empty(nstrs, dtype=numpy.uint64) strs = numpy.asarray(strs, order='C') sort_idx = numpy.asarray(sort_idx, order='C') nstrs_ = numpy.array([nstrs]) libhci.argunique(strs.ctypes.data_as(ctypes.c_void_p), sort_idx.ctypes.data_as(ctypes.c_void_p), nstrs_.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(nset)) sort_idx = sort_idx[:nstrs_[0]] return sort_idx.tolist()
Example #5
Source File: test_casting.py From me-ica with GNU Lesser General Public License v2.1 | 6 votes |
def test_able_int_type(): # The integer type cabable of containing values for vals, exp_out in ( ([0, 1], np.uint8), ([0, 255], np.uint8), ([-1, 1], np.int8), ([0, 256], np.uint16), ([-1, 128], np.int16), ([0.1, 1], None), ([0, 2**16], np.uint32), ([-1, 2**15], np.int32), ([0, 2**32], np.uint64), ([-1, 2**31], np.int64), ([-1, 2**64-1], None), ([0, 2**64-1], np.uint64), ([0, 2**64], None)): assert_equal(able_int_type(vals), exp_out)
Example #6
Source File: chunkUtilTest.py From hsds with Apache License 2.0 | 6 votes |
def testChunkReadPoints2D(self): chunk_id = "c-00de6a9c-6aff5c35-15d5-3864dd-0740f8_3_4" chunk_layout = (100,100) chunk_arr = np.zeros((100,100)) chunk_arr[:,12] = 69 chunk_arr[12,:] = 96 point_arr = np.array([[312,498],[312,412],[355,412],[398,497]], dtype=np.uint64) arr = chunkReadPoints(chunk_id=chunk_id, chunk_layout=chunk_layout, chunk_arr=chunk_arr, point_arr=point_arr) self.assertEqual(arr.tolist(), [96,96,69,0]) point_arr = np.array([[312,498],[312,412],[355,412],[398,397]], dtype=np.uint64) try: chunkReadPoints(chunk_id=chunk_id, chunk_layout=chunk_layout, chunk_arr=chunk_arr, point_arr=point_arr) self.assertTrue(False) # expected exception except IndexError: pass # expected
Example #7
Source File: test_inference.py From recruit with Apache License 2.0 | 6 votes |
def test_maybe_convert_objects_uint64(self): # see gh-4471 arr = np.array([2**63], dtype=object) exp = np.array([2**63], dtype=np.uint64) tm.assert_numpy_array_equal(lib.maybe_convert_objects(arr), exp) # NumPy bug: can't compare uint64 to int64, as that # results in both casting to float64, so we should # make sure that this function is robust against it arr = np.array([np.uint64(2**63)], dtype=object) exp = np.array([2**63], dtype=np.uint64) tm.assert_numpy_array_equal(lib.maybe_convert_objects(arr), exp) arr = np.array([2, -1], dtype=object) exp = np.array([2, -1], dtype=np.int64) tm.assert_numpy_array_equal(lib.maybe_convert_objects(arr), exp) arr = np.array([2**63, -1], dtype=object) exp = np.array([2**63, -1], dtype=object) tm.assert_numpy_array_equal(lib.maybe_convert_objects(arr), exp)
Example #8
Source File: payload.py From baseband with GNU General Public License v3.0 | 6 votes |
def encode_16chan_2bit_fanout2_ft(values): """Encode payload for 16 channels using 2 bits, fan-out 2 (64 tracks).""" # words encode 32 values (above) in order ch&0x8, ch&0x3, sample, ch&0x4 # First reshape goes to time, sample, ch&0x8, ch&0x4, ch&0x3, # transpose makes this time, ch&0x8, ch&0x3, sample, ch&0x4. # second reshape future bytes, sample+ch&0x4. values = (values.reshape(-1, 2, 2, 2, 4).transpose(0, 2, 4, 1, 3) .reshape(-1, 4)) bitvalues = encode_2bit_base(values) # values are -3, -1, +1, 3 -> 00, 01, 10, 11; # get first bit (sign) as 1, second bit (magnitude) as 16 reorder_bits = np.array([0, 16, 1, 17], dtype=np.uint8) reorder_bits.take(bitvalues, out=bitvalues) bitvalues <<= np.array([0, 1, 2, 3], dtype=np.uint8) out = np.bitwise_or.reduce(bitvalues, axis=-1).ravel().view(np.uint64) return reorder64_Ft(out).view('<u8')
Example #9
Source File: test_constructors.py From recruit with Apache License 2.0 | 6 votes |
def test_constructor_overflow_int64(self): # see gh-14881 values = np.array([2 ** 64 - i for i in range(1, 10)], dtype=np.uint64) result = DataFrame({'a': values}) assert result['a'].dtype == np.uint64 # see gh-2355 data_scores = [(6311132704823138710, 273), (2685045978526272070, 23), (8921811264899370420, 45), (long(17019687244989530680), 270), (long(9930107427299601010), 273)] dtype = [('uid', 'u8'), ('score', 'u8')] data = np.zeros((len(data_scores),), dtype=dtype) data[:] = data_scores df_crawls = DataFrame(data) assert df_crawls['uid'].dtype == np.uint64
Example #10
Source File: test_indexing.py From recruit with Apache License 2.0 | 6 votes |
def test_setitem(self): df = self.df idx = self.idx # setitem df['C'] = idx assert_series_equal(df['C'], Series(idx, name='C')) df['D'] = 'foo' df['D'] = idx assert_series_equal(df['D'], Series(idx, name='D')) del df['D'] # With NaN: because uint64 has no NaN element, # the column should be cast to object. df2 = df.copy() df2.iloc[1, 1] = pd.NaT df2.iloc[1, 2] = pd.NaT result = df2['B'] assert_series_equal(notna(result), Series( [True, False, True], name='B')) assert_series_equal(df2.dtypes, Series([np.dtype('uint64'), np.dtype('O'), np.dtype('O')], index=['A', 'B', 'C']))
Example #11
Source File: model.py From modelforge with Apache License 2.0 | 6 votes |
def squeeze_bits(arr: numpy.ndarray) -> numpy.ndarray: """Return a copy of an integer numpy array with the minimum bitness.""" assert arr.dtype.kind in ("i", "u") if arr.size == 0: return arr if arr.dtype.kind == "i": assert arr.min() >= 0 mlbl = int(arr.max()).bit_length() if mlbl <= 8: dtype = numpy.uint8 elif mlbl <= 16: dtype = numpy.uint16 elif mlbl <= 32: dtype = numpy.uint32 else: dtype = numpy.uint64 return arr.astype(dtype)
Example #12
Source File: test_numeric.py From recruit with Apache License 2.0 | 6 votes |
def test_coerce_uint64_conflict(self): # see gh-17007 and gh-17125 # # Still returns float despite the uint64-nan conflict, # which would normally force the casting to object. df = pd.DataFrame({"a": [200, 300, "", "NaN", 30000000000000000000]}) expected = pd.Series([200, 300, np.nan, np.nan, 30000000000000000000], dtype=float, name="a") result = to_numeric(df["a"], errors="coerce") tm.assert_series_equal(result, expected) s = pd.Series(["12345678901234567890", "1234567890", "ITEM"]) expected = pd.Series([12345678901234567890, 1234567890, np.nan], dtype=float) result = to_numeric(s, errors="coerce") tm.assert_series_equal(result, expected) # For completeness, check against "ignore" and "raise" result = to_numeric(s, errors="ignore") tm.assert_series_equal(result, s) msg = "Unable to parse string" with pytest.raises(ValueError, match=msg): to_numeric(s, errors="raise")
Example #13
Source File: payload.py From baseband with GNU General Public License v3.0 | 6 votes |
def reorder64_Ft(x): """Reorder 64-track bits to bring signs & magnitudes together. Special version for the Ft station, which has unusual settings. """ return (((x & 0xFFFFFAAFFFFFFAAF)) | ((x & 0x0000050000000500) >> 4) | ((x & 0x0000005000000050) << 4)) # Check on 2015-JUL-12: C code: 738811025863578102 -> 738829572664316278 # 118, 209, 53, 244, 148, 217, 64, 10 # reorder64(np.array([738811025863578102], dtype=np.uint64)) # # array([738829572664316278], dtype=uint64) # reorder64(np.array([738811025863578102], dtype=np.uint64)).view(np.uint8) # # array([118, 209, 53, 244, 148, 217, 64, 10], dtype=uint8) # decode_2bit_64track_fanout4( # np.array([738811025863578102], dtype=np.int64)).astype(int).T # -1 1 3 1 array([[-1, 1, 3, 1], # 1 1 3 -3 [ 1, 1, 3, -3], # 1 -3 1 3 [ 1, -3, 1, 3], # -3 1 3 3 [-3, 1, 3, 3], # -3 1 1 -1 [-3, 1, 1, -1], # -3 -3 -3 1 [-3, -3, -3, 1], # 1 -1 1 3 [ 1, -1, 1, 3], # -1 -1 -3 -3 [-1, -1, -3, -3]])
Example #14
Source File: test_random.py From recruit with Apache License 2.0 | 6 votes |
def test_int64_uint64_corner_case(self): # When stored in Numpy arrays, `lbnd` is casted # as np.int64, and `ubnd` is casted as np.uint64. # Checking whether `lbnd` >= `ubnd` used to be # done solely via direct comparison, which is incorrect # because when Numpy tries to compare both numbers, # it casts both to np.float64 because there is # no integer superset of np.int64 and np.uint64. However, # `ubnd` is too large to be represented in np.float64, # causing it be round down to np.iinfo(np.int64).max, # leading to a ValueError because `lbnd` now equals # the new `ubnd`. dt = np.int64 tgt = np.iinfo(np.int64).max lbnd = np.int64(np.iinfo(np.int64).max) ubnd = np.uint64(np.iinfo(np.int64).max + 1) # None of these function calls should # generate a ValueError now. actual = np.random.randint(lbnd, ubnd, dtype=dt) assert_equal(actual, tgt)
Example #15
Source File: test_other.py From recruit with Apache License 2.0 | 6 votes |
def test_sum_uint64_overflow(): # see gh-14758 # Convert to uint64 and don't overflow df = pd.DataFrame([[1, 2], [3, 4], [5, 6]], dtype=object) df = df + 9223372036854775807 index = pd.Index([9223372036854775808, 9223372036854775810, 9223372036854775812], dtype=np.uint64) expected = pd.DataFrame({1: [9223372036854775809, 9223372036854775811, 9223372036854775813]}, index=index) expected.index.name = 0 result = df.groupby(0).sum() tm.assert_frame_equal(result, expected)
Example #16
Source File: test_inference.py From recruit with Apache License 2.0 | 5 votes |
def test_convert_numeric_uint64(self): arr = np.array([2**63], dtype=object) exp = np.array([2**63], dtype=np.uint64) tm.assert_numpy_array_equal(lib.maybe_convert_numeric(arr, set()), exp) arr = np.array([str(2**63)], dtype=object) exp = np.array([2**63], dtype=np.uint64) tm.assert_numpy_array_equal(lib.maybe_convert_numeric(arr, set()), exp) arr = np.array([np.uint64(2**63)], dtype=object) exp = np.array([2**63], dtype=np.uint64) tm.assert_numpy_array_equal(lib.maybe_convert_numeric(arr, set()), exp)
Example #17
Source File: multi.py From recruit with Apache License 2.0 | 5 votes |
def _hashed_values(self): """ return a uint64 ndarray of my hashed values """ from pandas.core.util.hashing import hash_tuples return hash_tuples(self)
Example #18
Source File: test_algos.py From recruit with Apache License 2.0 | 5 votes |
def test_uint64_overflow(self): exp = Series([2**63], dtype=np.uint64) s = Series([1, 2**63, 2**63], dtype=np.uint64) tm.assert_series_equal(algos.mode(s), exp) exp = Series([1, 2**63], dtype=np.uint64) s = Series([1, 2**63], dtype=np.uint64) tm.assert_series_equal(algos.mode(s), exp)
Example #19
Source File: test_algos.py From recruit with Apache License 2.0 | 5 votes |
def test_get_unique(self): s = Series([1, 2, 2**63, 2**63], dtype=np.uint64) exp = np.array([1, 2, 2**63], dtype=np.uint64) tm.assert_numpy_array_equal(s.unique(), exp)
Example #20
Source File: test_algos.py From recruit with Apache License 2.0 | 5 votes |
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=writable) m = ht.UInt64HashTable() m.map_locations(xs) tm.assert_numpy_array_equal(m.lookup(xs), np.arange(len(xs), dtype=np.int64))
Example #21
Source File: test_algos.py From recruit with Apache License 2.0 | 5 votes |
def test_value_counts_uint64(self): arr = np.array([2**63], dtype=np.uint64) expected = Series([1], index=[2**63]) result = algos.value_counts(arr) tm.assert_series_equal(result, expected) arr = np.array([-1, 2**63], dtype=object) expected = Series([1, 1], index=[-1, 2**63]) result = algos.value_counts(arr) # 32-bit linux has a different ordering if not compat.is_platform_32bit(): tm.assert_series_equal(result, expected)
Example #22
Source File: multi.py From recruit with Apache License 2.0 | 5 votes |
def _hashed_indexing_key(self, key): """ validate and return the hash for the provided key *this is internal for use for the cython routines* Parameters ---------- key : string or tuple Returns ------- np.uint64 Notes ----- we need to stringify if we have mixed levels """ from pandas.core.util.hashing import hash_tuples, hash_tuple if not isinstance(key, tuple): return hash_tuples(key) if not len(key) == self.nlevels: raise KeyError def f(k, stringify): if stringify and not isinstance(k, compat.string_types): k = str(k) return k key = tuple(f(k, stringify) for k, stringify in zip(key, self._have_mixed_levels)) return hash_tuple(key)
Example #23
Source File: test_algos.py From recruit with Apache License 2.0 | 5 votes |
def test_uint64_overflow(self): s = Series([1, 2, 2**63, 2**63], dtype=np.uint64) exp = np.array([1, 2, 2**63], dtype=np.uint64) tm.assert_numpy_array_equal(algos.unique(s), exp)
Example #24
Source File: test_algos.py From recruit with Apache License 2.0 | 5 votes |
def test_deprecate_order(self): # gh 19727 - check warning is raised for deprecated keyword, order. # Test not valid once order keyword is removed. data = np.array([2**63, 1, 2**63], dtype=np.uint64) with tm.assert_produces_warning(expected_warning=FutureWarning): algos.factorize(data, order=True) with tm.assert_produces_warning(False): algos.factorize(data)
Example #25
Source File: test_numeric.py From recruit with Apache License 2.0 | 5 votes |
def test_join_outer(self): other = UInt64Index(2**63 + np.array( [7, 12, 25, 1, 2, 10], dtype='uint64')) other_mono = UInt64Index(2**63 + np.array( [1, 2, 7, 10, 12, 25], dtype='uint64')) # not monotonic # guarantee of sortedness res, lidx, ridx = self.index.join(other, how='outer', return_indexers=True) noidx_res = self.index.join(other, how='outer') tm.assert_index_equal(res, noidx_res) eres = UInt64Index(2**63 + np.array( [0, 1, 2, 7, 10, 12, 15, 20, 25], dtype='uint64')) elidx = np.array([0, -1, -1, -1, 1, -1, 2, 3, 4], dtype=np.intp) eridx = np.array([-1, 3, 4, 0, 5, 1, -1, -1, 2], dtype=np.intp) assert isinstance(res, UInt64Index) tm.assert_index_equal(res, eres) tm.assert_numpy_array_equal(lidx, elidx) tm.assert_numpy_array_equal(ridx, eridx) # monotonic res, lidx, ridx = self.index.join(other_mono, how='outer', return_indexers=True) noidx_res = self.index.join(other_mono, how='outer') tm.assert_index_equal(res, noidx_res) elidx = np.array([0, -1, -1, -1, 1, -1, 2, 3, 4], dtype=np.intp) eridx = np.array([-1, 0, 1, 2, 3, 4, -1, -1, 5], dtype=np.intp) assert isinstance(res, UInt64Index) tm.assert_index_equal(res, eres) tm.assert_numpy_array_equal(lidx, elidx) tm.assert_numpy_array_equal(ridx, eridx)
Example #26
Source File: test_numeric.py From recruit with Apache License 2.0 | 5 votes |
def test_join_non_int_index(self): other = Index(2**63 + np.array( [1, 5, 7, 10, 20], dtype='uint64'), dtype=object) outer = self.index.join(other, how='outer') outer2 = other.join(self.index, how='outer') expected = Index(2**63 + np.array( [0, 1, 5, 7, 10, 15, 20, 25], dtype='uint64')) tm.assert_index_equal(outer, outer2) tm.assert_index_equal(outer, expected) inner = self.index.join(other, how='inner') inner2 = other.join(self.index, how='inner') expected = Index(2**63 + np.array([10, 20], dtype='uint64')) tm.assert_index_equal(inner, inner2) tm.assert_index_equal(inner, expected) left = self.index.join(other, how='left') tm.assert_index_equal(left, self.index.astype(object)) left2 = other.join(self.index, how='left') tm.assert_index_equal(left2, other) right = self.index.join(other, how='right') tm.assert_index_equal(right, other) right2 = other.join(self.index, how='right') tm.assert_index_equal(right2, self.index.astype(object))
Example #27
Source File: test_numeric.py From recruit with Apache License 2.0 | 5 votes |
def test_join_left(self): other = UInt64Index(2**63 + np.array( [7, 12, 25, 1, 2, 10], dtype='uint64')) other_mono = UInt64Index(2**63 + np.array( [1, 2, 7, 10, 12, 25], dtype='uint64')) # not monotonic res, lidx, ridx = self.index.join(other, how='left', return_indexers=True) eres = self.index eridx = np.array([-1, 5, -1, -1, 2], dtype=np.intp) assert isinstance(res, UInt64Index) tm.assert_index_equal(res, eres) assert lidx is None tm.assert_numpy_array_equal(ridx, eridx) # monotonic res, lidx, ridx = self.index.join(other_mono, how='left', return_indexers=True) eridx = np.array([-1, 3, -1, -1, 5], dtype=np.intp) assert isinstance(res, UInt64Index) tm.assert_index_equal(res, eres) assert lidx is None tm.assert_numpy_array_equal(ridx, eridx) # non-unique idx = UInt64Index(2**63 + np.array([1, 1, 2, 5], dtype='uint64')) idx2 = UInt64Index(2**63 + np.array([1, 2, 5, 7, 9], dtype='uint64')) res, lidx, ridx = idx2.join(idx, how='left', return_indexers=True) # 1 is in idx2, so it should be x2 eres = UInt64Index(2**63 + np.array( [1, 1, 2, 5, 7, 9], dtype='uint64')) eridx = np.array([0, 1, 2, 3, -1, -1], dtype=np.intp) elidx = np.array([0, 0, 1, 2, 3, 4], dtype=np.intp) tm.assert_index_equal(res, eres) tm.assert_numpy_array_equal(lidx, elidx) tm.assert_numpy_array_equal(ridx, eridx)
Example #28
Source File: test_numeric.py From recruit with Apache License 2.0 | 5 votes |
def test_join_inner(self): other = UInt64Index(2**63 + np.array( [7, 12, 25, 1, 2, 10], dtype='uint64')) other_mono = UInt64Index(2**63 + np.array( [1, 2, 7, 10, 12, 25], dtype='uint64')) # not monotonic res, lidx, ridx = self.index.join(other, how='inner', return_indexers=True) # no guarantee of sortedness, so sort for comparison purposes ind = res.argsort() res = res.take(ind) lidx = lidx.take(ind) ridx = ridx.take(ind) eres = UInt64Index(2**63 + np.array([10, 25], dtype='uint64')) elidx = np.array([1, 4], dtype=np.intp) eridx = np.array([5, 2], dtype=np.intp) assert isinstance(res, UInt64Index) tm.assert_index_equal(res, eres) tm.assert_numpy_array_equal(lidx, elidx) tm.assert_numpy_array_equal(ridx, eridx) # monotonic res, lidx, ridx = self.index.join(other_mono, how='inner', return_indexers=True) res2 = self.index.intersection(other_mono) tm.assert_index_equal(res, res2) elidx = np.array([1, 4], dtype=np.intp) eridx = np.array([3, 5], dtype=np.intp) assert isinstance(res, UInt64Index) tm.assert_index_equal(res, eres) tm.assert_numpy_array_equal(lidx, elidx) tm.assert_numpy_array_equal(ridx, eridx)
Example #29
Source File: test_common.py From recruit with Apache License 2.0 | 5 votes |
def test_outside_int64_uint64_range(all_parsers, val): # These numbers fall just outside the int64-uint64 # range, so they should be parsed as string. parser = all_parsers result = parser.read_csv(StringIO(str(val)), header=None) expected = DataFrame([str(val)]) tm.assert_frame_equal(result, expected)
Example #30
Source File: hashing.py From recruit with Apache License 2.0 | 5 votes |
def _combine_hash_arrays(arrays, num_items): """ Parameters ---------- arrays : generator num_items : int Should be the same as CPython's tupleobject.c """ try: first = next(arrays) except StopIteration: return np.array([], dtype=np.uint64) arrays = itertools.chain([first], arrays) mult = np.uint64(1000003) out = np.zeros_like(first) + np.uint64(0x345678) for i, a in enumerate(arrays): inverse_i = num_items - i out ^= a out *= mult mult += np.uint64(82520 + inverse_i + inverse_i) assert i + 1 == num_items, 'Fed in wrong num_items' out += np.uint64(97531) return out