Skip to content

Commit

Permalink
Agrego auto-replicación
Browse files Browse the repository at this point in the history
  • Loading branch information
joangq committed May 15, 2024
1 parent d216e20 commit 327a979
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
6 changes: 6 additions & 0 deletions data_transformers/default_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ def sort_values(df: DataFrame, how: str, by: list):
@transformer.convert
def cast_col(df: DataFrame, col: str, cast_to: type):
df[col] = df[col].astype(cast_to)
return df


@transformer.convert
def rename_cols(df: DataFrame, map):
df = df.rename(columns=map)
return df
7 changes: 4 additions & 3 deletions data_transformers/dtransformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@ def __init__(self, *fs: transformer):

self.fs = fs

def transformers_source(self):
def transformers_source(self, hide_decorators=False):
sources = []
for f in self.fs:
src, count = f.sourcelines
if src[0].startswith('@'):
src = src[1:]
if hide_decorators:
if src[0].startswith('@'):
src = src[1:]
sources.append(''.join(src))
return sources

Expand Down
14 changes: 12 additions & 2 deletions data_transformers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def get_dataframe_info(df):
return buf.getvalue()

def dict_to_str(d):
return ','.join([f'{k}={v}' for k,v in d.items()])
return ', '.join([f'{k}={v!r}' for k,v in d.items()])

def callstack_to_str(callstack):
frames = []
Expand All @@ -28,4 +28,14 @@ def callstack_to_str(callstack):
frames.append('-'*30)
frames.append('')

return '\n'.join(frames)
return '\n'.join(frames)

def callstack_to_program(callstack):
code = []
for i, (f, params, presult) in enumerate(callstack[1:]):
params.pop('df', None)
params_str = dict_to_str(params)
params_str = f'{f.name}({params_str})' + (',' if i < len(callstack) - 2 else '')
code.append(params_str)

return 'pipeline = chain(\n' + '\n\t'.join(code) + '\n)'

0 comments on commit 327a979

Please sign in to comment.