コード例 #1
0
ファイル: arche.py プロジェクト: codacy-badger/arche
 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")
コード例 #2
0
ファイル: arche.py プロジェクト: zanachka/arche
 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")
コード例 #3
0
def test_items_from_df(df, expected_raw, expected_df):
    items = Items.from_df(df)
    np.testing.assert_array_equal(items.raw, expected_raw)
    pd.testing.assert_frame_equal(items.df, expected_df)
コード例 #4
0
def test_origin_column_name(get_cloud_items, name, expected_name):
    items = Items.from_df(pd.DataFrame(get_cloud_items))
    assert items.origin_column_name(name) == expected_name