def get_ext_other_df_combine_first(self, context=None): df = context['_self'] (nr, nc) = df.shape if np.random.choice([0, 1]) == 0: val = self.df_generator.call( DfConfig(num_cols=nc, num_rows=nr, nan_prob=0.2)) val.columns = df.columns val.index = df.index else: val = self.df_generator.call( DfConfig(index_levels=df.index.nlevels, column_levels=df.columns.nlevels, col_prefix='i1_', nan_prob=0.2)) if df.index.nlevels == 1: val.index = pd.Index( random.sample(set((list(df.index) + list(val.index))), len(val.index))) else: val.index = pd.MultiIndex.from_tuples( random.sample(set((list(df.index) + list(val.index))), len(val.index))) if df.columns.nlevels == 1: val.columns = pd.Index( random.sample(set((list(df.columns) + list(val.columns))), len(val.columns))) else: val.columns = pd.MultiIndex.from_tuples( random.sample(set((list(df.columns) + list(val.columns))), len(val.columns))) return val
def get_ext_other_df_ne_like(self, context=None): df = context['_self'] (nr, nc) = df.shape cond = self.df_generator.call( DfConfig(num_rows=nr, num_cols=nc, value_bags=Bags.bool_bags)) cond.columns = df.columns cond.index = df.index new_df = self.df_generator.call(DfConfig(num_rows=nr, num_cols=nc)) new_df.columns = df.columns new_df.index = df.index return df.where(cond, new_df)
def get_ext_other_df_align(self, context=None): df = context['_self'] (nr, nc) = df.shape val = self.df_generator.call( DfConfig(num_rows=random.choice([max((nr - 1), 1), nr, (nr + 1)]), num_cols=random.choice([max((nc - 1), 1), nc, (nc + 1)]), col_prefix='i1_', index_levels=df.index.nlevels, column_levels=df.columns.nlevels, value_bags=[*Bags.int_bags, *Bags.float_bags])) if (np.random.choice([0, 1]) == 0) and (len(val.index) == nr): val.index = df.index elif df.index.nlevels == 1: val.index = pd.Index( random.sample(set((list(df.index) + list(val.index))), len(val.index))) else: val.index = pd.MultiIndex.from_tuples( random.sample(set((list(df.index) + list(val.index))), len(val.index))) if (np.random.choice([0, 1]) == 0) and (len(val.columns) == nc): val.columns = df.columns elif df.columns.nlevels == 1: val.columns = pd.Index( random.sample(set((list(df.columns) + list(val.columns))), len(val.columns))) else: val.columns = pd.MultiIndex.from_tuples( random.sample(set((list(df.columns) + list(val.columns))), len(val.columns))) return val
def get_ext_right_df_merge(self, context=None): df = context['_self'] new_df: pd.DataFrame = self.df_generator.call( DfConfig(col_prefix='i1_')) dg1 = collections.defaultdict(list) dg2 = collections.defaultdict(list) for (k, v) in dict(df.dtypes).items(): dg1[v].append(k) for (k, v) in dict(new_df.dtypes).items(): dg2[v].append(k) c = (set(dg1.keys()) & set(dg2.keys())) for dt in c: cols1 = list(dg1[dt]) cols2 = list(dg2[dt]) random.shuffle(cols1) random.shuffle(cols2) pairs = list(zip(cols1, cols2)) for pair in pairs: if np.random.choice([0, 1]) == 0: new_df[pair[1]] = random.sample( (list(new_df[pair[1]]) + list(df[pair[0]])), new_df.shape[0]) if (np.random.choice([0, 1]) == 0) and (pair[0] not in new_df.columns): new_df = new_df.rename({ pair[1]: pair[0], }, axis=1) return new_df
def get_ext_cond_df_where_mask(self, context=None): df, nr, nc = context['_self'], context['num_rows'], context['num_cols'] cond_df = self.df_generator.call( DfConfig(num_rows=nr, num_cols=nc, value_bags=Bags.bool_bags, index_like_columns_prob=0.0)) cond_df.index = df.index cond_df.columns = df.columns return cond_df
def get_ext_other_df_combine(self, context=None): df = context['_self'] (nr, nc) = df.shape new_df = self.df_generator.call( DfConfig(num_rows=nr, num_cols=nc, value_bags=[*Bags.int_bags, *Bags.float_bags])) new_df.columns = df.columns new_df.index = df.index return new_df
def get_ext_other_df_reindex_like(self, context=None): df = context['_self'] val = self.df_generator.call( DfConfig(index_levels=df.index.nlevels, col_prefix=random.choice(['', 'i1_']), value_bags=[*Bags.int_bags, *Bags.float_bags])) if df.index.nlevels == 1: val.index = pd.Index( random.sample(set((list(df.index) + list(val.index))), len(val.index))) else: val.index = pd.MultiIndex.from_tuples( random.sample(set((list(df.index) + list(val.index))), len(val.index))) return val
def get_ext_other_df_add_like(self, context=None): df = context['_self'] (nr, nc) = df.shape v_nc = random.choice([nc, nc, nc, nc - 1, nc + 1]) new_df = self.df_generator.call( DfConfig(num_cols=v_nc, num_rows=nr, column_levels=df.columns.nlevels, index_like_columns_prob=0.0, col_prefix='i1_', value_bags=[*Bags.int_bags, *Bags.float_bags])) new_df.index = df.index if (np.random.choice([0, 1]) == 0) and (len(new_df.columns) == nc): new_df.columns = df.columns elif df.columns.nlevels == 1: new_df.columns = pd.Index( random.sample(set((list(df.columns) + list(new_df.columns))), len(new_df.columns))) else: new_df.columns = pd.MultiIndex.from_tuples( random.sample(set((list(df.columns) + list(new_df.columns))), len(new_df.columns))) return new_df
def get_ext_other_df_equals(self, context=None): return self.df_generator.call( DfConfig(col_prefix=random.choice(['', 'i1_'])))
def get_ext_self_df_duplicate_removal(self, context=None): return self.df_generator.call(DfConfig(min_height=3))
def get_ext_self_df_computational(self, context=None): return self.df_generator.call(DfConfig(nan_prob=0.1))
def get_ext_self_df_reorder_levels(self, context=None): return self.df_generator.call( DfConfig(multi_index_prob=0.6, multi_col_index_prob=0.4))
def get_ext_self_df_combine_first(self, context=None): return self.df_generator.call(DfConfig(nan_prob=0.2))
def get_ext_self_df_int_and_floats(self, context=None): return self.df_generator.call( DfConfig(value_bags=[*Bags.int_bags, *Bags.float_bags], index_like_columns_prob=0.0))
def get_ext_other_df_where_mask(self, context=None): df, nr, nc = context['_self'], context['num_rows'], context['num_cols'] other_df = self.df_generator.call(DfConfig(num_rows=nr, num_cols=nc)) other_df.index = df.index other_df.columns = df.columns return other_df
def get_ext_self_df_dropna_fillna(self, context=None): return self.df_generator.call(DfConfig(nan_prob=0.3))
def get_ext_self_df_pivot(self, context=None): return self.df_generator.call(DfConfig(column_levels=1))
def get_ext_self_df_all_any(self, context=None): return self.df_generator.call( DfConfig(value_bags=[ *Bags.int_bags, *Bags.string_bags, *Bags.bool_bags, *Bags.bool_bags ]))
def get_ext_self_df_count(self, context=None): return self.df_generator.call(DfConfig(nan_prob=0.5))
def get_ext_input_df_isna_notna(self, context=None): return self.df_generator.call(DfConfig(nan_prob=0.5))