Skip to content

Commit

Permalink
sync names with other packages, generic to extract row and column names
Browse files Browse the repository at this point in the history
  • Loading branch information
jkanche committed Dec 27, 2023
1 parent 9e20101 commit 672c4d9
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 34 deletions.
68 changes: 34 additions & 34 deletions src/summarizedexperiment/BaseSE.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,14 +520,14 @@ def col_data(self, rows: Optional[biocframe.BiocFrame]):
######>> row names <<#####
##########################

def get_rownames(self) -> Optional[ut.Names]:
def get_row_names(self) -> Optional[ut.Names]:
"""
Returns:
List of row names, or None if no row names are available.
"""
return self._row_names

def set_rownames(
def set_row_names(
self, names: Optional[List[str]], in_place: bool = False
) -> "BaseSE":
"""Set new row names.
Expand Down Expand Up @@ -556,50 +556,50 @@ def set_rownames(

@property
def rownames(self) -> Optional[ut.Names]:
"""Alias for :py:attr:`~get_rownames`, provided for back-compatibility."""
return self.get_rownames()
"""Alias for :py:attr:`~get_row_names`, provided for back-compatibility."""
return self.get_row_names()

@rownames.setter
def rownames(self, names: Optional[List[str]]):
"""Alias for :py:meth:`~set_rownames` with ``in_place = True``.
"""Alias for :py:meth:`~set_row_names` with ``in_place = True``.
As this mutates the original object, a warning is raised.
"""
warn(
"Setting property 'row_names' is an in-place operation, use 'set_rownames' instead",
"Setting property 'row_names' is an in-place operation, use 'set_row_names' instead",
UserWarning,
)
self.set_rownames(names, in_place=True)
self.set_row_names(names, in_place=True)

@property
def row_names(self) -> Optional[ut.Names]:
"""Alias for :py:attr:`~get_rownames`, provided for back-compatibility."""
return self.get_rownames()
"""Alias for :py:attr:`~get_row_names`, provided for back-compatibility."""
return self.get_row_names()

@row_names.setter
def row_names(self, names: Optional[List[str]]):
"""Alias for :py:meth:`~set_rownames` with ``in_place = True``.
"""Alias for :py:meth:`~set_row_names` with ``in_place = True``.
As this mutates the original object, a warning is raised.
"""
warn(
"Setting property 'row_names' is an in-place operation, use 'set_rownames' instead",
"Setting property 'row_names' is an in-place operation, use 'set_row_names' instead",
UserWarning,
)
self.set_rownames(names, in_place=True)
self.set_row_names(names, in_place=True)

#############################
######>> column names <<#####
#############################

def get_columnnames(self) -> Optional[ut.Names]:
def get_column_names(self) -> Optional[ut.Names]:
"""
Returns:
List of column names, or None if no column names are available.
"""
return self._column_names

def set_columnnames(
def set_column_names(
self, names: Optional[List[str]], in_place: bool = False
) -> "BaseSE":
"""Set new column names.
Expand Down Expand Up @@ -628,71 +628,71 @@ def set_columnnames(

@property
def columnnames(self) -> Optional[ut.Names]:
"""Alias for :py:attr:`~get_columnnames`, provided for back-compatibility."""
return self.get_columnnames()
"""Alias for :py:attr:`~get_column_names`, provided for back-compatibility."""
return self.get_column_names()

@columnnames.setter
def columnnames(self, names: Optional[List[str]]):
"""Alias for :py:meth:`~set_columnnames` with ``in_place = True``.
"""Alias for :py:meth:`~set_column_names` with ``in_place = True``.
As this mutates the original object, a warning is raised.
"""
warn(
"Setting property 'column_names' is an in-place operation, use 'set_columnnames' instead",
"Setting property 'column_names' is an in-place operation, use 'set_column_names' instead",
UserWarning,
)
self.set_columnnames(names, in_place=True)
self.set_column_names(names, in_place=True)

@property
def colnames(self) -> Optional[ut.Names]:
"""Alias for :py:attr:`~get_columnnames`, provided for back-compatibility."""
return self.get_columnnames()
"""Alias for :py:attr:`~get_column_names`, provided for back-compatibility."""
return self.get_column_names()

@colnames.setter
def colnames(self, names: Optional[List[str]]):
"""Alias for :py:meth:`~set_columnnames` with ``in_place = True``.
"""Alias for :py:meth:`~set_column_names` with ``in_place = True``.
As this mutates the original object, a warning is raised.
"""
warn(
"Setting property 'column_names' is an in-place operation, use 'set_columnnames' instead",
"Setting property 'column_names' is an in-place operation, use 'set_column_names' instead",
UserWarning,
)
self.set_columnnames(names, in_place=True)
self.set_column_names(names, in_place=True)

@property
def col_names(self) -> Optional[ut.Names]:
"""Alias for :py:attr:`~get_columnnames`, provided for back-compatibility."""
return self.get_columnnames()
"""Alias for :py:attr:`~get_column_names`, provided for back-compatibility."""
return self.get_column_names()

@col_names.setter
def col_names(self, names: Optional[List[str]]):
"""Alias for :py:meth:`~set_columnnames` with ``in_place = True``.
"""Alias for :py:meth:`~set_column_names` with ``in_place = True``.
As this mutates the original object, a warning is raised.
"""
warn(
"Setting property 'column_names' is an in-place operation, use 'set_columnnames' instead",
"Setting property 'column_names' is an in-place operation, use 'set_column_names' instead",
UserWarning,
)
self.set_columnnames(names, in_place=True)
self.set_column_names(names, in_place=True)

@property
def column_names(self) -> Optional[ut.Names]:
"""Alias for :py:attr:`~get_rownames`, provided for back-compatibility."""
return self.get_columnnames()
"""Alias for :py:attr:`~get_column_names`, provided for back-compatibility."""
return self.get_column_names()

@column_names.setter
def column_names(self, names: Optional[List[str]]):
"""Alias for :py:meth:`~set_columnnames` with ``in_place = True``.
"""Alias for :py:meth:`~set_column_names` with ``in_place = True``.
As this mutates the original object, a warning is raised.
"""
warn(
"Setting property 'column_names' is an in-place operation, use 'set_columnnames' instead",
"Setting property 'column_names' is an in-place operation, use 'set_column_names' instead",
UserWarning,
)
self.set_columnnames(names, in_place=True)
self.set_column_names(names, in_place=True)

###########################
######>> metadata <<#######
Expand Down
9 changes: 9 additions & 0 deletions src/summarizedexperiment/RangedSummarizedExperiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,3 +1040,12 @@ def relaxed_combine_columns(
column_names=_new_col_names,
metadata=first._metadata,
)

@ut.extract_row_names.register(RangedSummarizedExperiment)
def _rownames_rse(x: RangedSummarizedExperiment):
return x.get_row_names()


@ut.extract_column_names.register(RangedSummarizedExperiment)
def _colnames_rse(x: RangedSummarizedExperiment):
return x.get_column_names()
10 changes: 10 additions & 0 deletions src/summarizedexperiment/SummarizedExperiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,13 @@ def relaxed_combine_columns(*x: SummarizedExperiment) -> SummarizedExperiment:
column_names=_new_col_names,
metadata=first._metadata,
)


@ut.extract_row_names.register(SummarizedExperiment)
def _rownames_se(x: SummarizedExperiment):
return x.get_row_names()


@ut.extract_column_names.register(SummarizedExperiment)
def _colnames_se(x: SummarizedExperiment):
return x.get_column_names()

0 comments on commit 672c4d9

Please sign in to comment.