def __delitem__(self, locator): """Override the operator to delete items Examples: >>> import pyexcel as pe >>> data = [[1],[2],[3],[4],[5],[6],[7],[9]] >>> sheet = pe.Sheet(data) >>> sheet pyexcel sheet: +---+ | 1 | +---+ | 2 | +---+ | 3 | +---+ | 4 | +---+ | 5 | +---+ | 6 | +---+ | 7 | +---+ | 9 | +---+ >>> del sheet.row[1,2,3,5] >>> sheet pyexcel sheet: +---+ | 1 | +---+ | 5 | +---+ | 7 | +---+ | 9 | +---+ """ if compact.is_string(type(locator)): self._ref.delete_named_row_at(locator) elif compact.is_tuple_consists_of_strings(locator): indices = utils.names_to_indices(list(locator), self._ref.rownames) self._ref.delete_rows(indices) elif isinstance(locator, slice): my_range = utils.analyse_slice(locator, self._ref.number_of_rows()) self._ref.delete_rows(my_range) elif isinstance(locator, tuple): self._ref.filter(row_indices=(list(locator))) elif isinstance(locator, list): self._ref.filter(row_indices=locator) elif isinstance(locator, types.LambdaType): self._delete_rows_by_content(locator) elif isinstance(locator, types.FunctionType): self._delete_rows_by_content(locator) else: self._ref.delete_rows([locator])
def __delitem__(self, aslice): """Override the operator to delete items Examples: >>> import pyexcel as pe >>> data = [[1,2,3,4,5,6,7,9]] >>> sheet = pe.Sheet(data) >>> sheet pyexcel sheet: +---+---+---+---+---+---+---+---+ | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | +---+---+---+---+---+---+---+---+ >>> del sheet.column[1,2,3,5] >>> sheet pyexcel sheet: +---+---+---+---+ | 1 | 5 | 7 | 9 | +---+---+---+---+ >>> data = [ ... ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'], ... [1,2,3,4,5,6,7,9], ... ] >>> sheet = pe.Sheet(data, name_columns_by_row=0) >>> sheet pyexcel sheet: +---+---+---+---+---+---+---+---+ | a | b | c | d | e | f | g | h | +===+===+===+===+===+===+===+===+ | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | +---+---+---+---+---+---+---+---+ >>> del sheet.column['a', 'b', 'i', 'f'] # doctest:+ELLIPSIS Traceback (most recent call last): ... ValueError: ... >>> del sheet.column['a', 'c', 'e', 'h'] >>> sheet pyexcel sheet: +---+---+---+---+ | b | d | f | g | +===+===+===+===+ | 2 | 4 | 6 | 7 | +---+---+---+---+ """ is_sheet = (compact.is_string(type(aslice)) and hasattr(self.__ref, 'delete_named_column_at')) if is_sheet: self.__ref.delete_named_column_at(aslice) elif compact.is_tuple_consists_of_strings(aslice): indices = utils.names_to_indices(list(aslice), self.__ref.colnames) self.__ref.delete_columns(indices) elif isinstance(aslice, slice): my_range = utils.analyse_slice(aslice, self.__ref.number_of_columns()) self.__ref.delete_columns(my_range) elif isinstance(aslice, str): index = utils.excel_column_index(aslice) self.__ref.delete_columns([index]) elif isinstance(aslice, tuple): indices = list(aslice) self.__ref.filter(column_indices=indices) elif isinstance(aslice, list): indices = aslice self.__ref.filter(column_indices=indices) elif isinstance(aslice, int): self.__ref.delete_columns([aslice]) elif isinstance(aslice, types.LambdaType): self._delete_columns_by_content(aslice) elif isinstance(aslice, types.FunctionType): self._delete_columns_by_content(aslice) else: raise IndexError
def __delitem__(self, locator): """Override the operator to delete items Examples: >>> import pyexcel as pe >>> data = [[1],[2],[3],[4],[5],[6],[7],[9]] >>> sheet = pe.Sheet(data) >>> sheet pyexcel sheet: +---+ | 1 | +---+ | 2 | +---+ | 3 | +---+ | 4 | +---+ | 5 | +---+ | 6 | +---+ | 7 | +---+ | 9 | +---+ >>> del sheet.row[1,2,3,5] >>> sheet pyexcel sheet: +---+ | 1 | +---+ | 5 | +---+ | 7 | +---+ | 9 | +---+ """ if compact.is_string(type(locator)): self._ref.delete_named_row_at(locator) elif compact.is_tuple_consists_of_strings(locator): indices = utils.names_to_indices(list(locator), self._ref.rownames) self._ref.delete_rows(indices) elif isinstance(locator, slice): my_range = utils.analyse_slice(locator, self._ref.number_of_rows()) self._ref.delete_rows(my_range) elif isinstance(locator, tuple): self._ref.filter(row_indices=(list(locator))) elif isinstance(locator, list): self._ref.filter(row_indices=locator) elif isinstance(locator, types.LambdaType): self._delete_rows_by_content(locator) elif isinstance(locator, types.FunctionType): self._delete_rows_by_content(locator) else: self._ref.delete_rows([locator])
def __delitem__(self, aslice): """Override the operator to delete items Examples: >>> import pyexcel as pe >>> data = [[1,2,3,4,5,6,7,9]] >>> sheet = pe.Sheet(data) >>> sheet pyexcel sheet: +---+---+---+---+---+---+---+---+ | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | +---+---+---+---+---+---+---+---+ >>> del sheet.column[1,2,3,5] >>> sheet pyexcel sheet: +---+---+---+---+ | 1 | 5 | 7 | 9 | +---+---+---+---+ >>> data = [ ... ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'], ... [1,2,3,4,5,6,7,9], ... ] >>> sheet = pe.Sheet(data, name_columns_by_row=0) >>> sheet pyexcel sheet: +---+---+---+---+---+---+---+---+ | a | b | c | d | e | f | g | h | +===+===+===+===+===+===+===+===+ | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | +---+---+---+---+---+---+---+---+ >>> del sheet.column['a', 'b', 'i', 'f'] # doctest:+ELLIPSIS Traceback (most recent call last): ... ValueError: ... >>> del sheet.column['a', 'c', 'e', 'h'] >>> sheet pyexcel sheet: +---+---+---+---+ | b | d | f | g | +===+===+===+===+ | 2 | 4 | 6 | 7 | +---+---+---+---+ """ is_sheet = (compact.is_string(type(aslice)) and hasattr(self._ref, 'delete_named_column_at')) if is_sheet: self._ref.delete_named_column_at(aslice) elif compact.is_tuple_consists_of_strings(aslice): indices = utils.names_to_indices(list(aslice), self._ref.colnames) self._ref.delete_columns(indices) elif isinstance(aslice, slice): my_range = utils.analyse_slice(aslice, self._ref.number_of_columns()) self._ref.delete_columns(my_range) elif isinstance(aslice, str): index = utils.excel_column_index(aslice) self._ref.delete_columns([index]) elif isinstance(aslice, tuple): indices = list(aslice) self._ref.filter(column_indices=indices) elif isinstance(aslice, list): indices = aslice self._ref.filter(column_indices=indices) elif isinstance(aslice, int): self._ref.delete_columns([aslice]) elif isinstance(aslice, types.LambdaType): self._delete_columns_by_content(aslice) elif isinstance(aslice, types.FunctionType): self._delete_columns_by_content(aslice) else: raise IndexError