pyjanitor icon indicating copy to clipboard operation
pyjanitor copied to clipboard

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

Open thatlittleboy opened this issue 2 years ago • 0 comments

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")

thatlittleboy avatar Jan 26 '22 13:01 thatlittleboy