Control Functions: Looping over Client Accounts
These functions can be imported from the ppc_robot_lib.reporting.control
module.
- for_each_client_union(selector, fn, parallel_workers=None)[source]
Executes the given
fn
for each client account specified by theselector
. The function must return a DataFrame. These DataFrames are then collected and concatenated into one DataFrame and returned.selector
can be instance of the following classes: :rtype:DataFrame
ppc_robot_lib.client_selector.PredefinedClientSelector
: iterates over a given set of Client IDs. Useful when the user has to select for which accounts the report should run.
Example:
>>> import pandas >>> from ppc_robot_lib import tasks >>> from ppc_robot_lib.reporting.control import for_each_client_union >>> from ppc_robot_lib.accounts.client_selectors.selected import SelectedClientSelector >>> # Client IDs were selected by user. >>> selector = SelectedClientsSelector({'accounts': ['111', '222', '333']}) >>> def client_fn(): ... ctx = tasks.get_context() ... return pandas.DataFrame(columns=['ExternalCustomerId'], data=[(ctx.client_id,)]) >>> for_each_client_union(selector, client_fn)
When executed, the function will return the following results:
ExternalCustomerId
111 222 333