Skip to content

Commit

Permalink
refac: remove inplace from functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ibiscp committed Aug 1, 2022
1 parent 11abe12 commit e838adb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
21 changes: 9 additions & 12 deletions src/wavy/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,6 @@ def sample_panel(
samples: Union[int, float] = 5,
how: str = "spaced",
reset_ids: bool = False,
inplace: bool = False,
seed: int = 42,
) -> Optional[Panel]:
"""
Expand All @@ -583,7 +582,6 @@ def sample_panel(
samples (int or float): Number or percentage of samples to return.
how (str): Sampling method, 'spaced' or 'random'
reset_ids (bool): If True, reset the index of the sampled panel.
inplace (bool): If True, perform operation in-place.
seed (int): Random seed.
Returns:
Expand Down Expand Up @@ -664,23 +662,22 @@ def sample_panel(
new_panel.val_size = val_samples
new_panel.test_size = test_samples

# TODO inplace not working
if inplace:
self = new_panel
return None
# # TODO inplace not working
# if inplace:
# self = new_panel
# return None

return new_panel

def shuffle_panel(
self, seed: int = None, reset_ids: bool = False, inplace: bool = False
self, seed: int = None, reset_ids: bool = False
) -> Optional[Panel]:
"""
Shuffle the panel.
Args:
seed (int): Random seed.
reset_ids (bool): If True, reset the index of the shuffled panel.
inplace (bool): If True, perform operation in-place.
Returns:
``Panel``: Result of shuffle function.
Expand Down Expand Up @@ -708,10 +705,10 @@ def shuffle_panel(
if reset_ids:
new_panel.reset_ids(inplace=True)

# TODO inplace not working
if inplace:
self = new_panel
return None
# # TODO inplace not working
# if inplace:
# self = new_panel
# return None

return new_panel

Expand Down
6 changes: 3 additions & 3 deletions src/wavy/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def add_annotation(self, panel, color="gray", opacity=1):

ymax = panel.max().max() if panel.train_size else 0

if panel.train_size:
if hasattr(panel, "train_size"):
xtrain_min = panel.train.index.min()
self.fig.add_vline(
x=xtrain_min, line_dash="dot", line_color=color, opacity=opacity
Expand All @@ -37,7 +37,7 @@ def add_annotation(self, panel, color="gray", opacity=1):
x=xtrain_min, y=ymax, text="Train", showarrow=False, xshift=20
)

if panel.val_size:
if hasattr(panel, "val_size"):
xval_min = panel.val.index.min()
self.fig.add_vline(
x=xval_min, line_dash="dot", line_color=color, opacity=opacity
Expand All @@ -46,7 +46,7 @@ def add_annotation(self, panel, color="gray", opacity=1):
x=xval_min, y=ymax, text="Validation", showarrow=False, xshift=35
)

if panel.test_size:
if hasattr(panel, "test_size"):
xtest_min = panel.test.index.min()
self.fig.add_vline(
x=xtest_min, line_dash="dot", line_color=color, opacity=opacity
Expand Down

0 comments on commit e838adb

Please sign in to comment.