def test_NumpyArray(): array = ak.layout.NumpyArray( np.array(["1chchc", "1chchc", "2sss", "3", "4", "5"], dtype=object), parameters={"__array__": "categorical"}, ) assert ak.is_valid(ak.Array(array)) is False # FIXME? assert array.is_unique() is False array2 = ak.layout.NumpyArray(np.array([5, 6, 1, 3, 4, 5])) assert array2.is_unique() is False
def test_second_issue(): a = ak.layout.NumpyArray(np.arange(122)) idx = ak.layout.Index64([0, 2, 4, 6, 8, 10, 12]) a = ak.layout.ListOffsetArray64(idx, a) idx = ak.layout.Index64([0, -1, 1, 2, -1, 3, 4, 5]) a = ak.layout.IndexedOptionArray64(idx, a) a = ak.Array(a) assert ak.is_valid(a) assert ak.is_valid(ak.argsort(a)) assert a[ak.argsort(a)].tolist() == [ [0, 1], None, [2, 3], [4, 5], None, [6, 7], [8, 9], [10, 11], ]
def test_ByteMaskedArray_setidentities(): content = ak.from_iter( [[0.0, 1.1, 2.2], [], [3.3, 4.4], [5.5], [6.6, 7.7, 8.8, 9.9], [321]], highlevel=False, ) mask = ak.layout.Index8(np.array([0, 0, 1, 1, 0], dtype=np.int8)) array = ak.layout.ByteMaskedArray(mask, content, valid_when=False) assert ak.to_list(array) == [[0.0, 1.1, 2.2], [], None, None, [6.6, 7.7, 8.8, 9.9]] array.setidentities() assert np.asarray(array.identities).tolist() == [[0], [1], [2], [3], [4]] assert np.asarray(array.content.identities).tolist() == [ [0], [1], [2], [3], [4], [-1], ] assert ak.is_valid(ak.Array(array))
def test_categorical_is_valid(): # validate a categorical array by its content arr = ak.Array([2019, 2020, 2021, 2020, 2019]) categorical = ak.to_categorical(arr) assert ak.is_valid(categorical)
def test(): nums = [ [ 17, 11, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], [ 17, 11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 17, 11, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], [ 17, 11, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], [ 17, 11, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], ] sample = [] for outer in nums: sample.append([]) for inner in outer: sample[-1].append([0] * inner) assert ak.is_valid(ak.count(sample, axis=0))
def _build_standard_jme_lookup( name, layout, pars, nBinnedVars, nBinColumns, nEvalVars, formula, nParms, columns, dtypes, interpolatedFunc=False, ): # the first bin is always usual for JECs # the next bins may vary in number, so they're jagged arrays... yay bins = {} offset_col = 0 offset_name = 1 bin_order = [] for i in range(nBinnedVars): binMins = None binMaxs = None if i == 0: binMins = numpy.unique(pars[columns[0]]) binMaxs = numpy.unique(pars[columns[1]]) if numpy.all(binMins[1:] == binMaxs[:-1]): bins[layout[i + offset_name]] = numpy.union1d(binMins, binMaxs) else: warnings.warn( "binning for file for %s is malformed in variable %s" % (name, layout[i + offset_name]) ) bins[layout[i + offset_name]] = numpy.union1d(binMins, binMaxs[-1:]) else: counts = numpy.zeros(0, dtype=numpy.int64) allBins = numpy.zeros(0, dtype=numpy.double) for binMin in bins[bin_order[0]][:-1]: binMins = numpy.unique( pars[numpy.where(pars[columns[0]] == binMin)][ columns[i + offset_col] ] ) binMaxs = numpy.unique( pars[numpy.where(pars[columns[0]] == binMin)][ columns[i + offset_col + 1] ] ) theBins = None if numpy.all(binMins[1:] == binMaxs[:-1]): theBins = numpy.union1d(binMins, binMaxs) else: warnings.warn( "binning for file for %s is malformed in variable %s" % (name, layout[i + offset_name]) ) theBins = numpy.union1d(binMins, binMaxs[-1:]) allBins = numpy.append(allBins, theBins) counts = numpy.append(counts, theBins.size) bins[layout[i + offset_name]] = awkward.unflatten(allBins, counts) bin_order.append(layout[i + offset_name]) offset_col += 1 # skip nvars to the variable columns # the columns here define clamps for the variables defined in columns[] # ----> clamps can be different from bins # ----> if there is more than one binning variable this array is jagged # ----> just make it jagged all the time clamp_mins = {} clamp_maxs = {} var_order = [] offset_col = 2 * nBinnedVars + 1 offset_name = nBinnedVars + 2 jagged_counts = numpy.ones(bins[bin_order[0]].size - 1, dtype=numpy.int64) if len(bin_order) > 1: jagged_counts = numpy.maximum( awkward.num(bins[bin_order[1]]) - 1, 0 ) # need counts-1 since we only care about Nbins for i in range(nEvalVars): var_order.append(layout[i + offset_name]) if not interpolatedFunc: clamp_mins[layout[i + offset_name]] = awkward.unflatten( numpy.atleast_1d(pars[columns[i + offset_col]]), jagged_counts ) clamp_maxs[layout[i + offset_name]] = awkward.unflatten( numpy.atleast_1d(pars[columns[i + offset_col + 1]]), jagged_counts ) assert awkward.is_valid(clamp_mins[layout[i + offset_name]]) assert awkward.is_valid(clamp_maxs[layout[i + offset_name]]) offset_col += 1 # now get the parameters, which we will look up with the clamped values parms = [] parm_order = [] offset_col = 2 * nBinnedVars + 1 + int(not interpolatedFunc) * 2 * nEvalVars for i in range(nParms): jag = awkward.unflatten(pars[columns[i + offset_col]], jagged_counts) assert awkward.is_valid(jag) parms.append(jag) parm_order.append("p%i" % (i)) wrapped_up = {} wrapped_up[(name, "jme_standard_function")] = ( formula, (bins, bin_order), (clamp_mins, clamp_maxs, var_order), (parms, parm_order), ) return wrapped_up
def test_but_first_fix_sort(): assert ak.is_valid(ak.sort(ak.Array(["one", "two", "three"]), axis=-1))