diff --git a/src/pypelines/__init__.py b/src/pypelines/__init__.py index 40b96c9f2635f4d47b9843870cfd159acbcee48c..c8a9b2677e78459789d9b0b8866b9883e7890f9a 100644 --- a/src/pypelines/__init__.py +++ b/src/pypelines/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.0.56" +__version__ = "0.0.57" from . import loggs from .pipes import * diff --git a/src/pypelines/pipes.py b/src/pypelines/pipes.py index aca5ce15a7f9f7b41251a2913537683970ff6e68..0f95a07ec5dbb1cfeb06a9da5baf6109c1c471ea 100644 --- a/src/pypelines/pipes.py +++ b/src/pypelines/pipes.py @@ -6,6 +6,8 @@ from .disk import BaseDiskObject from functools import wraps import inspect, hashlib +from pandas import DataFrame + from abc import ABCMeta, abstractmethod from typing import Callable, Type, Iterable, Protocol, TYPE_CHECKING, Literal, Dict @@ -208,7 +210,23 @@ class BasePipe(metaclass=ABCMeta): list(self.steps.values()), key=lambda item: item.get_level(selfish=True), reverse=reverse ) + highest_step = None + + if isinstance(session, DataFrame): + # if multisession, we assume we are trying to just load sessions + # that all have reached the same level of requirements. (otherwise, use generate) + # because of that, we use only the first session in the lot to search the highest loadable step + search_on_session = session.iloc[0] + else: + search_on_session = session + for step in ordered_steps: - if step.get_disk_object(session, extra).is_matching(): - return step.load(session, extra) + if step.get_disk_object(search_on_session, extra).is_matching(): + highest_step = step + + if highest_step is not None: # if we found one : it is not None + # we use the load wrapper, wich will dispatch to multissession or not automatically, + # depending on session type (Series or DataFrame) + return highest_step.load(session, extra) + raise ValueError(f"Could not find a {self} object to load for the session {session.alias} with extra {extra}") diff --git a/src/pypelines/steps.py b/src/pypelines/steps.py index 3d7116561c72eedd4aa3234e9494788d7535674f..e624fc9d384d711d38c774fb415d80b82129e8c8 100644 --- a/src/pypelines/steps.py +++ b/src/pypelines/steps.py @@ -1,8 +1,9 @@ from functools import wraps, partial, update_wrapper from .loggs import loggedmethod, NAMELENGTH from .arguments import autoload_arguments -import logging, inspect +import logging, inspect +from pandas import DataFrame from dataclasses import dataclass from types import MethodType @@ -258,6 +259,9 @@ class BaseStep: ValueError: If the disk object does not match and has a status message. """ # print("extra in load wrapper : ", extra) + if isinstance(session, DataFrame): + return self.multisession.load(sessions=session, extras=extra) + if extra is None: extra = self.get_default_extra() # print("extra in load wrapper after None : ", extra)