Skip to content

Commit

Permalink
Remove internal uses of join_axes
Browse files Browse the repository at this point in the history
  • Loading branch information
h-vetinari committed Aug 22, 2018
1 parent 5294371 commit f7902e4
Showing 1 changed file with 20 additions and 30 deletions.
50 changes: 20 additions & 30 deletions pandas/core/reshape/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,27 +220,32 @@ def concat(objs, axis=0, join='outer', join_axes=None, ignore_index=False,
...
ValueError: Indexes have overlapping values: ['a']
"""
op = _Concatenator(objs, axis=axis, ignore_index=ignore_index, join=join,
keys=keys, levels=levels, names=names,
verify_integrity=verify_integrity, copy=copy, sort=sort)

res = op.get_result()

if join_axes is not None:
warnings.warn('The join_axes-keyword is deprecated. Use .reindex or '
'.reindex_like on the result to achieve the same '
'functionality.', FutureWarning, stacklevel=2)
op = _Concatenator(objs, axis=axis, join_axes=join_axes,
ignore_index=ignore_index, join=join,
keys=keys, levels=levels, names=names,
verify_integrity=verify_integrity,
copy=copy, sort=sort)
return op.get_result()
if len(join_axes) > 1:
raise AssertionError("join_axes must be a list of indexes of "
"length {length}".format(length=1))
other_axis = 1 if axis == 0 else 0 # switches between 0 & 1
res = res.reindex(join_axes[0], axis=other_axis)
return res


class _Concatenator(object):
"""
Orchestrates a concatenation operation for BlockManagers
"""

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

if (len(non_empties) and (keys is None and names is None and
levels is None and
join_axes is None and
not self.intersect)):
levels is None and not self.intersect)):
objs = non_empties
sample = objs[0]

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

# note: this is the BlockManager axis (since DataFrame is transposed)
self.axis = axis
self.join_axes = join_axes
self.keys = keys
self.names = names or getattr(keys, 'names', None)
self.levels = levels
Expand Down Expand Up @@ -444,22 +446,10 @@ def _get_new_axes(self):
ndim = self._get_result_dim()
new_axes = [None] * ndim

if self.join_axes is None:
for i in range(ndim):
if i == self.axis:
continue
new_axes[i] = self._get_comb_axis(i)
else:
if len(self.join_axes) != ndim - 1:
raise AssertionError("length of join_axes must not be equal "
"to {length}".format(length=ndim - 1))

# ufff...
indices = compat.lrange(ndim)
indices.remove(self.axis)

for i, ax in zip(indices, self.join_axes):
new_axes[i] = ax
for i in range(ndim):
if i == self.axis:
continue
new_axes[i] = self._get_comb_axis(i)

new_axes[self.axis] = self._get_concat_axis()
return new_axes
Expand Down

0 comments on commit f7902e4

Please sign in to comment.