def test_drop_columns(self): tab = Table({'a': 1, 'b': 2, 'c': 3}) print(tab.dtype) tab = tab.drop_columns(['a', 'b']) print(tab.dtype) with pytest.raises(AttributeError): print(tab.a) with pytest.raises(AttributeError): print(tab.b) print(tab.c)
def test_drop_columns(self): tab = Table({"a": 1, "b": 2, "c": 3}) print(tab.dtype) tab = tab.drop_columns(["a", "b"]) print(tab.dtype) with pytest.raises(AttributeError): print(tab.a) with pytest.raises(AttributeError): print(tab.b) print(tab.c)
def apply(self, hits, no_copy=False, correct_slewing=True, slewing_variant=3): """Add x, y, z, t0 (and du, floor if DataFrame) columns to the hits.""" if not no_copy: try: hits = hits.copy() except AttributeError: # probably a km3io object pass if isinstance(hits, (ak.Array, ak.Record, km3io.rootio.Branch)): if hasattr(hits, "dom_id"): hits = Table( dict( dom_id=hits.dom_id, channel_id=hits.channel_id, time=hits.t, tot=hits.tot, triggered=hits.trig, )) else: # mc_hits in km3io hits = Table( dict( pmt_id=hits.pmt_id, time=hits.t, a=hits.a, # TODO: Not all MC files have these two fields # pure_a=hits.pure_a, # pure_t=hits.pure_t, origin=hits.origin, )) if istype(hits, "DataFrame"): # do we ever see McHits here? hits = Table.from_template(hits, "Hits") is_mc = None if hasattr(hits, "dom_id") and hasattr(hits, "channel_id"): try: ( dir_x, dir_y, dir_z, du, floor, pos_x, pos_y, pos_z, t0, pmt_id, ) = _get_calibration_for_hits(hits, self._calib_by_dom_and_channel) except KeyError as e: self.log.critical("Wrong calibration (DETX) data provided.") raise is_mc = False elif hasattr(hits, "pmt_id"): try: ( dir_x, dir_y, dir_z, du, floor, pos_x, pos_y, pos_z, t0, dom_id, channel_id, ) = _get_calibration_for_mchits(hits, self._calib_by_pmt_id) except KeyError as e: self.log.critical("Wrong calibration (DETX) data provided.") raise is_mc = True else: raise TypeError("Don't know how to apply calibration to '{0}'. " "We need at least 'dom_id' and 'channel_id', or " "'pmt_id'.".format(hits.name)) if hasattr(hits, "time") and not is_mc: if hits.time.dtype != t0.dtype: time = hits.time.astype("f4") + t0.astype("f4") hits = hits.drop_columns(["time"]) hits = hits.append_columns(["time"], [time]) else: hits.time += t0 hits_data = {} for colname in hits.dtype.names: hits_data[colname] = hits[colname] calib = { "dir_x": dir_x, "dir_y": dir_y, "dir_z": dir_z, "du": du.astype(np.uint8), "floor": floor.astype(np.uint8), "pos_x": pos_x, "pos_y": pos_y, "pos_z": pos_z, "t0": t0, } if is_mc: calib["dom_id"] = dom_id.astype(np.int32) calib["channel_id"] = channel_id.astype(np.int32) else: calib["pmt_id"] = pmt_id.astype(np.int32) hits_data.update(calib) if correct_slewing and not is_mc: hits_data["time"] -= slew(hits_data["tot"], variant=slewing_variant) return Table(hits_data, h5loc=hits.h5loc, split_h5=hits.split_h5, name=hits.name)
def test_drop_column(self): tab = Table({'a': 1, 'b': 2}) tab = tab.drop_columns('a') with pytest.raises(AttributeError): print(tab.a) print(tab.b)
def test_drop_column(self): tab = Table({"a": 1, "b": 2}) tab = tab.drop_columns("a") with pytest.raises(AttributeError): print(tab.a) print(tab.b)