def get_items( source: Union[str, pd.DataFrame, RawItems], start: int, count: Optional[int], filters: Optional[api.Filters], expand: bool, ) -> Union[JobItems, CollectionItems]: if isinstance(source, pd.DataFrame): return Items.from_df(source, expand=expand) elif isinstance(source, Iterable) and not isinstance(source, str): return Items.from_array(source, expand=expand) elif helpers.is_job_key(source): return JobItems(key=source, start=start, count=count, filters=filters, expand=expand) elif helpers.is_collection_key(source): if start: raise ValueError( "Collections API does not support 'start' parameter") return CollectionItems(key=source, count=count, filters=filters, expand=expand) else: raise ValueError( f"'{source}' is not a valid job or collection key")
def test_flat_df(data, expected_data, expected_map): i = Items.from_array(data, expand=True) pd.testing.assert_frame_equal(i.flat_df, pd.DataFrame(expected_data), check_like=False) for new, old in expected_map.items(): assert i.origin_column_name(new) == old
def get_items( source: Union[str, pd.DataFrame, RawItems], count: Optional[int], start: Optional[str], filters: Optional[api.Filters], ) -> Items: if isinstance(source, pd.DataFrame): return Items.from_df(source) elif isinstance(source, Iterable) and not isinstance(source, str): return Items.from_array(cast(RawItems, source)) elif helpers.is_job_key(source): return JobItems(source, count, int(start or 0), filters) elif helpers.is_collection_key(source): return CollectionItems(source, count, start, filters) else: raise ValueError( f"'{source}' is not a valid job or collection key")
def test_items_from_array(raw): items = Items.from_array(raw) np.testing.assert_array_equal(items.raw, np.array(raw)) pd.testing.assert_frame_equal(items.df, pd.DataFrame(list(raw)))