def test_0459_types(): plain_plain = ak.Array([0.0, 1.1, 2.2, 3.3, 4.4]) array_plain = ak.with_parameter(plain_plain, "__array__", "zoinks") plain_isdoc = ak.with_parameter(plain_plain, "__doc__", "This is a zoink.") array_isdoc = ak.with_parameter(array_plain, "__doc__", "This is a zoink.") assert ak.parameters(plain_plain) == {} assert ak.parameters(array_plain) == {"__array__": "zoinks"} assert ak.parameters(plain_isdoc) == {"__doc__": "This is a zoink."} assert ak.parameters(array_isdoc) == { "__array__": "zoinks", "__doc__": "This is a zoink.", } assert ak.type(plain_plain) == ak.type(plain_plain) assert ak.type(array_plain) == ak.type(array_plain) assert ak.type(plain_isdoc) == ak.type(plain_isdoc) assert ak.type(array_isdoc) == ak.type(array_isdoc) assert ak.type(plain_plain) != ak.type(array_plain) assert ak.type(array_plain) != ak.type(plain_plain) assert ak.type(plain_plain) == ak.type(plain_isdoc) assert ak.type(plain_isdoc) == ak.type(plain_plain) assert ak.type(array_plain) == ak.type(array_isdoc) assert ak.type(array_isdoc) == ak.type(array_plain) assert ak.type(plain_isdoc) != ak.type(array_isdoc) assert ak.type(array_isdoc) != ak.type(plain_isdoc)
def test_arraytype_3(): text = str( ak.with_parameter(ak.Array([[1, 2, 3], [], [4, 5]]), "wonky", { "other": "JSON" }).type) parsedtype = ak.types.from_datashape(text) assert str(parsedtype) == text
def test_arraytype_2(): text = str( ak.with_parameter(ak.Array([[1, 2, 3], [], [4, 5]]), "wonky", "string").type) parsedtype = ak.types.from_datashape(text, True) assert isinstance(parsedtype, ak.types.ArrayType) assert str(parsedtype) == text
def test_jim21(): text = str( ak.with_parameter(ak.Array([1, 2, 3, None, [1], [1, 2], [1, 2, 3]]), "wonky", "string").type) print(text) parsedtype = deduce_type(text) assert str(parsedtype) == text
def test_jim19(): text = str( ak.with_parameter(ak.to_regular(ak.Array([[1, 2], [3, 4], [5, 6]])), "wonky", "string").type) print(text) parsedtype = deduce_type(text) assert str(parsedtype) == text
def test_jim16(): text = str( ak.with_parameter(ak.Array([(1, 1.1), (2, 2.2), (3, 3.3)]), "wonky", "string").type) print(text) parsedtype = deduce_type(text) assert str(parsedtype) == text
def test_jim8(): text = str( ak.with_parameter(ak.Array([[1, 2, 3], [], [4, 5]]), "wonky", "string").type) print(text) parsedtype = deduce_type(text) assert str(parsedtype) == text
def test_jim9(): text = str( ak.with_parameter(ak.Array([[1, 2, 3], [], [4, 5]]), "wonky", { "other": "JSON" }).type) print(text) parsedtype = deduce_type(text) assert str(parsedtype) == text
def test_arraytype_15(): text = str( ak.with_parameter( ak.Array([1, 2, 3, None, [1], [1, 2], [1, 2, 3]]), "wonky", "string" ).type ) parsedtype = ak.types.from_datashape(text) assert str(parsedtype) == text
def test_arraytype_13(): text = str( ak.with_parameter( ak.to_regular(ak.Array([[1, 2], [3, 4], [5, 6]])), "wonky", "string" ).type ) parsedtype = ak.types.from_datashape(text) assert str(parsedtype) == text
def test_arraytype_10(): text = str( ak.with_parameter( ak.Array([(1, 1.1), (2, 2.2), (3, 3.3)]), "wonky", "string" ).type ) parsedtype = ak.types.from_datashape(text) assert str(parsedtype) == text
def test_arraytype_8(): text = str( ak.with_parameter( ak.Array([{"x": 1, "y": 1.1}, {"x": 2, "y": 2.2}, {"x": 3, "y": 3.3}]), "wonky", "string", ).type ) parsedtype = ak.types.from_datashape(text) assert str(parsedtype) == text
def add_systematic( self, name: str, kind: str, what: Union[str, List[str], Tuple[str]], varying_function: Callable, ): """ name: str, name of the systematic variation / uncertainty source kind: str, the name of the kind of systematic variation what: Union[str, List[str], Tuple[str]], name what gets varied, this could be a list or tuple of column names varying_function: Union[function, bound method], a function that describes how 'what' is varied, it must close over all non-event-data arguments. """ self._ensure_systematics() if name in awkward.fields(self["__systematics__"]): raise ValueError( f"{name} already exists as a systematic for this object!") if kind not in self._systematic_kinds: raise ValueError( f"{kind} is not an available systematics type, please add it and try again!" ) wrap = partial(awkward_rewrap, like_what=self["__systematics__"], gfunc=rewrap_recordarray) flat = (self if isinstance(self, coffea.nanoevents.methods.base.NanoEvents) else awkward.flatten(self)) if what == "weight" and "__ones__" not in awkward.fields( flat["__systematics__"]): flat["__systematics__", "__ones__"] = numpy.ones(len(flat), dtype=numpy.float32) rendered_type = flat.layout.parameters["__record__"] as_syst_type = awkward.with_parameter(flat, "__record__", kind) as_syst_type._build_variations(name, what, varying_function) variations = as_syst_type.describe_variations() flat["__systematics__", name] = awkward.zip( { v: getattr(as_syst_type, v)(name, what, rendered_type) for v in variations }, depth_limit=1, with_name=f"{name}Systematics", ) self["__systematics__"] = wrap(flat["__systematics__"]) self.behavior[("__typestr__", f"{name}Systematics")] = f"{kind}"
def test_jim14(): text = str( ak.with_parameter( ak.Array([{ "x": 1, "y": 1.1 }, { "x": 2, "y": 2.2 }, { "x": 3, "y": 3.3 }]), "wonky", "string", ).type) print(text) parsedtype = deduce_type(text) assert str(parsedtype) == text
def _element_link_multiple(events, obj, link_field, with_name=None): link = obj[link_field] key = link.m_persKey index = link.m_persIndex unique_keys = [ i for i in numpy.unique( awkward.to_numpy(awkward.flatten(key, axis=None))) if i != 0 ] def where(unique_keys): target_name = _hash_to_target_name[unique_keys[0]] mask = key == unique_keys[0] global_index = _get_global_index(events[target_name], obj._eventindex, index) global_index = awkward.where(mask, global_index, -1) links = events[target_name]._apply_global_index(global_index) if len(unique_keys) == 1: return links return awkward.where(mask, links, where(unique_keys[1:])) out = where(unique_keys).mask[key != 0] if with_name is not None: out = awkward.with_parameter(out, "__record__", with_name) return out
def test_0459(): plain_plain = ak.Array([0.0, 1.1, 2.2, 3.3, 4.4]) array_plain = ak.with_parameter(plain_plain, "__array__", "zoinks") plain_isdoc = ak.with_parameter(plain_plain, "__doc__", "This is a zoink.") array_isdoc = ak.with_parameter(array_plain, "__doc__", "This is a zoink.") assert ak.parameters(plain_plain) == {} assert ak.parameters(array_plain) == {"__array__": "zoinks"} assert ak.parameters(plain_isdoc) == {"__doc__": "This is a zoink."} assert ak.parameters(array_isdoc) == { "__array__": "zoinks", "__doc__": "This is a zoink.", } assert ak.parameters(ak.concatenate([plain_plain, plain_plain])) == {} assert ak.parameters(ak.concatenate([array_plain, array_plain])) == { "__array__": "zoinks" } assert ak.parameters(ak.concatenate([plain_isdoc, plain_isdoc])) == { "__doc__": "This is a zoink." } assert ak.parameters(ak.concatenate([array_isdoc, array_isdoc])) == { "__array__": "zoinks", "__doc__": "This is a zoink.", } assert isinstance( ak.concatenate([plain_plain, plain_plain]).layout, ak.layout.NumpyArray) assert isinstance( ak.concatenate([array_plain, array_plain]).layout, ak.layout.NumpyArray) assert isinstance( ak.concatenate([plain_isdoc, plain_isdoc]).layout, ak.layout.NumpyArray) assert isinstance( ak.concatenate([array_isdoc, array_isdoc]).layout, ak.layout.NumpyArray) assert ak.parameters(ak.concatenate([plain_plain, array_plain])) == {} assert ak.parameters(ak.concatenate([plain_isdoc, array_isdoc])) == {} assert ak.parameters(ak.concatenate([array_plain, plain_plain])) == {} assert ak.parameters(ak.concatenate([array_isdoc, plain_isdoc])) == {} assert isinstance( ak.concatenate([plain_plain, array_plain]).layout, ak.layout.UnionArray8_64) assert isinstance( ak.concatenate([plain_isdoc, array_isdoc]).layout, ak.layout.UnionArray8_64) assert isinstance( ak.concatenate([array_plain, plain_plain]).layout, ak.layout.UnionArray8_64) assert isinstance( ak.concatenate([array_isdoc, plain_isdoc]).layout, ak.layout.UnionArray8_64) assert ak.parameters(ak.concatenate([plain_plain, plain_isdoc])) == {} assert ak.parameters(ak.concatenate([array_plain, array_isdoc])) == { "__array__": "zoinks" } assert ak.parameters(ak.concatenate([plain_isdoc, plain_plain])) == {} assert ak.parameters(ak.concatenate([array_isdoc, array_plain])) == { "__array__": "zoinks" } assert isinstance( ak.concatenate([plain_plain, plain_isdoc]).layout, ak.layout.NumpyArray) assert isinstance( ak.concatenate([array_plain, array_isdoc]).layout, ak.layout.NumpyArray) assert isinstance( ak.concatenate([plain_isdoc, plain_plain]).layout, ak.layout.NumpyArray) assert isinstance( ak.concatenate([array_isdoc, array_plain]).layout, ak.layout.NumpyArray)