From 327a9799a207c59626af28f138831f43dec70ae1 Mon Sep 17 00:00:00 2001 From: joangq Date: Wed, 15 May 2024 18:57:53 -0300 Subject: [PATCH] =?UTF-8?q?Agrego=20auto-replicaci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_transformers/default_transformers.py | 6 ++++++ data_transformers/dtransformers.py | 7 ++++--- data_transformers/utils.py | 14 ++++++++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/data_transformers/default_transformers.py b/data_transformers/default_transformers.py index 28c3067..fcc3352 100644 --- a/data_transformers/default_transformers.py +++ b/data_transformers/default_transformers.py @@ -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 \ No newline at end of file diff --git a/data_transformers/dtransformers.py b/data_transformers/dtransformers.py index 1014564..d1789a4 100644 --- a/data_transformers/dtransformers.py +++ b/data_transformers/dtransformers.py @@ -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 diff --git a/data_transformers/utils.py b/data_transformers/utils.py index 49074f3..d1cb10c 100644 --- a/data_transformers/utils.py +++ b/data_transformers/utils.py @@ -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 = [] @@ -28,4 +28,14 @@ def callstack_to_str(callstack): frames.append('-'*30) frames.append('') - return '\n'.join(frames) \ No newline at end of file + 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)' \ No newline at end of file