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

Implement Index.copy & MultiIndex.copy #939

Merged
merged 4 commits into from
Oct 21, 2019
Merged

Conversation

itholic
Copy link
Contributor

@itholic itholic commented Oct 18, 2019

like pandas (https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Index.copy.html#pandas.Index.copy)

implement function copy for Index

>>> df = ks.DataFrame([[1, 2], [4, 5], [7, 8]],
...                   index=['cobra', 'viper', 'sidewinder'],
...                   columns=['max_speed', 'shield'])
>>> df
            max_speed  shield
cobra               1       2
viper               4       5
sidewinder          7       8
>>> df.index
Index(['cobra', 'viper', 'sidewinder'], dtype='object')

>>> df.index.copy()
Index(['cobra', 'viper', 'sidewinder'], dtype='object')

>>> df.index.copy(name='snake')
Index(['cobra', 'viper', 'sidewinder'], dtype='object', name='snake')

@itholic itholic changed the title Implement Index.copy [WIP] Implement Index.copy Oct 18, 2019
@itholic
Copy link
Contributor Author

itholic commented Oct 18, 2019

While i'm here, i'm going to make this possible to support MultiIndex also.
Above resolved:

>>> midx = pd.MultiIndex([['a', 'b', 'c'],
...                       ['lama', 'cow', 'falcon'],
...                       ['speed', 'weight', 'length']],
...                      [[0, 0, 0, 0, 0, 0, 1, 1, 1],
...                       [0, 0, 0, 1, 1, 1, 2, 2, 2],
...                       [0, 0, 0, 0, 1, 2, 0, 1, 2]]
...  )
>>> s = ks.Series([45, 200, 1.2, 30, 250, 1.5, 320, 1, 0.3],
...              index=midx)

>>> s.index
MultiIndex([('a',   'lama',  'speed'),
            ('a',   'lama',  'speed'),
            ('a',   'lama',  'speed'),
            ('a',    'cow',  'speed'),
            ('a',    'cow', 'weight'),
            ('a',    'cow', 'length'),
            ('b', 'falcon',  'speed'),
            ('b', 'falcon', 'weight'),
            ('b', 'falcon', 'length')],
           )

>>> s.index.copy()
MultiIndex([('a',   'lama',  'speed'),
            ('a',   'lama',  'speed'),
            ('a',   'lama',  'speed'),
            ('a',    'cow',  'speed'),
            ('a',    'cow', 'weight'),
            ('a',    'cow', 'length'),
            ('b', 'falcon',  'speed'),
            ('b', 'falcon', 'weight'),
            ('b', 'falcon', 'length')],
           )

@itholic itholic changed the title [WIP] Implement Index.copy Implement Index.copy & MultiIndex.copy Oct 18, 2019
@softagram-bot
Copy link

Softagram Impact Report for pull/939 (head commit: 9b5bee7)

⭐ Change Overview

Showing the changed files, dependency changes and the impact - click for full size
(Open in Softagram Desktop for full details)

📄 Full report

Impact Report explained. Give feedback on this report to [email protected]

@codecov-io
Copy link

codecov-io commented Oct 18, 2019

Codecov Report

Merging #939 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #939      +/-   ##
==========================================
+ Coverage   94.46%   94.47%   +<.01%     
==========================================
  Files          34       34              
  Lines        6382     6390       +8     
==========================================
+ Hits         6029     6037       +8     
  Misses        353      353
Impacted Files Coverage Δ
databricks/koalas/missing/indexes.py 100% <ø> (ø) ⬆️
databricks/koalas/indexes.py 97.38% <100%> (+0.18%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 465861c...9b5bee7. Read the comment docs.

@HyukjinKwon HyukjinKwon merged commit 580f48c into databricks:master Oct 21, 2019
def copy(self):
"""
Make a copy of this object.
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add an example but I think it's fine for now since it's incomplete for now due to missing name anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for reviewing. i'm planning to implement name, after then i'll add the example here also.

@itholic itholic deleted the i.copy branch October 23, 2019 04:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants