Repository: pandas-dev/pandas

Issue:
CLN: move rename functionality out of internals
See comment https://github.com/pandas-dev/pandas/pull/13766#r71974566. Currently the `rename` logic lives in `internals`, cleaner would be to do this on the actual index


Discussion:

Resolving patch:
diff --git a/pandas/core/generic.py b/pandas/core/generic.py
--- a/pandas/core/generic.py
+++ b/pandas/core/generic.py
@@ -289,10 +289,7 @@ def set_axis(a, i):
                 for i, a in cls._AXIS_NAMES.items():
                     set_axis(a, i)
 
-        # addtl parms
-        if isinstance(ns, dict):
-            for k, v in ns.items():
-                setattr(cls, k, v)
+        assert not isinstance(ns, dict)
 
     def _construct_axes_dict(self, axes=None, **kwargs):
         """Return an axes dictionary for myself."""
@@ -3406,8 +3403,10 @@ def add_prefix(self, prefix):
         2       3       5
         3       4       6
         """
-        new_data = self._data.add_prefix(prefix)
-        return self._constructor(new_data).__finalize__(self)
+        f = functools.partial('{prefix}{}'.format, prefix=prefix)
+
+        mapper = {self._info_axis_name: f}
+        return self.rename(**mapper)
 
     def add_suffix(self, suffix):
         """
@@ -3463,8 +3462,10 @@ def add_suffix(self, suffix):
         2       3       5
         3       4       6
         """
-        new_data = self._data.add_suffix(suffix)
-        return self._constructor(new_data).__finalize__(self)
+        f = functools.partial('{}{suffix}'.format, suffix=suffix)
+
+        mapper = {self._info_axis_name: f}
+        return self.rename(**mapper)
 
     _shared_docs['sort_values'] = """
         Sort by the values along either axis
@@ -3980,6 +3981,7 @@ def _reindex_with_indexers(self, reindexers, fill_value=None, copy=False,
 
         return self._constructor(new_data).__finalize__(self)
 
+    # TODO: unused; remove?
     def _reindex_axis(self, new_index, fill_method, axis, copy):
         new_data = self._data.reindex_axis(new_index, axis=axis,
                                            method=fill_method, copy=copy)
diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py
--- a/pandas/core/internals/managers.py
+++ b/pandas/core/internals/managers.py
@@ -176,20 +176,11 @@ def rename_axis(self, mapper, axis, copy=True, level=None):
         axis : int
         copy : boolean, default True
         level : int, default None
-
         """
         obj = self.copy(deep=copy)
         obj.set_axis(axis, _transform_index(self.axes[axis], mapper, level))
         return obj
 
-    def add_prefix(self, prefix):
-        f = partial('{prefix}{}'.format, prefix=prefix)
-        return self.rename_axis(f, axis=0)
-
-    def add_suffix(self, suffix):
-        f = partial('{}{suffix}'.format, suffix=suffix)
-        return self.rename_axis(f, axis=0)
-
     @property
     def _is_single_block(self):
         if self.ndim == 1:
@@ -222,12 +213,10 @@ def _rebuild_blknos_and_blklocs(self):
         self._blknos = new_blknos
         self._blklocs = new_blklocs
 
-    # make items read only for now
-    def _get_items(self):
+    @property
+    def items(self):
         return self.axes[0]
 
-    items = property(fget=_get_items)
-
     def _get_counts(self, f):
         """ return a dict of the counts of the function in BlockManager """
         self._consolidate_inplace()


Test patch: