Skip to content

Commit 1f208a8

Browse files
author
Christopher C. Aycock
committed
Use tuple representation instead of strings
1 parent 77eb47b commit 1f208a8

File tree

3 files changed

+13
-31
lines changed

3 files changed

+13
-31
lines changed

doc/source/whatsnew/v0.19.2.txt

-2
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,3 @@ Bug Fixes
9090
- Explicit check in ``to_stata`` and ``StataWriter`` for out-of-range values when writing doubles (:issue:`14618`)
9191

9292
- Bug in ``unstack()`` if called with a list of column(s) as an argument, regardless of the dtypes of all columns, they get coerced to ``object`` (:issue:`11847`)
93-
94-

pandas/src/joins_func_helper.pxi.in

-19
Original file line numberDiff line numberDiff line change
@@ -163,22 +163,3 @@ def asof_join_{{on_dtype}}(ndarray[{{on_dtype}}] left_values,
163163

164164
{{endfor}}
165165

166-
167-
#----------------------------------------------------------------------
168-
# stringify
169-
#----------------------------------------------------------------------
170-
171-
def stringify(ndarray[object, ndim=2] xt):
172-
""" Invokes .tostring() on each array entry within a 2D array. """
173-
cdef:
174-
Py_ssize_t n
175-
ndarray[object] result
176-
177-
n = len(xt)
178-
result = np.empty(n, dtype=np.object)
179-
180-
for i in range(n):
181-
result[i] = xt[i].tostring()
182-
183-
return result
184-

pandas/tools/merge.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import copy
66
import warnings
77

8+
import string
9+
810
import numpy as np
911
from pandas.compat import range, lrange, lzip, zip, map, filter
1012
import pandas.compat as compat
@@ -303,12 +305,12 @@ def merge_asof(left, right, on=None,
303305
by : column name or list of column names
304306
Match on these columns before performing merge operation.
305307
left_by : column name
306-
Field name to match on in the left DataFrame.
308+
Field names to match on in the left DataFrame.
307309
308310
.. versionadded:: 0.19.2
309311
310312
right_by : column name
311-
Field name to match on in the right DataFrame.
313+
Field names to match on in the right DataFrame.
312314
313315
.. versionadded:: 0.19.2
314316
@@ -1156,11 +1158,12 @@ def _get_merge_keys(self):
11561158
def _get_join_indexers(self):
11571159
""" return the join indexers """
11581160

1159-
def flip_stringify(xs):
1160-
""" flip an array of arrays and string-ify contents """
1161-
xt = np.transpose(xs)
1162-
# numpy arrays aren't hashable, so we convert to a string
1163-
return _join.stringify(_ensure_object(xt))
1161+
def flip(xs):
1162+
""" unlike np.transpose, this returns an array of tuples """
1163+
labels = list(string.ascii_lowercase[:len(xs)])
1164+
dtypes = [x.dtype for x in xs]
1165+
labeled_dtypes = list(zip(labels, dtypes))
1166+
return np.array(lzip(*xs), labeled_dtypes)
11641167

11651168
# values to compare
11661169
left_values = (self.left.index.values if self.left_index else
@@ -1186,9 +1189,9 @@ def flip_stringify(xs):
11861189
# a "by" parameter requires special handling
11871190
if self.left_by is not None:
11881191
if len(self.left_join_keys) > 2:
1189-
# get string representation of values if more than one
1190-
left_by_values = flip_stringify(self.left_join_keys[0:-1])
1191-
right_by_values = flip_stringify(self.right_join_keys[0:-1])
1192+
# get tuple representation of values if more than one
1193+
left_by_values = flip(self.left_join_keys[0:-1])
1194+
right_by_values = flip(self.right_join_keys[0:-1])
11921195
else:
11931196
left_by_values = self.left_join_keys[0]
11941197
right_by_values = self.right_join_keys[0]

0 commit comments

Comments
 (0)