Skip to content

Commit f7902e4

Browse files
committed
Remove internal uses of join_axes
1 parent 5294371 commit f7902e4

File tree

1 file changed

+20
-30
lines changed

1 file changed

+20
-30
lines changed

pandas/core/reshape/concat.py

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -220,27 +220,32 @@ def concat(objs, axis=0, join='outer', join_axes=None, ignore_index=False,
220220
...
221221
ValueError: Indexes have overlapping values: ['a']
222222
"""
223+
op = _Concatenator(objs, axis=axis, ignore_index=ignore_index, join=join,
224+
keys=keys, levels=levels, names=names,
225+
verify_integrity=verify_integrity, copy=copy, sort=sort)
226+
227+
res = op.get_result()
228+
223229
if join_axes is not None:
224230
warnings.warn('The join_axes-keyword is deprecated. Use .reindex or '
225231
'.reindex_like on the result to achieve the same '
226232
'functionality.', FutureWarning, stacklevel=2)
227-
op = _Concatenator(objs, axis=axis, join_axes=join_axes,
228-
ignore_index=ignore_index, join=join,
229-
keys=keys, levels=levels, names=names,
230-
verify_integrity=verify_integrity,
231-
copy=copy, sort=sort)
232-
return op.get_result()
233+
if len(join_axes) > 1:
234+
raise AssertionError("join_axes must be a list of indexes of "
235+
"length {length}".format(length=1))
236+
other_axis = 1 if axis == 0 else 0 # switches between 0 & 1
237+
res = res.reindex(join_axes[0], axis=other_axis)
238+
return res
233239

234240

235241
class _Concatenator(object):
236242
"""
237243
Orchestrates a concatenation operation for BlockManagers
238244
"""
239245

240-
def __init__(self, objs, axis=0, join='outer', join_axes=None,
241-
keys=None, levels=None, names=None,
242-
ignore_index=False, verify_integrity=False, copy=True,
243-
sort=False):
246+
def __init__(self, objs, axis=0, join='outer', keys=None, levels=None,
247+
names=None, ignore_index=False, verify_integrity=False,
248+
copy=True, sort=False):
244249
if isinstance(objs, (NDFrame, compat.string_types)):
245250
raise TypeError('first argument must be an iterable of pandas '
246251
'objects, you passed an object of type '
@@ -313,9 +318,7 @@ def __init__(self, objs, axis=0, join='outer', join_axes=None,
313318
if sum(obj.shape) > 0 or isinstance(obj, Series)]
314319

315320
if (len(non_empties) and (keys is None and names is None and
316-
levels is None and
317-
join_axes is None and
318-
not self.intersect)):
321+
levels is None and not self.intersect)):
319322
objs = non_empties
320323
sample = objs[0]
321324

@@ -371,7 +374,6 @@ def __init__(self, objs, axis=0, join='outer', join_axes=None,
371374

372375
# note: this is the BlockManager axis (since DataFrame is transposed)
373376
self.axis = axis
374-
self.join_axes = join_axes
375377
self.keys = keys
376378
self.names = names or getattr(keys, 'names', None)
377379
self.levels = levels
@@ -444,22 +446,10 @@ def _get_new_axes(self):
444446
ndim = self._get_result_dim()
445447
new_axes = [None] * ndim
446448

447-
if self.join_axes is None:
448-
for i in range(ndim):
449-
if i == self.axis:
450-
continue
451-
new_axes[i] = self._get_comb_axis(i)
452-
else:
453-
if len(self.join_axes) != ndim - 1:
454-
raise AssertionError("length of join_axes must not be equal "
455-
"to {length}".format(length=ndim - 1))
456-
457-
# ufff...
458-
indices = compat.lrange(ndim)
459-
indices.remove(self.axis)
460-
461-
for i, ax in zip(indices, self.join_axes):
462-
new_axes[i] = ax
449+
for i in range(ndim):
450+
if i == self.axis:
451+
continue
452+
new_axes[i] = self._get_comb_axis(i)
463453

464454
new_axes[self.axis] = self._get_concat_axis()
465455
return new_axes

0 commit comments

Comments
 (0)