class_docstr: pandas-on-Spark specific features for Series.
docstr: Transform the data with the function that takes pandas Series and outputs pandas Series.
  The pandas Series given to the function is of a batch used internally.
  
  See also `Transform and apply a function
  <https://spark.apache.org/docs/latest/api/python/user_guide/pandas_on_spark/transform_apply.html>`_.
  
  .. note:: the `func` is unable to access the whole input series. pandas-on-Spark
      internally splits the input series into multiple batches and calls `func` with each
      batch multiple times. Therefore, operations such as global aggregations are impossible.
      See the example below.
  
      >>> # This case does not return the length of whole frame but of the batch internally
      ... # used.
      ... def length(pser) -> ps.Series[int]:
      ...     return pd.Series([len(pser)] * len(pser))
      ...
      >>> df = ps.DataFrame({'A': range(1000)})
      >>> df.A.pandas_on_spark.transform_batch(length)  # doctest: +SKIP
          c0
      0   83
      1   83
      2   83
      ...
  
  .. note:: this API executes the function once to infer the type which is
      potentially expensive, for instance, when the dataset is created after
      aggregations or sorting.
  
      To avoid this, specify return type in ``func``, for instance, as below:
  
      >>> def plus_one(x) -> ps.Series[int]:
      ...     return x + 1
  
  Parameters
  ----------
  func : function
      Function to apply to each pandas frame.
  *args
      Positional arguments to pass to func.
  **kwargs
      Keyword arguments to pass to func.
  
  Returns
  -------
  DataFrame
  
  See Also
  --------
  DataFrame.pandas_on_spark.apply_batch : Similar but it takes pandas DataFrame as its
      internal batch.
  
  Examples
  --------
  >>> df = ps.DataFrame([(1, 2), (3, 4), (5, 6)], columns=['A', 'B'])
  >>> df
     A  B
  0  1  2
  1  3  4
  2  5  6
  
  >>> def plus_one_func(pser) -> ps.Series[np.int64]:
  ...     return pser + 1
  >>> df.A.pandas_on_spark.transform_batch(plus_one_func)
  0    2
  1    4
  2    6
  Name: A, dtype: int64
  
  You can also omit the type hints so pandas-on-Spark infers the return schema as below:
  
  >>> df.A.pandas_on_spark.transform_batch(lambda pser: pser + 1)
  0    2
  1    4
  2    6
  Name: A, dtype: int64
  
  You can also specify extra arguments.
  
  >>> def plus_one_func(pser, a, b, c=3) -> ps.Series[np.int64]:
  ...     return pser + a + b + c
  >>> df.A.pandas_on_spark.transform_batch(plus_one_func, 1, b=2)
  0     7
  1     9
  2    11
  Name: A, dtype: int64
  
  You can also use ``np.ufunc`` and built-in functions as input.
  
  >>> df.A.pandas_on_spark.transform_batch(np.add, 10)
  0    11
  1    13
  2    15
  Name: A, dtype: int64
  
  >>> (df * -1).A.pandas_on_spark.transform_batch(abs)
  0    1
  1    3
  2    5
  Name: A, dtype: int64
docstr_tok: ["Transform","the","data","with","the","function","that","takes","pandas","Series","and","outputs","pandas","Series",".","The","pandas","Series","given","to","the","function","is","of","a","batch","used","internally",".","See","also","`","Transform","and","apply","a","function","<","https",":","\/\/spark.apache.org\/docs\/latest\/api\/python\/user_guide\/pandas_on_spark\/transform_apply.html",">","`","_",".","..","note",":",":","the","`","func","`","is","unable","to","access","the","whole","input","series",".","pandas-on-Spark","internally","splits","the","input","series","into","multiple","batches","and","calls","`","func","`","with","each","batch","multiple","times",".","Therefore",",","operations","such","as","global","aggregations","are","impossible",".","See","the","example","below",".",">",">",">","#","This","case","does","not","return","the","length","of","whole","frame","but","of","the","batch","internally","...","#","used",".","...","def","length","(","pser",")","-",">","ps.Series","[","int","]",":","...","return","pd.Series","(","[","len","(","pser",")","]","*","len","(","pser",")",")","...",">",">",">","df","=","ps.DataFrame","(","{","'","A","'",":","range","(","1000",")","}",")",">",">",">","df.A.pandas_on_spark.transform_batch","(","length",")","#","doctest",":","+SKIP","c0","0","83","1","83","2","83","...","..","note",":",":","this","API","executes","the","function","once","to","infer","the","type","which","is","potentially","expensive",",","for","instance",",","when","the","dataset","is","created","after","aggregations","or","sorting",".","To","avoid","this",",","specify","return","type","in","``","func","``",",","for","instance",",","as","below",":",">",">",">","def","plus_one","(","x",")","-",">","ps.Series","[","int","]",":","...","return","x","+","1","Parameters","--","--","--","--","--","func",":","function","Function","to","apply","to","each","pandas","frame",".","*","args","Positional","arguments","to","pass","to","func",".","*","*","kwargs","Keyword","arguments","to","pass","to","func",".","Returns","--","--","--","-","DataFrame","See","Also","--","--","--","--","DataFrame.pandas_on_spark.apply_batch",":","Similar","but","it","takes","pandas","DataFrame","as","its","internal","batch",".","Examples","--","--","--","--",">",">",">","df","=","ps.DataFrame","(","[","(","1",",","2",")",",","(","3",",","4",")",",","(","5",",","6",")","]",",","columns=","[","'","A","'",",","'","B","'","]",")",">",">",">","df","A","B","0","1","2","1","3","4","2","5","6",">",">",">","def","plus_one_func","(","pser",")","-",">","ps.Series","[","np.int64","]",":","...","return","pser","+","1",">",">",">","df.A.pandas_on_spark.transform_batch","(","plus_one_func",")","0","2","1","4","2","6","Name",":","A",",","dtype",":","int64","You","can","also","omit","the","type","hints","so","pandas-on-Spark","infers","the","return","schema","as","below",":",">",">",">","df.A.pandas_on_spark.transform_batch","(","lambda","pser",":","pser","+","1",")","0","2","1","4","2","6","Name",":","A",",","dtype",":","int64","You","can","also","specify","extra","arguments",".",">",">",">","def","plus_one_func","(","pser",",","a",",","b",",","c=3",")","-",">","ps.Series","[","np.int64","]",":","...","return","pser","+","a","+","b","+","c",">",">",">","df.A.pandas_on_spark.transform_batch","(","plus_one_func",",","1",",","b=2",")","0","7","1","9","2","11","Name",":","A",",","dtype",":","int64","You","can","also","use","``","np.ufunc","``","and","built-in","functions","as","input",".",">",">",">","df.A.pandas_on_spark.transform_batch","(","np.add",",","10",")","0","11","1","13","2","15","Name",":","A",",","dtype",":","int64",">",">",">","(","df","*","-1",")",".A.pandas_on_spark.transform_batch","(","abs",")","0","1","1","3","2","5","Name",":","A",",","dtype",":","int64"]
code: def transform_batch(
      self, func: Callable[..., pd.Series], *args: Any, **kwargs: Any
  ) -> "Series":
      """
      Transform the data with the function that takes pandas Series and outputs pandas Series.
      The pandas Series given to the function is of a batch used internally.
  
      See also `Transform and apply a function
      <https://spark.apache.org/docs/latest/api/python/user_guide/pandas_on_spark/transform_apply.html>`_.
  
      .. note:: the `func` is unable to access the whole input series. pandas-on-Spark
          internally splits the input series into multiple batches and calls `func` with each
          batch multiple times. Therefore, operations such as global aggregations are impossible.
          See the example below.
  
          >>> # This case does not return the length of whole frame but of the batch internally
          ... # used.
          ... def length(pser) -> ps.Series[int]:
          ...     return pd.Series([len(pser)] * len(pser))
          ...
          >>> df = ps.DataFrame({'A': range(1000)})
          >>> df.A.pandas_on_spark.transform_batch(length)  # doctest: +SKIP
              c0
          0   83
          1   83
          2   83
          ...
  
      .. note:: this API executes the function once to infer the type which is
          potentially expensive, for instance, when the dataset is created after
          aggregations or sorting.
  
          To avoid this, specify return type in ``func``, for instance, as below:
  
          >>> def plus_one(x) -> ps.Series[int]:
          ...     return x + 1
  
      Parameters
      ----------
      func : function
          Function to apply to each pandas frame.
      *args
          Positional arguments to pass to func.
      **kwargs
          Keyword arguments to pass to func.
  
      Returns
      -------
      DataFrame
  
      See Also
      --------
      DataFrame.pandas_on_spark.apply_batch : Similar but it takes pandas DataFrame as its
          internal batch.
  
      Examples
      --------
      >>> df = ps.DataFrame([(1, 2), (3, 4), (5, 6)], columns=['A', 'B'])
      >>> df
         A  B
      0  1  2
      1  3  4
      2  5  6
  
      >>> def plus_one_func(pser) -> ps.Series[np.int64]:
      ...     return pser + 1
      >>> df.A.pandas_on_spark.transform_batch(plus_one_func)
      0    2
      1    4
      2    6
      Name: A, dtype: int64
  
      You can also omit the type hints so pandas-on-Spark infers the return schema as below:
  
      >>> df.A.pandas_on_spark.transform_batch(lambda pser: pser + 1)
      0    2
      1    4
      2    6
      Name: A, dtype: int64
  
      You can also specify extra arguments.
  
      >>> def plus_one_func(pser, a, b, c=3) -> ps.Series[np.int64]:
      ...     return pser + a + b + c
      >>> df.A.pandas_on_spark.transform_batch(plus_one_func, 1, b=2)
      0     7
      1     9
      2    11
      Name: A, dtype: int64
  
      You can also use ``np.ufunc`` and built-in functions as input.
  
      >>> df.A.pandas_on_spark.transform_batch(np.add, 10)
      0    11
      1    13
      2    15
      Name: A, dtype: int64
  
      >>> (df * -1).A.pandas_on_spark.transform_batch(abs)
      0    1
      1    3
      2    5
      Name: A, dtype: int64
      """
      assert callable(
          func
      ), "the first argument should be a callable function."
  
      return_sig = None
      try:
          spec = inspect.getfullargspec(func)
          return_sig = spec.annotations.get("return", None)
      except TypeError:
          # Falls back to schema inference if it fails to get signature.
          pass
  
      return_type = None
      if return_sig is not None:
          # Extract the signature arguments from this function.
          sig_return = infer_return_type(func)
          if not isinstance(sig_return, SeriesType):
              raise ValueError(
                  "Expected the return type of this function to be of type column,"
                  " but found type {}".format(sig_return)
              )
          return_type = sig_return
  
      return self._transform_batch(
          lambda c: func(c, *args, **kwargs), return_type
      )
  
imports: import inspect
  from typing import Any, Callable, Optional, Tuple, Union, TYPE_CHECKING, cast, List
  from types import FunctionType
  import numpy
  import pandas
  from pyspark.sql import functions
  from pyspark.sql.functions import pandas_udf
  from pyspark.sql.types import DataType, LongType, StructField, StructType
  from pyspark.pandas._typing import DataFrameOrSeries, Name
  from pyspark.pandas.internal import InternalField, InternalFrame, SPARK_INDEX_NAME_FORMAT, SPARK_DEFAULT_SERIES_NAME, SPARK_INDEX_NAME_PATTERN
  from pyspark.pandas.typedef import infer_return_type, DataFrameType, ScalarType, SeriesType
  from pyspark.pandas.utils import is_name_like_value, is_name_like_tuple, name_like_string, scol_for, verify_temp_column_name, log_advice
label_desc: Use image node_id 2 for calling the PandasOnSparkSeriesMethods obj's underlying member method code with example usage: obj.transform_batch(func) and returns: self