Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: DataFrame.apply fails on timezone aware datetime data #12244

Closed
jorisvandenbossche opened this issue Feb 6, 2016 · 1 comment
Closed
Labels
Bug Timezones Timezone data dtype
Milestone

Comments

@jorisvandenbossche
Copy link
Member

In [29]: df = pd.DataFrame({'dt': pd.date_range("2015-01-01", periods=3, tz='Europe/Brussels')})

In [30]: df
Out[30]:
                         dt
0 2015-01-01 00:00:00+01:00
1 2015-01-02 00:00:00+01:00
2 2015-01-03 00:00:00+01:00

In [31]: df.apply(lambda x: x)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-31-9cd68f0fd3ff> in <module>()
----> 1 df.apply(lambda x: x)

c:\users\vdbosscj\scipy\pandas-joris\pandas\core\frame.py in apply(self, func, a
xis, broadcast, raw, reduce, args, **kwds)
   4029                     if reduce is None:
   4030                         reduce = True
-> 4031                     return self._apply_standard(f, axis, reduce=reduce)
   4032             else:
   4033                 return self._apply_broadcast(f, axis)

c:\users\vdbosscj\scipy\pandas-joris\pandas\core\frame.py in _apply_standard(sel
f, func, axis, ignore_failures, reduce)
   4076             # Create a dummy Series from an empty array
   4077             index = self._get_axis(axis)
-> 4078             empty_arr = np.empty(len(index), dtype=values.dtype)
   4079             dummy = Series(empty_arr, index=self._get_axis(axis),
   4080                            dtype=values.dtype)

TypeError: data type not understood

(from SO)

@jorisvandenbossche jorisvandenbossche added Bug Timezones Timezone data dtype labels Feb 6, 2016
@jreback jreback added this to the 0.18.1 milestone Feb 11, 2016
@jreback jreback modified the milestones: 0.18.0, 0.18.1 Feb 11, 2016
gfyoung added a commit to forking-repos/pandas that referenced this issue Feb 12, 2016
Fixes bug in DataFrame.apply by avoiding reducing DataFrames
whose values dtype is not a numpy dtype.

Closes pandas-devgh-12244.
jreback pushed a commit that referenced this issue Feb 12, 2016
Addresses issue in #12244 in which a non-numpy-dtype for
DataFrame.values causes a `TypeError` to be thrown in the `reduce ==
True` case for `DataFrame.apply`.  Resolved by first passing
`DataFrame.values` through `Series` initialization and taking its
`values` attribute, which is an `ndarray` and hence will have a valid
`dtype`.  Note that the output of `apply` will still have the original
`dtype`.

Author: gfyoung <gfyoung17@gmail.com>

Closes #12284 from gfyoung/df_apply_tz_aware and squashes the following commits:

b18b74f [gfyoung] BUG: Allow apply to be used with non-numpy-dtype DataFrames
@jreback
Copy link
Contributor

jreback commented Feb 12, 2016

closed by #12284

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Timezones Timezone data dtype
Projects
None yet
Development

No branches or pull requests

2 participants