Construct a DataFrameHolder and then return either that or the DataFrame.
436022
def return_obj(cols, df, return_cols=False):
        """"""
        df_holder = DataFrameHolder(cols=cols, df=df)
        return df_holder.return_self(return_cols=return_cols)
192153
def _construct_result(left, result, index, name, dtype=None):
    
    out = left._constructor(result, index=index, dtype=dtype)
    out = out.__finalize__(left)
    out.name = name
    return out
1072407
def to_placeholder(self, name=None, db_type=None):
    
    if name is None:
      placeholder = self.unnamed_placeholder
    else:
      placeholder = self.named_placeholder.format(name)

    if db_type:
      return self.typecast(placeholder, db_type)
    else:
      return placeholder
420929
def construct(self):
        ''''''
        if self.__construct is None:
            self.__construct = self._construct()
        return self.__construct
1306998
def to_frame(self, **kwargs):
        
        """
        df = export.write_dataframe(self._values, **kwargs)
        df.name = self.title
        return df
1282521
def get_data(self):
        
        if self.handle is None:
            raise Exception("Cannot get data before construct Dataset")
        if self.data is not None and self.used_indices is not None and self.need_slice:
            if isinstance(self.data, np.ndarray) or scipy.sparse.issparse(self.data):
                self.data = self.data[self.used_indices, :]
            elif isinstance(self.data, DataFrame):
                self.data = self.data.iloc[self.used_indices].copy()
            elif isinstance(self.data, DataTable):
                self.data = self.data[self.used_indices, :]
            else:
                warnings.warn("Cannot subset {} type of raw data.\n"
                              "Returning original raw data".format(type(self.data).__name__))
            self.need_slice = False
        return self.data
563163
def construct(self):
        
        if self.handle is None:
            if self.reference is not None:
                if self.used_indices is None:
                    # create valid
                    self._lazy_init(self.data, label=self.label, reference=self.reference,
                                    weight=self.weight, group=self.group,
                                    init_score=self.init_score, predictor=self._predictor,
                                    silent=self.silent, feature_name=self.feature_name, params=self.params)
                else:
                    # construct subset
                    used_indices = list_to_1d_numpy(self.used_indices, np.int32, name='used_indices')
                    assert used_indices.flags.c_contiguous
                    if self.reference.group is not None:
                        group_info = np.array(self.reference.group).astype(int)
                        _, self.group = np.unique(np.repeat(range_(len(group_info)), repeats=group_info)[self.used_indices],
                                                  return_counts=True)
                    self.handle = ctypes.c_void_p()
                    params_str = param_dict_to_str(self.params)
                    _safe_call(_LIB.LGBM_DatasetGetSubset(
                        self.reference.construct().handle,
                        used_indices.ctypes.data_as(ctypes.POINTER(ctypes.c_int32)),
                        ctypes.c_int(used_indices.shape[0]),
                        c_str(params_str),
                        ctypes.byref(self.handle)))
                    self.data = self.reference.data
                    self.get_data()
                    if self.group is not None:
                        self.set_group(self.group)
                    if self.get_label() is None:
                        raise ValueError("Label should not be None.")
            else:
                # create train
                self._lazy_init(self.data, label=self.label,
                                weight=self.weight, group=self.group,
                                init_score=self.init_score, predictor=self._predictor,
                                silent=self.silent, feature_name=self.feature_name,
                                categorical_feature=self.categorical_feature, params=self.params)
            if self.free_raw_data:
                self.data = None
        return self
421535
def to_pandas(self):
        
        dataframe = self.get().to_pandas()
        assert type(dataframe) is pandas.DataFrame or type(dataframe) is pandas.Series

        return dataframe
250782
def copy(self, *args, **kwargs):
        
        cls = self.__class__    # Note that type conversion does not perform copy
        return cls(pd.DataFrame(self).copy(*args, **kwargs))
618001
def to_pandas(self, wrap=False, **kwargs):
        

        try:
            import pandas as pd
        except ImportError:
            raise DependencyNotInstalledError(
                    'to_pandas requires `pandas` library')

        def wrapper(result):
            res = result.values
            if wrap:
                from .. import DataFrame
                return DataFrame(res, schema=self.schema)
            return res

        return self.execute(wrapper=wrapper, **kwargs)
998031
def dataSource(self, value):
        
        if isinstance(value, DataSource):
            self._dataSource = value
        else:
            raise TypeError("value must be a DataSource object")
264506
def avail(df):
    """"""
    avail = DataFrame(
        {
            "start": df.apply(lambda col: col.first_valid_index()),
            "end": df.apply(lambda col: col.last_valid_index()),
        }
    )
    return avail[["start", "end"]]
467694
def from_rdd_of_dataframes(self, rdd, column_idxs=None):
        """"""
        def frame_to_spark_sql(frame):
            """Convert a Panda's DataFrame into Spark SQL Rows"""
            return [r.tolist() for r in frame.to_records()]

        def frame_to_schema_and_idx_names(frames):
            """Returns the schema and index names of the frames. Useful
            if the frame is large and we wish to avoid transfering
            the entire frame. Only bothers to apply once per partiton"""
            try:
                frame = frames.next()
                return [(list(frame.columns), list(frame.index.names))]
            except StopIteration:
                return []

        # Store if the RDD was persisted so we don't uncache an
        # explicitly cached input.
        was_persisted = rdd.is_cached
        # If we haven't been supplied with the schema info cache the RDD
        # since we are going to eveluate the first partition and then eveluate
        # the entire RDD as part of creating a Spark DataFrame.
        (schema, index_names) = ([], [])
        if not column_idxs:
            rdd.cache()
            (schema, index_names) = rdd.mapPartitions(
                frame_to_schema_and_idx_names).first()
        else:
            (schema, index_names) = column_idxs
        # Add the index_names to the schema.
        index_names = _normalize_index_names(index_names)
        schema = index_names + schema
        ddf = DataFrame.from_schema_rdd(
            self.sql_ctx.createDataFrame(rdd.flatMap(frame_to_spark_sql),
                                         schema=schema))
        ddf._index_names = index_names
        if not was_persisted:
            rdd.unpersist()
        return ddf
1230378
def df=(new_dataframe)
      dsl_eval
      if new_dataframe.respond_to? :df_type
        @dataframe = new_dataframe
      else
        @dataframe = Remi::DataFrame.create(df_type, new_dataframe)
      end
    end
481167
def _get_result_constructor(self):
        
        if not self._values_list: # we want models
            return lambda rows: self.model._construct_instance(rows)
        elif self._flat_values_list: # the user has requested flattened list (1 value per row)
            return lambda row: row.popitem()[1]
        else:
            return lambda row: self._get_row_value_list(self._only_fields, row)
348079
def copy(self, deep=True):
        
        # TODO: https://github.com/pandas-dev/pandas/issues/22314
        # We skip the block manager till that is resolved.
        new_data = self.values.copy(deep=deep)
        return self._constructor(new_data, sparse_index=self.sp_index,
                                 fill_value=self.fill_value,
                                 index=self.index.copy(),
                                 name=self.name).__finalize__(self)
1209281
def make_value_from_datastore(self, value):
    

    if value is None:
      return None
    _json = json.loads(value, cls=JsonDecoder)
    if self.data_type == dict:
      return _json
    return self.data_type.from_json(_json)