BUG: #19497 FIX. Add tupleize_cols option to internals._transform_index()
State: closed

- Closes #19497
- NO TESTS have been added/passed. Currently experiencing issues getting pandas conda environment installed so unable to do this myself. Very simple alteration however...
- Code passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- Implements tupleize_cols option for pandas.core.internals_transform_index(), and provides the capability to manipulate this option using pandas.DataFrame.rename(). 
**NOTE**: for renaming, the keyword argument default is False, because as suggested [here](https://github.com/pandas-dev/pandas/issues/19497), this is unintuitive and unexepected. The keyword argument for the _transform_index() is True however, which is consistent with default pandas.Index() creation behaviour.


Labels:
name: Indexing
description: Related to indexing on series/frames, not to indexes themselves

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/20526?src=pr&el=h1) Report
> Merging [#20526](https://codecov.io/gh/pandas-dev/pandas/pull/20526?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/0c4e611927772af44b02204192b29282341a5716?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/20526/graphs/tree.svg?width=650&height=150&src=pr&token=eZ4WkYLtcO)](https://codecov.io/gh/pandas-dev/pandas/pull/20526?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #20526      +/-   ##
==========================================
- Coverage   91.84%   91.83%   -0.01%     
==========================================
  Files         152      152              
  Lines       49259    49260       +1     
==========================================
- Hits        45241    45240       -1     
- Misses       4018     4020       +2
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.22% <100%> (-0.01%)` | :arrow_down: |
| #single | `41.89% <100%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/20526?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/20526/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.18% <ø> (ø)` | :arrow_up: |
| [pandas/core/internals.py](https://codecov.io/gh/pandas-dev/pandas/pull/20526/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW50ZXJuYWxzLnB5) | `95.53% <100%> (ø)` | :arrow_up: |
| [pandas/core/generic.py](https://codecov.io/gh/pandas-dev/pandas/pull/20526/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ2VuZXJpYy5weQ==) | `95.85% <100%> (ø)` | :arrow_up: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/20526/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `84.52% <0%> (-0.21%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/20526?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/20526?src=pr&el=footer). Last update [0c4e611...f79b82d](https://codecov.io/gh/pandas-dev/pandas/pull/20526?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Ok, so from what I gather, the only change should be:

return Index(items, name=index.name, tupleize_cols=False)

(in internals._transform_index()). If that's agreed, I can make the change
on the other side of the weekend.

On 30 March 2018 at 01:38, Tom Augspurger <notifications@github.com> wrote:

> *@TomAugspurger* commented on this pull request.
>
> I don't think that adding a new keyword to rename is the right level for
> the fix. The original example in the issue is a bug. We should fix the bug,
> not add a keyword to work around it.
>
> I'd prefer a proper fix for #17246
> <https://github.com/pandas-dev/pandas/issues/17246> (Index(...,
> dtype='object') is respected). Then to fix this bug, we'd pass through
> self.index.dtype I think.
> ------------------------------
>
> In pandas/core/frame.py
> <https://github.com/pandas-dev/pandas/pull/20526#discussion_r178075198>:
>
> > @@ -3642,6 +3642,10 @@ def rename(self, *args, **kwargs):
>          level : int or level name, default None
>              In case of a MultiIndex, only rename labels in the specified
>              level.
> +        tupleize_cols : boolean, default False
>
> I'd prefer not to add a new keyword argument here. I don't think that
> .rename should be able to change between Index and MultiIndex, so it
> shouldn't be necessary.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/20526#pullrequestreview-108071684>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ADhP44mGQTUIL8gMcH0Cex8mZdWWtbyZks5tjPHJgaJpZM4S_0vU>
> .
>

this PR is not likely to be accepted, esp as there are no tests. We are not going to be adding a specific argument to ``.rename`` to special handle a very non-idiomatic special case here. If you want to propose something, do so on the original issue.