Skip to content

PERF: perf regression with mixed-type ops using numexpr (GH5481) #5482

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

Merged
merged 1 commit into from
Nov 10, 2013
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
35 changes: 27 additions & 8 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2810,11 +2810,28 @@ def _arith_op(left, right):
return func(left, right)

if this._is_mixed_type or other._is_mixed_type:
# XXX no good for duplicate columns
# but cannot outer join in align if dups anyways?
result = {}
for col in this:
result[col] = _arith_op(this[col].values, other[col].values)

# unique
if this.columns.is_unique:

def f(col):
r = _arith_op(this[col].values, other[col].values)
return self._constructor_sliced(r,index=new_index,dtype=r.dtype)

result = dict([ (col, f(col)) for col in this ])

# non-unique
else:

def f(i):
r = _arith_op(this.iloc[:,i].values, other.iloc[:,i].values)
return self._constructor_sliced(r,index=new_index,dtype=r.dtype)

result = dict([ (i,f(i)) for i, col in enumerate(this.columns) ])
result = self._constructor(result, index=new_index, copy=False)
result.columns = new_columns
return result

else:
result = _arith_op(this.values, other.values)

Expand Down Expand Up @@ -2890,10 +2907,12 @@ def _compare(a, b):
# non-unique
else:
def _compare(a, b):
return [func(a.iloc[:,i], b.iloc[:,i]) for i, col in enumerate(a.columns)]
return dict([(i,func(a.iloc[:,i], b.iloc[:,i])) for i, col in enumerate(a.columns)])
new_data = expressions.evaluate(_compare, str_rep, self, other)
return self._constructor(data=new_data, index=self.columns,
columns=self.index, copy=False).T
result = self._constructor(data=new_data, index=self.index,
copy=False)
result.columns = self.columns
return result

def _compare_frame(self, other, func, str_rep):
if not self._indexed_same(other):
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3217,6 +3217,15 @@ def check(result, expected=None):
this_df['A'] = index
check(this_df, expected_df)

# operations
for op in ['__add__','__mul__','__sub__','__truediv__']:
df = DataFrame(dict(A = np.arange(10), B = np.random.rand(10)))
expected = getattr(df,op)(df)
expected.columns = ['A','A']
df.columns = ['A','A']
result = getattr(df,op)(df)
check(result,expected)

def test_column_dups_indexing(self):

def check(result, expected=None):
Expand Down