class_docstr: A collection of data which can be pre-processed in parallel on Spark
class_docstr_tok: ["A","collection","of","data","which","can","be","pre-processed","in","parallel","on","Spark"]
docstr: Return a new SparkXShards that has exactly num_partitions partitions.
  
  :param num_partitions: target number of partitions
  :return: a new SparkXShards object.
docstr_tok: ["Return","a","new","SparkXShards","that","has","exactly","num_partitions","partitions",".",":","param","num_partitions",":","target","number","of","partitions",":","return",":","a","new","SparkXShards","object","."]
code: def repartition(self, num_partitions):
      """
  
      Return a new SparkXShards that has exactly num_partitions partitions.
  
      :param num_partitions: target number of partitions
      :return: a new SparkXShards object.
      """
      if self._get_class_name() == "pandas.core.frame.DataFrame":
          import pandas as pd
  
          if num_partitions > self.rdd.getNumPartitions():
              rdd = self.rdd.flatMap(
                  lambda df: df.apply(
                      lambda row: (row[0], row.values.tolist()), axis=1
                  ).values.tolist()
              ).partitionBy(num_partitions)
  
              schema = self._get_schema()
  
              def merge_rows(iter):
                  data = [value[1] for value in list(iter)]
                  if data:
                      df = pd.DataFrame(
                          data=data, columns=schema["columns"]
                      ).astype(schema["dtypes"])
                      return [df]
                  else:
                      # no data in this partition
                      return iter
  
              repartitioned_shard = SparkXShards(
                  rdd.mapPartitions(merge_rows)
              )
          else:
  
              def combine_df(iter):
                  dfs = list(iter)
                  if len(dfs) > 0:
                      return [pd.concat(dfs)]
                  else:
                      return iter
  
              rdd = self.rdd.coalesce(num_partitions)
              repartitioned_shard = SparkXShards(
                  rdd.mapPartitions(combine_df)
              )
      elif self._get_class_name() == "list":
          if num_partitions > self.rdd.getNumPartitions():
              rdd = self.rdd.flatMap(lambda data: data).repartition(
                  num_partitions
              )
  
              repartitioned_shard = SparkXShards(
                  rdd.mapPartitions(lambda iter: [list(iter)])
              )
          else:
              rdd = self.rdd.coalesce(num_partitions)
              from functools import reduce
  
              repartitioned_shard = SparkXShards(
                  rdd.mapPartitions(
                      lambda iter: [
                          reduce(lambda l1, l2: l1 + l2, iter)
                      ]
                  )
              )
      elif self._get_class_name() == "numpy.ndarray":
          elem = self.rdd.first()
          shape = elem.shape
          dtype = elem.dtype
          if len(shape) > 0:
              if num_partitions > self.rdd.getNumPartitions():
                  rdd = self.rdd.flatMap(
                      lambda data: list(data)
                  ).repartition(num_partitions)
  
                  repartitioned_shard = SparkXShards(
                      rdd.mapPartitions(
                          lambda iter: np.stack(
                              [list(iter)], axis=0
                          ).astype(dtype)
                      )
                  )
              else:
                  rdd = self.rdd.coalesce(num_partitions)
                  from functools import reduce
  
                  repartitioned_shard = SparkXShards(
                      rdd.mapPartitions(
                          lambda iter: [
                              np.concatenate(list(iter), axis=0)
                          ]
                      )
                  )
          else:
              repartitioned_shard = SparkXShards(
                  self.rdd.repartition(num_partitions)
              )
      else:
          repartitioned_shard = SparkXShards(
              self.rdd.repartition(num_partitions)
          )
      self._uncache()
      return repartitioned_shard
  
imports: from py4j.protocol import Py4JError
  from zoo.orca.data.utils import *
  from zoo.orca import OrcaContext
  from zoo.common.nncontext import init_nncontext
  from zoo import ZooContext, get_node_and_core_number
  from zoo.util import nest
label_desc: Use image node_id 10 for calling the SparkXShards obj's underlying member method code with example usage: obj.repartition(num_partitions) and returns: repartitioned_shard, list, iter, list, iter