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

[ENH] A cleaner API for the "move" function #999

Open
thatlittleboy opened this issue Jan 26, 2022 · 0 comments
Open

[ENH] A cleaner API for the "move" function #999

thatlittleboy opened this issue Jan 26, 2022 · 0 comments

Comments

@thatlittleboy
Copy link
Contributor

Brief Description

Arose from discussion in PR #997 , proposed by @ericmjl , comment / review here.

The proposal is for a more declarative approach for move function. At the moment, the API is as such:

# present API
>>> import pandas as pd
>>> import janitor
>>> df = pd.DataFrame({"a": [2, 4, 6, 8], "b": list("wxyz")})
>>> df
   a  b
0  2  w
1  4  x
2  6  y
3  8  z
>>> df.move(source=0, target=3, position="before", axis=0)
   a  b
1  4  x
2  6  y
0  2  w
3  8  z

Proposed API

# args order is [axis, source, position, target, cmd], all default to None.
# `cmd` is a placeholder; we don't have to use this name, can be called something better instead.
df.move("row", 0, "after", 3)
df.move("column", "b", "after", "c")

# here we pass in only cmd, which gets split into [axis, source, position, target]
# and used in the underlying implementation.
df.move(cmd="row 0 after 3")
df.move(cmd="column b after c")
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

No branches or pull requests

1 participant