[Tutor] Implicit passing of argument select functions being called

Αλέξανδρος Ρόδης alexanderrhodis at gmail.com
Thu Jul 14 03:56:31 EDT 2022


I've finally figured ou a solution, I'll leave it here in case it helps
someone else, using inspect.signature


The actuall functions would look like this:
`
dfilter = simple_filter(start_col = 6,)
make_pipeline(
  load_dataset(fpath="some/path.xlsx",
  header=[0,1],
  apply_internal_standard(target_col = "EtD5"),
 export_to_sql(fname  = "some/name"),
  ,
  data _filter = dfilter
  )

`
Though I doubt the actuall code cleared things up, if make_pipeline is a
forloop
and lets say apply_internal_standard needs access to dfilter (along with
others not shown here) a pretty good solution is

`
def make_pipeline(
   *args, **kwargs):
  D = args[0]
  for arg in args[1:]:
    k = inspect.signature(arg).parameters.keys()
    if "data_filter" in k:
      D = arg(D, kwargs["data_filter"] = data_filter)
    D = arg(D)
  return D
`

On Thu, Jul 14, 2022, 10:36 Peter Otten <__peter__ at web.de> wrote:

> On 10/07/2022 08:51, alexander-rodis wrote:
>
> > I'm working on a project, where accessibility is very important as it's
> > addressed to non - specialists, who may even have no knowledge of coding
> > of Python.
> >
> > In a specific section, I've come up with this API to make data
> > transformation pipeline:
> >
> > make_pipeline(
> >
> >      load_data(fpath,...),
> >
> >      transform1(arg1,arg2,....),
> >
> >      ....,
> >
> >      transform2(arg1,arg2,....),
>
> Frankly, I have no idea what your actual scenario might be.
>
> If you are still interested in a comment it would help if you provide a
> more concrete scenario with two or three actual transformations working
> together on a few rows of toy data, with a filter and one or two globals
> that you are hoping to avoid.
>
> Actual code is far easier to reshuffle and improve than an abstraction
> with overgeneralized function names and signatures where you cannot tell
> the necessary elements from the artifacts of the generalization.
>


More information about the Tutor mailing list