Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: Index.map should return Index rather than array #12766

Closed
den-run-ai opened this issue Apr 1, 2016 · 4 comments
Closed

API: Index.map should return Index rather than array #12766

den-run-ai opened this issue Apr 1, 2016 · 4 comments
Labels
API Design Compat pandas objects compatability with Numpy or Python functions
Milestone

Comments

@den-run-ai
Copy link

df2=pd.DataFrame([[0,1],[2,3]],columns=['c1','c2'],index=['i1','i2'])
df2.index.name='index'
df2.to_html()
<table border="1" class="dataframe">\n  <thead>\n    <tr style="text-align: right;">\n      <th></th>\n      <th>c1</th>\n      <th>c2</th>\n    </tr>\n    <tr>\n      <th>index</th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>i1</th>\n      <td>0</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>i2</th>\n      <td>2</td>\n      <td>3</td>\n    </tr>\n  </tbody>\n</table>
df2.index = df2.index.map(lambda x: x.upper())
df2.to_html()
<table border="1" class="dataframe">\n  <thead>\n    <tr style="text-align: right;">\n      <th></th>\n      <th>c1</th>\n      <th>c2</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>I1</th>\n      <td>0</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>I2</th>\n      <td>2</td>\n      <td>3</td>\n    </tr>\n  </tbody>\n</table>

I think map should accept inplace

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.11.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 60 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None

pandas: 0.18.0
nose: 1.3.7
pip: 8.1.1
setuptools: 18.2
Cython: None
numpy: 1.10.4
scipy: 0.17.0
statsmodels: None
xarray: None
IPython: 4.1.2
sphinx: None
patsy: None
dateutil: 2.5.1
pytz: 2016.2
blosc: None
bottleneck: 1.0.0
tables: None
numexpr: 2.5
matplotlib: 1.5.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.12
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None
@jreback
Copy link
Contributor

jreback commented Apr 1, 2016

.map return an array, not an Index. So if that is fixed then this would work.

@denfromufa pr's welcome.

@jreback jreback added API Design Compat pandas objects compatability with Numpy or Python functions labels Apr 1, 2016
@jreback jreback added this to the Next Major Release milestone Apr 1, 2016
@jreback jreback changed the title pandas map looses index name API: Index.map should return Index rather than array Apr 1, 2016
@jreback jreback modified the milestones: 0.19.0, Next Major Release Apr 1, 2016
@jreback
Copy link
Contributor

jreback commented Apr 1, 2016

inplace is not acceptable for an immutable object.

@jrings
Copy link

jrings commented Apr 5, 2016

Not sure if it's that easy, but seemed like a good start to contribute something.
Putting in a PR, I just turn it into Index before returning?

@den-run-ai
Copy link
Author

Go for it! :)

Yes it should be that simple!

On Monday, April 4, 2016, Joerg Rings notifications@github.com wrote:

Not sure if it's that easy, but seemed like a good start to contribute
something.
Putting in a PR, I just turn it into Index before returning?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#12766 (comment)

ischurov pushed a commit to ischurov/pandas that referenced this issue Dec 19, 2016
closes pandas-dev#12766
closes pandas-dev#12798

This is a follow on to pandas-dev#12798.

Author: Nate Yoder <nate@whistle.com>

Closes pandas-dev#14506 from nateyoder/index_map_index and squashes the following commits:

95e4440 [Nate Yoder] fix typo and add ref tag in whatsnew
b36e83c [Nate Yoder] update whatsnew, fix documentation
4635e6a [Nate Yoder] compare as index
a17ddab [Nate Yoder] Fix unused import and docstrings per pep8radius docformatter; change other uses of assert_index_equal to testing instead os self
ab168e7 [Nate Yoder] Update whatsnew and add git PR to tests to denote changes
504c2a2 [Nate Yoder] Fix tests that weren't run by PyCharm
23c133d [Nate Yoder] Update tests to match dtype int64
07b772a [Nate Yoder] use the numpy results if we can to avoid repeating the computation just to create the object
a110be9 [Nate Yoder] make map on time tseries indices return index if dtype of output is not a tseries; sphinx changes; fix docstring
a596744 [Nate Yoder] introspect results from map so that if the output array has tuples we create a multiindex instead of an index
5fc66c3 [Nate Yoder] make map return an index if it operates on an index, multi index, or categorical index; map on a categorical will either return a categorical or an index (rather than a numpy array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Compat pandas objects compatability with Numpy or Python functions
Projects
None yet
3 participants