Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1414,10 +1414,11 @@ def aggregate(self, values, how, axis=0):
else:
is_numeric = issubclass(values.dtype.type, (np.datetime64,
np.timedelta64))
out_dtype = 'float64'
if is_numeric:
out_dtype = 'float64'
values = values.view('int64')
else:
out_dtype = 'object'
values = values.astype(object)

# will be filled in Cython function
Expand Down
2 changes: 1 addition & 1 deletion pandas/src/generate_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -2234,7 +2234,7 @@ def generate_put_template(template, use_ints=True, use_floats=True,
date_like_list = [
('int64', 'int64_t', 'float64_t', 'np.float64'),
]
object_list = [('object', 'object', 'float64_t', 'np.float64')]
object_list = [('object', 'object', 'object', 'np.object_')]
function_list = []
if use_floats:
function_list.extend(floats_list)
Expand Down
4 changes: 2 additions & 2 deletions pandas/src/generated.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6697,7 +6697,7 @@ def group_count_float32(ndarray[float32_t, ndim=2] out,

@cython.boundscheck(False)
@cython.wraparound(False)
def group_count_object(ndarray[float64_t, ndim=2] out,
def group_count_object(ndarray[object, ndim=2] out,
ndarray[int64_t] counts,
ndarray[object, ndim=2] values,
ndarray[int64_t] labels):
Expand Down Expand Up @@ -6838,7 +6838,7 @@ def group_count_bin_float32(ndarray[float32_t, ndim=2] out,

@cython.boundscheck(False)
@cython.wraparound(False)
def group_count_bin_object(ndarray[float64_t, ndim=2] out,
def group_count_bin_object(ndarray[object, ndim=2] out,
ndarray[int64_t] counts,
ndarray[object, ndim=2] values,
ndarray[int64_t] bins):
Expand Down
28 changes: 25 additions & 3 deletions vb_suite/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,24 +232,46 @@ def f():
labels = labels.take(np.random.permutation(len(labels)))
"""

groupby_first = Benchmark('data.groupby(labels).first()', setup,
groupby_first_float64 = Benchmark('data.groupby(labels).first()', setup,
start_date=datetime(2012, 5, 1))

groupby_first_float32 = Benchmark('data2.groupby(labels).first()', setup,
start_date=datetime(2013, 1, 1))

groupby_last = Benchmark('data.groupby(labels).last()', setup,
groupby_last_float64 = Benchmark('data.groupby(labels).last()', setup,
start_date=datetime(2012, 5, 1))

groupby_last_float32 = Benchmark('data2.groupby(labels).last()', setup,
start_date=datetime(2013, 1, 1))

groupby_nth_float64 = Benchmark('data.groupby(labels).nth(0)', setup,
start_date=datetime(2012, 5, 1))

groupby_nth_float32 = Benchmark('data2.groupby(labels).nth(0)', setup,
start_date=datetime(2013, 1, 1))

# with datetimes (GH7555)
setup = common_setup + """
df = DataFrame({'a' : date_range('1/1/2011',periods=100000,freq='s'),'b' : range(100000)})
"""

groupby_mixed_first = Benchmark('df.groupby("b").first()', setup,
groupby_first_datetimes = Benchmark('df.groupby("b").first()', setup,
start_date=datetime(2013, 5, 1))
groupby_last_datetimes = Benchmark('df.groupby("b").last()', setup,
start_date=datetime(2013, 5, 1))
groupby_nth_datetimes = Benchmark('df.groupby("b").nth(0)', setup,
start_date=datetime(2013, 5, 1))

# with object
setup = common_setup + """
df = DataFrame({'a' : ['foo']*100000,'b' : range(100000)})
"""

groupby_first_object = Benchmark('df.groupby("b").first()', setup,
start_date=datetime(2013, 5, 1))
groupby_last_object = Benchmark('df.groupby("b").last()', setup,
start_date=datetime(2013, 5, 1))
groupby_nth_object = Benchmark('df.groupby("b").nth(0)', setup,
start_date=datetime(2013, 5, 1))

#----------------------------------------------------------------------
Expand Down