# Buggy code
def apply(self, func, convert_dtype=True, args=(), **kwds):
    """
    Invoke function on values of Series. Can be ufunc (a NumPy function
    that applies to the entire Series) or a Python function that only works
    on single values

    Parameters
    ----------
    func : function
    convert_dtype : boolean, default True
        Try to find better dtype for elementwise function results. If
        False, leave as dtype=object
    args : tuple
        Positional arguments to pass to function in addition to the value
    Additional keyword arguments will be passed as keywords to the function

    Returns
    -------
    y : Series or DataFrame if func returns a Series

    See also
    --------
    Series.map: For element-wise operations

    Examples
    --------

    Create a series with typical summer temperatures for each city.

    >>> import pandas as pd
    >>> import numpy as np
    >>> series = pd.Series([20, 21, 12], index=['London',
    ... 'New York','Helsinki'])
    London      20
    New York    21
    Helsinki    12
    dtype: int64

    Square the values by defining a function and passing it as an
    argument to ``apply()``.

    >>> def square(x):
    ...     return x**2
    >>> series.apply(square)
    London      400
    New York    441
    Helsinki    144
    dtype: int64

    Square the values by passing an anonymous function as an
    argument to ``apply()``.

    >>> series.apply(lambda x: x**2)
    London      400
    New York    441
    Helsinki    144
    dtype: int64

    Define a custom function that needs additional positional
    arguments and pass these additional arguments using the
    ``args`` keyword.

    >>> def subtract_custom_value(x, custom_value):
    ...     return x-custom_value

    >>> series.apply(subtract_custom_value, args=(5,))
    London      15
    New York    16
    Helsinki     7
    dtype: int64

    Define a custom function that takes keyword arguments
    and pass these arguments to ``apply``.

    >>> def add_custom_values(x, **kwargs):
    ...     for month in kwargs:
    ...         x+=kwargs[month]
    ...         return x

    >>> series.apply(add_custom_values, june=30, july=20, august=25)
    London      95
    New York    96
    Helsinki    87
    dtype: int64

    Use a function from the Numpy library.

    >>> series.apply(np.log)
    London      2.995732
    New York    3.044522
    Helsinki    2.484907
    dtype: float64


    """
    if len(self) == 0:
        return self._constructor(dtype=self.dtype, index=self.index).__finalize__(self)

    if kwds or args and not isinstance(func, np.ufunc):
        f = lambda x: func(x, *args, **kwds)
    else:
        f = func

    if isinstance(f, np.ufunc):
        return f(self)

    mapped = lib.map_infer(self.asobject, f, convert=convert_dtype)
    if len(mapped) and isinstance(mapped[0], Series):
        from pandas.core.frame import DataFrame

        return DataFrame(mapped.tolist(), index=self.index)
    else:
        return self._constructor(mapped, index=self.index).__finalize__(self)


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-13-ba941613799a> in <module>()
----> 1 df.publication_timestamp.map(lambda x: x)

/Users/johria/.pyenv/versions/3.5.1/lib/python3.5/site-packages/pandas/core/series.py in map(self, arg, na_action)
2052                                      index=self.index).__finalize__(self)
2053         else:
-> 2054             mapped = map_f(values, arg)
2055             return self._constructor(mapped,
2056                                      index=self.index).__finalize__(self)

TypeError: Argument 'arr' has incorrect type (expected numpy.ndarray, got DatetimeIndex)

# Fixed code
def apply(self, func, convert_dtype=True, args=(), **kwds):
    """
    Invoke function on values of Series. Can be ufunc (a NumPy function
    that applies to the entire Series) or a Python function that only works
    on single values

    Parameters
    ----------
    func : function
    convert_dtype : boolean, default True
        Try to find better dtype for elementwise function results. If
        False, leave as dtype=object
    args : tuple
        Positional arguments to pass to function in addition to the value
    Additional keyword arguments will be passed as keywords to the function

    Returns
    -------
    y : Series or DataFrame if func returns a Series

    See also
    --------
    Series.map: For element-wise operations

    Examples
    --------

    Create a series with typical summer temperatures for each city.

    >>> import pandas as pd
    >>> import numpy as np
    >>> series = pd.Series([20, 21, 12], index=['London',
    ... 'New York','Helsinki'])
    London      20
    New York    21
    Helsinki    12
    dtype: int64

    Square the values by defining a function and passing it as an
    argument to ``apply()``.

    >>> def square(x):
    ...     return x**2
    >>> series.apply(square)
    London      400
    New York    441
    Helsinki    144
    dtype: int64

    Square the values by passing an anonymous function as an
    argument to ``apply()``.

    >>> series.apply(lambda x: x**2)
    London      400
    New York    441
    Helsinki    144
    dtype: int64

    Define a custom function that needs additional positional
    arguments and pass these additional arguments using the
    ``args`` keyword.

    >>> def subtract_custom_value(x, custom_value):
    ...     return x-custom_value

    >>> series.apply(subtract_custom_value, args=(5,))
    London      15
    New York    16
    Helsinki     7
    dtype: int64

    Define a custom function that takes keyword arguments
    and pass these arguments to ``apply``.

    >>> def add_custom_values(x, **kwargs):
    ...     for month in kwargs:
    ...         x+=kwargs[month]
    ...         return x

    >>> series.apply(add_custom_values, june=30, july=20, august=25)
    London      95
    New York    96
    Helsinki    87
    dtype: int64

    Use a function from the Numpy library.

    >>> series.apply(np.log)
    London      2.995732
    New York    3.044522
    Helsinki    2.484907
    dtype: float64


    """
    if len(self) == 0:
        return self._constructor(dtype=self.dtype, index=self.index).__finalize__(self)

    if kwds or args and not isinstance(func, np.ufunc):
        f = lambda x: func(x, *args, **kwds)
    else:
        f = func

    if isinstance(f, np.ufunc):
        return f(self)

    if is_extension_type(self.dtype):
        mapped = self._values.map(f)
    else:
        values = self.asobject
        mapped = lib.map_infer(values, f, convert=convert_dtype)

    if len(mapped) and isinstance(mapped[0], Series):
        from pandas.core.frame import DataFrame

        return DataFrame(mapped.tolist(), index=self.index)
    else:
        return self._constructor(mapped, index=self.index).__finalize__(self)