示例#1
0
    def loc(self):
        """
        Access a group of rows by label(s) or a boolean array.

        ``.loc[]`` is primarily label based, but may also be used with a
        boolean array.

        If the selection result is a DataFrame or Series, Woodwork typing
        information will be initialized for the returned object when possible.

        Allowed inputs are:
            A single label, e.g. ``5`` or ``'a'``, (note that ``5`` is
            interpreted as a *label* of the index, and **never** as an
            integer position along the index).
            A list or array of labels, e.g. ``['a', 'b', 'c']``.
            A slice object with labels, e.g. ``'a':'f'``.
            A boolean array of the same length as the axis being sliced,
            e.g. ``[True, False, True]``.
            An alignable boolean Series. The index of the key will be aligned before
            masking.
            An alignable Index. The Index of the returned selection will be the input.
            A ``callable`` function with one argument (the calling Series or
            DataFrame) and that returns valid output for indexing (one of the above)
        """
        if self._schema is None:
            _raise_init_error()
        return _locIndexer(self._dataframe)
示例#2
0
def test_locIndexer_class(sample_df):
    sample_df.ww.init()
    ind = _locIndexer(sample_df)
    pd.testing.assert_frame_equal(to_pandas(ind.data), to_pandas(sample_df))
    pd.testing.assert_frame_equal(to_pandas(ind[1:2]), to_pandas(sample_df.loc[1:2]))
    single_val = ind[0, 'id']
    if dd and isinstance(single_val, dd.Series):
        # Dask returns a series - convert to pandas to check the value
        single_val = single_val.compute()
        assert len(single_val) == 1
        single_val = single_val.loc[0]
    assert single_val == 0