code: def _one_hot_encode(
      block_table, block_indexes, data_manager, categories, dtype
  ):
      transform_categories = []
      mock_data = []
      for category in categories:
          transform_categories.append(
              [np.array(cate) for cate in category]
          )
          shapes = [cate.shape[0] for cate in transform_categories[-1]]
          row_shape = max(shapes)
          column_shape = len(categories[-1])
          mock_cate_data = torch.zeros(
              (row_shape, column_shape), dtype=getattr(torch, dtype)
          )
          for rid in range(row_shape):
              for cid in range(column_shape):
                  mock_cate_data[rid][cid] = rid % shapes[cid]
  
          mock_data.append(mock_cate_data)
  
      block_index_set = set(block_indexes)
  
      def _encode(blocks):
          ret_blocks = []
          enc_blocks = []
          idx = 0
          for bid, block in enumerate(blocks):
              if bid not in block_index_set:
                  ret_blocks.append(block)
                  continue
  
              enc = OneHotEncoder(dtype=dtype)
              enc.fit(
                  mock_data[idx]
              )  # one hot encoder need to fit first.
              enc.categories_ = transform_categories[idx]
              idx += 1
              enc_blocks.append(enc.transform(block).toarray())
  
          ret_blocks.append(
              data_manager.blocks[-1].convert_block(
                  np.hstack(enc_blocks)
              )
          )
  
          return ret_blocks
  
      return block_table.mapValues(_encode)
  
file_path: FATE/python/fate/arch/dataframe/ops/_encoder.py
imports: import functools
  import pandas
  import numpy
  import torch
  from sklearn.preprocessing import OneHotEncoder
  from typing import Union
  from ._compress_block import compress_blocks
  from .._dataframe import DataFrame
  from ..manager import BlockType, DataManager
label_desc: Use image node_id 3 for calling a global function with example usage: _one_hot_encode(block_table, block_indexes, data_manager, categories, dtype) and returns: block_table, ret_blocks