Skip to content

Commit

Permalink
add prefix option to progress, add scheduler arg in from_pandas
Browse files Browse the repository at this point in the history
  • Loading branch information
MainRo committed Oct 6, 2022
1 parent 5aecbce commit ad35b91
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
2 changes: 2 additions & 0 deletions rxsci/internal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,7 @@ def build_tdqm_kwargs(progress):
if 'interval' in progress:
tqdm_kwargs['mininterval'] = progress['interval']
tqdm_kwargs['maxinterval'] = progress['interval']
if 'prefix' in progress:
tqdm_kwargs['desc'] = progress['prefix']

return tqdm_kwargs
4 changes: 4 additions & 0 deletions rxsci/operators/from_iterable.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
def from_iterable(iterable, scheduler=None, progress=False):
"""Converts an iterable to an observable.
When a dict is provided as the progress argument, it accepts these keys:
interval: The interval in seconds used to update the progressbar
prefix: A prefix displayed at before the progressbar.
Args:
iterable: A Python iterable
scheduler: An optional scheduler to schedule the values on.
Expand Down
17 changes: 14 additions & 3 deletions rxsci/operators/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@
except Exception:
pass

def from_pandas(dataframe, progress=False):
def from_pandas(dataframe, scheduler=None, progress=False):
"""Creates an observable from a pandas dataframe
When a dict is provided as the progress argument, it accepts these keys:
interval: The interval in seconds used to update the progressbar
prefix: A prefix displayed at before the progressbar.
Args:
dataframe: A pandas dataframe
scheduler: An optional scheduler to schedule the values on.
progess: Displays a progressbar while iterating the dataframe
Returns:
Expand All @@ -25,8 +30,14 @@ def from_pandas(dataframe, progress=False):
if 'total' not in tqdm_kwargs:
tqdm_kwargs['total']=len(dataframe)

return rx.from_(tqdm(dataframe.itertuples(index=False), **tqdm_kwargs))
return rx.from_(dataframe.itertuples(index=False))
return rx.from_(
tqdm(dataframe.itertuples(index=False), **tqdm_kwargs),
scheduler=scheduler,
)
return rx.from_(
dataframe.itertuples(index=False),
scheduler=scheduler,
)


def to_pandas(columns=None):
Expand Down
5 changes: 4 additions & 1 deletion tests/operators/test_from_iterable.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
@pytest.mark.parametrize(
"progress",
[
False, True, {'interval': 60}
False, True,
{'interval': 60},
{'prefix': 'test_from'},
{'prefix': 'test_from', 'interval': 60}
]
)
def test_from_iterable_base(progress):
Expand Down

0 comments on commit ad35b91

Please sign in to comment.