API: map() on Index returns an Index, not array
State: closed

Continued in #14506

- [x] closes #12766 
- [x] tests added / passed
- [x] passes `git diff upstream/master | flake8 --diff`
- [x] whatsnew entry


Labels:
name: API Design
name: Compat
description: pandas objects compatability with Numpy or Python functions

Comments:
Not sure about where the whatsnew entry will go? 

Thanks! whatsnew locates on `doc/source/whatsnew`.

Also, I think it is an API change, rather than a bug (as original issue is tagged). 

Thanks @sinhrks for the friendly review! This is my first PR, so it's a good opportunity to get a start!
I made those changes, let me know if this is what you had in mind!

Also, the Travis failures seem to be unrelated?

@jrings you need to rebase on master. Things changed a bit today.

Ugh rebase doesn't like me. Never has never will. Have rebased, will try to squash if changes are ok? (or cry for help)

http://pandas.pydata.org/pandas-docs/stable/contributing.html#contributing-your-changes-to-pandas

```
git checkout yourbranch
git rebase -i origin/master
```

then
`git push yourremote yourbranch -f`

Yeah I merged on the master to my master, then to my branch. Will work on fixing it, I finally need to figure this out :D

After properly rebased, pls fix datetimelike `map` consistently. 
- https://github.com/pydata/pandas/blob/master/pandas/tseries/base.py#L226

Also, adding more dtype tests (you can find some examples here).
- https://github.com/pydata/pandas/blob/master/pandas/tests/indexes/test_base.py#L37

Ok, cleaned up the rebase mess, will react to the rest later or tomorrow. Thanks!

@sinhrks Oh I see, by different dtypes you meant testing map on the different index flavors, not a type conversion on the Index?

@jrings thx for the fix. yes i meant different classes.

Ok, need some advice. Added almost all the index types successfully (pushed what I have so far), but failed on the categorical:

``` python
======================================================================
ERROR: test_map (pandas.tests.indexes.test_base.TestIndex)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/joerg/src/pandas/pandas/tests/indexes/test_base.py", line 1593, in test_map
    testIdx = self.catIndex.map(lambda x: int(x))
  File "/home/joerg/src/pandas/pandas/indexes/base.py", line 2201, in map
    return self._shallow_copy_with_infer(self._arrmap(self.values, mapper))
TypeError: Argument 'index' has incorrect type (expected numpy.ndarray, got Categorical)
```

Can you give me a pointer to how to fix this? i guess since the .c mapper doesn't cover this, I'd check for a CategoricalIndex and handle it in Python instead? Or, rather, implement a separate `map` in `CategoricalIndex`?

The `CategoricalIndex` error should be handled in #12532. Let me update it.

Ok, yeah sorry that `print` was left over from figuring out the catIndex, and I'll dedupe the whatsnew entry as well. Should I wait for #12532 to be merged then? 

Also, should I do anything for empty and tuples Index?

#12532 has been merged, can you update? 

Ok categorical works now! Rebased on master and squashed commits.
@sinhrks 

Will work on it this weekend!

Sorry for being slow, am traveling a lot at the moment. But one question @jreback, would a very simple function for `map` be enough, just to test that a map still produces an `Index`, because then putting it all in the loop of the various indexes would be fine, but if I would try to transfer my more varied tests that would lead to a lot of `isinstance` for each type that would sort of defeat the purpose - so then I'd distribute them over all the different test classes for each type of index?

can you rebase/update

can you rebase/update

can you rebase / update?

pls rebase / update

If this has stalled I'd be more than happy to take it over as I'd really like to see and #12756 make it into a release soon.  Is the easiest way to do this by creating a new PR or can I use this one somehow?

create a new PR. you can incorporate this commit (if you'd like). you can add a closes (this PR number) as well as the issue number.

Continued in #14506