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 Series.pop #789

Closed
HyukjinKwon opened this issue Sep 17, 2019 · 6 comments · Fixed by #866
Closed

Implement Series.pop #789

HyukjinKwon opened this issue Sep 17, 2019 · 6 comments · Fixed by #866
Labels
enhancement New feature or request

Comments

@HyukjinKwon
Copy link
Member

HyukjinKwon commented Sep 17, 2019

filter out given arugmnet in the series. See https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.pop.html?highlight=pop#pandas.Series.pop

Related to #362

@HyukjinKwon HyukjinKwon added the enhancement New feature or request label Sep 17, 2019
@HyukjinKwon
Copy link
Member Author

cc @itholic and @harupy are you interested in it?

@itholic
Copy link
Contributor

itholic commented Sep 17, 2019

@HyukjinKwon Oh it looks interesting. i'll try this out :)

@harupy
Copy link
Contributor

harupy commented Sep 17, 2019

pandas.DataFrame.pop and pandas.Series.pop use the same function internally.

https://github.com/pandas-dev/pandas/blob/v0.25.1/pandas/core/generic.py#L821-L869

@HyukjinKwon
Copy link
Member Author

Yes i checked that too but from my cursory look, we cannot share implementation in Koalas. In this case, it might better to have two separate APIs with two separate examples. It's fine to have some differences if that looks obviously better.

@itholic
Copy link
Contributor

itholic commented Sep 23, 2019

i'm working on this.

HyukjinKwon pushed a commit that referenced this issue Nov 22, 2019
Resolves #789 

```python
>>> s = ks.Series(data=np.arange(3), index=['A', 'B', 'C'])
>>> s
A    0
B    1
C    2
Name: 0, dtype: int64

>>> s.pop('A')
A    0
Name: 0, dtype: int64

>>> s
B    1
C    2
Name: 0, dtype: int64
```

Also support for MultiIndex

```python
>>> midx = pd.MultiIndex([['lama', 'cow', 'falcon'],
...                       ['speed', 'weight', 'length']],
...                      [[0, 0, 0, 1, 1, 1, 2, 2, 2],
...                       [0, 1, 2, 0, 1, 2, 0, 1, 2]])
>>> s = ks.Series([45, 200, 1.2, 30, 250, 1.5, 320, 1, 0.3],
...               index=midx)
>>> s
lama    speed      45.0
        weight    200.0
        length      1.2
cow     speed      30.0
        weight    250.0
        length      1.5
falcon  speed     320.0
        weight      1.0
        length      0.3
Name: 0, dtype: float64

>>> s.pop('lama')
lama  speed      45.0
      weight    200.0
      length      1.2
Name: 0, dtype: float64

>>> s
cow     speed      30.0
        weight    250.0
        length      1.5
falcon  speed     320.0
        weight      1.0
        length      0.3
Name: 0, dtype: float64
```

And beyond pandas, we can support for MultiIndex with specifying level.
(But i'm not sure this is necessary.)

```python
>>> midx = pd.MultiIndex([['lama', 'cow', 'falcon'],
...                       ['speed', 'weight', 'length']],
...                      [[0, 0, 0, 1, 1, 1, 2, 2, 2],
...                       [0, 1, 2, 0, 1, 2, 0, 1, 2]])
>>> s = ks.Series([45, 200, 1.2, 30, 250, 1.5, 320, 1, 0.3],
...               index=midx)
>>> s
lama    speed      45.0
        weight    200.0
        length      1.2
cow     speed      30.0
        weight    250.0
        length      1.5
falcon  speed     320.0
        weight      1.0
        length      0.3
Name: 0, dtype: float64

>>> s.pop('speed', level=1)
lama    speed     45.0
cow     speed     30.0
falcon  speed    320.0
Name: 0, dtype: float64

>>> s
lama    weight    200.0
        length      1.2
cow     weight    250.0
        length      1.5
falcon  weight      1.0
        length      0.3
Name: 0, dtype: float64
```

In pandas, above example raises TypeError like below:

```python
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: pop() got an unexpected keyword argument 'level'
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants