(self, idx)
return func_lines
Generate main code lines for df.getitem
Generate main code lines for df.getitem
Generate main code lines for df . getitem
def df_getitem_bool_series_idx_main_codelines(self, idx):
    """Generate main code lines for df.getitem"""

    # optimization for default indexes in df and idx when index alignment is trivial
    if (isinstance(self.index, PositionalIndexType) and isinstance(idx.index, PositionalIndexType)):
        func_lines = [f'  self_index = self._index',
                      f'  if len(self_index) > len(idx):',
                      f'    msg = "Unalignable boolean Series provided as indexer " + \\',
                      f'          "(index of the boolean Series and of the indexed object do not match)."',
                      f'    raise IndexingError(msg)',
                      f'  # do not trim idx._data to df length as getitem_by_mask handles such case',
                      f'  res_index = getitem_by_mask(self_index, idx._data)',
                      f'  # df index is default, same as positions so it can be used in take']
        results = []
        for i, col in enumerate(self.columns):
            col_loc = self.column_loc[col]
            type_id, col_id = col_loc.type_id, col_loc.col_id
            res_data = f'res_data_{i}'
            func_lines += [
                f'  data_{i} = self._data[{type_id}][{col_id}]',
                f'  {res_data} = sdc_take(data_{i}, res_index)'
            ]
            results.append((col, res_data))

        data = ', '.join(f'"{col}": {data}' for col, data in results)
        func_lines += [
            f'  return pandas.DataFrame({{{data}}}, index=res_index)'
        ]
    else:
        func_lines = [
            f'  self_index = self._index',
            f'  idx_reindexed_by_self = sdc_reindex_series(idx._data, idx._index, idx._name, self_index)',
            f'  final_mask = idx_reindexed_by_self._data',
            f'  res_index = self_index[final_mask]',
            f'  selected_pos = getitem_by_mask(numpy.arange(len(self_index)), final_mask)'
        ]
        results = []
        for i, col in enumerate(self.columns):
            col_loc = self.column_loc[col]
            type_id, col_id = col_loc.type_id, col_loc.col_id
            res_data = f'res_data_{i}'
            func_lines += [
                f'  data_{i} = self._data[{type_id}][{col_id}]',
                f'  {res_data} = sdc_take(data_{i}, selected_pos)'
            ]
            results.append((col, res_data))

        data = ', '.join(f'"{col}": {data}' for col, data in results)
        func_lines += [
            f'  return pandas.DataFrame({{{data}}}, index=res_index)'
        ]

    return func_lines
def df_getitem_bool_series_idx_main_codelines ( self , idx ) : # optimization for default indexes in df and idx when index alignment is trivial if ( isinstance ( self . index , PositionalIndexType ) and isinstance ( idx . index , PositionalIndexType ) ) : func_lines = [ f'  self_index = self._index' , f'  if len(self_index) > len(idx):' , f'    msg = "Unalignable boolean Series provided as indexer " + \\' , f'          "(index of the boolean Series and of the indexed object do not match)."' , f'    raise IndexingError(msg)' , f'  # do not trim idx._data to df length as getitem_by_mask handles such case' , f'  res_index = getitem_by_mask(self_index, idx._data)' , f'  # df index is default, same as positions so it can be used in take' ] results = [ ] for i , col in enumerate ( self . columns ) : col_loc = self . column_loc [ col ] type_id , col_id = col_loc . type_id , col_loc . col_id res_data = f'res_data_{i}' func_lines += [ f'  data_{i} = self._data[{type_id}][{col_id}]' , f'  {res_data} = sdc_take(data_{i}, res_index)' ] results . append ( ( col , res_data ) ) data = ', ' . join ( f'"{col}": {data}' for col , data in results ) func_lines += [ f'  return pandas.DataFrame({{{data}}}, index=res_index)' ] else : func_lines = [ f'  self_index = self._index' , f'  idx_reindexed_by_self = sdc_reindex_series(idx._data, idx._index, idx._name, self_index)' , f'  final_mask = idx_reindexed_by_self._data' , f'  res_index = self_index[final_mask]' , f'  selected_pos = getitem_by_mask(numpy.arange(len(self_index)), final_mask)' ] results = [ ] for i , col in enumerate ( self . columns ) : col_loc = self . column_loc [ col ] type_id , col_id = col_loc . type_id , col_loc . col_id res_data = f'res_data_{i}' func_lines += [ f'  data_{i} = self._data[{type_id}][{col_id}]' , f'  {res_data} = sdc_take(data_{i}, selected_pos)' ] results . append ( ( col , res_data ) ) data = ', ' . join ( f'"{col}": {data}' for col , data in results ) func_lines += [ f'  return pandas.DataFrame({{{data}}}, index=res_index)' ] return func_lines