Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
meta_columns = dict(meta.kind_meta.get('columns'))
if meta_columns:
# apply projection, if any
if columns:
# get only projected columns
# meta_columns is {origin_column: stored_column}
orig_columns = dict({k: v for k, v in iteritems(meta_columns)
if k in columns or v in columns})
else:
# restore columns to original name
orig_columns = meta_columns
df.rename(columns=orig_columns, inplace=True)
# -- restore indexes
idx_meta = meta.kind_meta.get('idx_meta')
if idx_meta:
df = restore_index(df, idx_meta)
# -- restore row order
if is_series:
index = df.index
name = df.columns[0]
df = df[name]
df.index = index
df.name = None if name == 'None' else name
return df
def _restore_dataframe_proper(self, df):
df = restore_index(df, dict())
if '_id' in df.columns:
df.drop('_id', axis=1, inplace=True)
if self.force_columns:
missing = set(self.force_columns) - set(self.columns)
for col in missing:
df[col] = np.NaN
return df
def evaluate(self):
"""
evaluate the query
:return: the pandas DataFrame
"""
result = self.q.apply_filter(self.coll)
try:
import pandas as pd
result = pd.DataFrame.from_records(result)
if '_id' in result.columns:
del result['_id']
result = restore_index(result, dict(),
rowid_sort=not self.q.sorted)
except ImportError:
result = list(result)
return result