示例#1
0
文件: base.py 项目: vlam020/vectorbt
    def map_array(self,
                  a: tp.ArrayLike,
                  idx_field: tp.Optional[str] = None,
                  value_map: tp.Optional[tp.ValueMapLike] = None,
                  group_by: tp.GroupByLike = None,
                  **kwargs) -> MappedArray:
        """Convert array to mapped array.

         The length of the array should match that of the records."""
        if not isinstance(a, np.ndarray):
            a = np.asarray(a)
        checks.assert_shape_equal(a, self.values)
        if idx_field is None:
            idx_field = self.idx_field
        if idx_field is not None:
            idx_arr = self.values[idx_field]
        else:
            idx_arr = None
        return MappedArray(self.wrapper,
                           a,
                           self.values['col'],
                           id_arr=self.values['id'],
                           idx_arr=idx_arr,
                           value_map=value_map,
                           **kwargs).regroup(group_by)
示例#2
0
文件: base.py 项目: vlam020/vectorbt
    def map(self,
            map_func_nb: tp.RecordMapFunc,
            *args,
            idx_field: tp.Optional[str] = None,
            value_map: tp.Optional[tp.ValueMapLike] = None,
            group_by: tp.GroupByLike = None,
            **kwargs) -> MappedArray:
        """Map each record to a scalar value. Returns mapped array.

        See `vectorbt.records.nb.map_records_nb`."""
        checks.assert_numba_func(map_func_nb)
        mapped_arr = nb.map_records_nb(self.values, map_func_nb, *args)
        if idx_field is None:
            idx_field = self.idx_field
        if idx_field is not None:
            idx_arr = self.values[idx_field]
        else:
            idx_arr = None
        return MappedArray(self.wrapper,
                           mapped_arr,
                           self.values['col'],
                           id_arr=self.values['id'],
                           idx_arr=idx_arr,
                           value_map=value_map,
                           **kwargs).regroup(group_by)
示例#3
0
    def map(self,
            map_func_nb,
            *args,
            idx_field=None,
            value_map=None,
            group_by=None,
            **kwargs):
        """Map each record to a scalar value. Returns mapped array.

        See `vectorbt.records.nb.map_records_nb`."""
        checks.assert_numba_func(map_func_nb)
        mapped_arr = nb.map_records_nb(self.values, map_func_nb, *args)
        if idx_field is None:
            idx_field = self.idx_field
        if idx_field is not None:
            idx_arr = self.values[idx_field]
        else:
            idx_arr = None
        return MappedArray(self.wrapper,
                           mapped_arr,
                           self.values['col'],
                           id_arr=self.values['id'],
                           idx_arr=idx_arr,
                           value_map=value_map,
                           **kwargs).regroup(group_by)
示例#4
0
 def map_field(self, field, idx_field=None, value_map=None, group_by=None, **kwargs):
     """Convert field to mapped array."""
     if idx_field is None:
         idx_field = self.idx_field
     if idx_field is not None:
         idx_arr = self.values[idx_field]
     else:
         idx_arr = None
     return MappedArray(
         self.wrapper,
         self.values[field],
         self.values['col'],
         id_arr=self.values['id'],
         idx_arr=idx_arr,
         value_map=value_map,
         **kwargs
     ).regroup(group_by)
示例#5
0
文件: base.py 项目: vlam020/vectorbt
 def map_field(self,
               field: str,
               idx_field: tp.Optional[str] = None,
               value_map: tp.Optional[tp.ValueMapLike] = None,
               group_by: tp.GroupByLike = None,
               **kwargs) -> MappedArray:
     """Convert field to mapped array."""
     if idx_field is None:
         idx_field = self.idx_field
     if idx_field is not None:
         idx_arr = self.values[idx_field]
     else:
         idx_arr = None
     return MappedArray(self.wrapper,
                        self.values[field],
                        self.values['col'],
                        id_arr=self.values['id'],
                        idx_arr=idx_arr,
                        value_map=value_map,
                        **kwargs).regroup(group_by)
示例#6
0
文件: base.py 项目: vroomzel/vectorbt
    def map_array(self,
                  a: tp.ArrayLike,
                  idx_arr: tp.Optional[tp.ArrayLike] = None,
                  mapping: tp.Optional[tp.MappingLike] = None,
                  group_by: tp.GroupByLike = None,
                  **kwargs) -> MappedArray:
        """Convert array to mapped array.

         The length of the array should match that of the records."""
        if not isinstance(a, np.ndarray):
            a = np.asarray(a)
        checks.assert_shape_equal(a, self.values)
        if idx_arr is None:
            idx_arr = self.idx_arr
        return MappedArray(self.wrapper,
                           a,
                           self.col_arr,
                           id_arr=self.id_arr,
                           idx_arr=idx_arr,
                           mapping=mapping,
                           col_mapper=self.col_mapper,
                           **kwargs).regroup(group_by)