From 05789210297a8b8262046a15f4180bfb9da6b6a6 Mon Sep 17 00:00:00 2001 From: Mark Bonicillo Date: Fri, 13 Oct 2023 17:14:16 -0700 Subject: [PATCH 1/3] HYP-353 Remove option to customize misc props column --- hypernetx/classes/entityset.py | 23 +++++------------------ hypernetx/classes/hypergraph.py | 2 -- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/hypernetx/classes/entityset.py b/hypernetx/classes/entityset.py index c0a5e3fd..37385353 100644 --- a/hypernetx/classes/entityset.py +++ b/hypernetx/classes/entityset.py @@ -34,8 +34,6 @@ class EntitySet: represents N-dimensional entity data (data table). Otherwise, represents 2-dimensional entity data (system of sets). data_cols : sequence of ints or strings, default=(0,1) - level1: str or int, default = 0 - level2: str or int, default = 1 data : numpy.ndarray, optional 2D M x N ``ndarray`` of ``ints`` (data table); sparse representation of an N-dimensional incidence tensor with M nonzero cells. @@ -75,9 +73,6 @@ class EntitySet: (order of columns does not matter; see Notes for an example). If doubly-nested dict, ``{item level: {item label: {property name: property value}}}``. - misc_props_col: str, default="properties" - Column names for miscellaneous properties, level index, and item name in - :attr:`properties`; see Notes for explanation. level_col: str, default="level" id_col : str, default="id" cell_properties: sequence of int or str, pandas.DataFrame, or doubly-nested dict, optional @@ -110,10 +105,7 @@ class EntitySet: all occurrences). The names of the Level (if provided) and ID columns must be specified by `level_col` - and `id_col`. `misc_props_col` can be used to specify the name of the column to be used - for miscellaneous properties; if no column by that name is found, - a new column will be created and populated with empty ``dicts``. - All other columns will be considered explicit property types. + and `id_col`. All other columns will be considered explicit property types. The order of the columns does not matter. This method assumes that there are no rows with the same (Level, ID); @@ -138,7 +130,6 @@ def __init__( weights: Optional[Sequence[float] | float | int | str] = 1, aggregateby: Optional[str | dict] = "sum", properties: Optional[pd.DataFrame | dict[int, dict[T, dict[Any, Any]]]] = None, - misc_props_col: str = "properties", level_col: str = "level", id_col: str = "id", cell_properties: Optional[ @@ -150,6 +141,7 @@ def __init__( self._static = static self._state_dict = {} self._misc_cell_props_col = misc_cell_props_col + self._misc_props_col = "properties" # build initial dataframe if isinstance(data, np.ndarray) and entity is None: @@ -178,7 +170,7 @@ def __init__( ) # create properties - self._create_properties(level_col, id_col, misc_props_col, properties) + self._create_properties(level_col, id_col, properties) # create cell properties (From old EntitySet) self._create_assign_cell_properties(cell_properties) @@ -224,7 +216,6 @@ def _create_properties( self, level_col: str, id_col: str, - misc_props_col: str, properties: Optional[pd.DataFrame | dict[int, dict[T, dict[Any, Any]]]], ) -> None: item_levels = [ @@ -235,9 +226,8 @@ def _create_properties( index = pd.MultiIndex.from_tuples(item_levels, names=[level_col, id_col]) data = [(i, 1, {}) for i in range(len(index))] self._properties = pd.DataFrame( - data=data, index=index, columns=["uid", "weight", misc_props_col] + data=data, index=index, columns=["uid", "weight", self._misc_props_col] ).sort_index() - self._misc_props_col = misc_props_col self.assign_properties(properties) def _create_assign_cell_properties( @@ -1296,7 +1286,6 @@ def _restrict_to_levels( data_cols=cols, aggregateby=aggregateby, properties=properties, - misc_props_col=self._misc_props_col, level_col=level_col, id_col=id_col, **kwargs, @@ -1329,9 +1318,7 @@ def restrict_to_indices( for col in self._data_cols: entity[col] = entity[col].cat.remove_unused_categories() - restricted = self.__class__( - entity=entity, misc_props_col=self._misc_props_col, **kwargs - ) + restricted = self.__class__(entity=entity, **kwargs) if not self.properties.empty: prop_idx = [ diff --git a/hypernetx/classes/hypergraph.py b/hypernetx/classes/hypergraph.py index 02001416..5eca748b 100644 --- a/hypernetx/classes/hypergraph.py +++ b/hypernetx/classes/hypergraph.py @@ -328,7 +328,6 @@ def __init__( ### cell properties if setsystem is None: #### Empty Case - self._edges = EntitySet({}) self._nodes = EntitySet({}) self._state_dict = {} @@ -545,7 +544,6 @@ def props2dict(df=None): misc_cell_props_col=misc_cell_properties_col or "cell_properties", aggregateby=aggregateby or "sum", properties=properties, - misc_props_col=misc_properties_col, ) self._edges = self.E From 119295c8bb1bb085e9536cbcb1f597bfb343adb6 Mon Sep 17 00:00:00 2001 From: Mark Bonicillo Date: Fri, 13 Oct 2023 17:24:50 -0700 Subject: [PATCH 2/3] HYP-353 Remove option to customize misc cell props col --- hypernetx/classes/entityset.py | 5 +---- hypernetx/classes/hypergraph.py | 1 - 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/hypernetx/classes/entityset.py b/hypernetx/classes/entityset.py index 37385353..fff5b405 100644 --- a/hypernetx/classes/entityset.py +++ b/hypernetx/classes/entityset.py @@ -76,7 +76,6 @@ class EntitySet: level_col: str, default="level" id_col : str, default="id" cell_properties: sequence of int or str, pandas.DataFrame, or doubly-nested dict, optional - misc_cell_props_col: str, default="cell_properties" Notes ----- @@ -135,12 +134,11 @@ def __init__( cell_properties: Optional[ Sequence[T] | pd.DataFrame | dict[T, dict[T, dict[Any, Any]]] ] = None, - misc_cell_props_col: str = "cell_properties", ): self._uid = uid self._static = static self._state_dict = {} - self._misc_cell_props_col = misc_cell_props_col + self._misc_cell_props_col = "cell_properties" self._misc_props_col = "properties" # build initial dataframe @@ -1998,7 +1996,6 @@ def restrict_to_levels( levels, weights, aggregateby, - misc_cell_props_col=self._misc_cell_props_col, **kwargs, ) diff --git a/hypernetx/classes/hypergraph.py b/hypernetx/classes/hypergraph.py index 5eca748b..7c077112 100644 --- a/hypernetx/classes/hypergraph.py +++ b/hypernetx/classes/hypergraph.py @@ -541,7 +541,6 @@ def props2dict(df=None): weight_col=cell_weight_col, weights=cell_weights, cell_properties=cell_properties, - misc_cell_props_col=misc_cell_properties_col or "cell_properties", aggregateby=aggregateby or "sum", properties=properties, ) From eb78a61815c909ed40c74fc8b2268ef0ba6c8256 Mon Sep 17 00:00:00 2001 From: Mark Bonicillo Date: Wed, 18 Oct 2023 16:20:22 -0700 Subject: [PATCH 3/3] HYP-353 Add deprecation warnings for property column args --- hypernetx/classes/entityset.py | 20 +++++++++++++++++++- hypernetx/classes/hypergraph.py | 2 ++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/hypernetx/classes/entityset.py b/hypernetx/classes/entityset.py index fff5b405..46c4fc66 100644 --- a/hypernetx/classes/entityset.py +++ b/hypernetx/classes/entityset.py @@ -34,6 +34,8 @@ class EntitySet: represents N-dimensional entity data (data table). Otherwise, represents 2-dimensional entity data (system of sets). data_cols : sequence of ints or strings, default=(0,1) + level1: str or int, default = 0 + level2: str or int, default = 1 data : numpy.ndarray, optional 2D M x N ``ndarray`` of ``ints`` (data table); sparse representation of an N-dimensional incidence tensor with M nonzero cells. @@ -73,9 +75,13 @@ class EntitySet: (order of columns does not matter; see Notes for an example). If doubly-nested dict, ``{item level: {item label: {property name: property value}}}``. + misc_props_col: str, default="properties" + Column names for miscellaneous properties, level index, and item name in + :attr:`properties`; see Notes for explanation. level_col: str, default="level" id_col : str, default="id" cell_properties: sequence of int or str, pandas.DataFrame, or doubly-nested dict, optional + misc_cell_props_col: str, default="cell_properties" Notes ----- @@ -104,7 +110,10 @@ class EntitySet: all occurrences). The names of the Level (if provided) and ID columns must be specified by `level_col` - and `id_col`. All other columns will be considered explicit property types. + and `id_col`. `misc_props_col` can be used to specify the name of the column to be used + for miscellaneous properties; if no column by that name is found, + a new column will be created and populated with empty ``dicts``. + All other columns will be considered explicit property types. The order of the columns does not matter. This method assumes that there are no rows with the same (Level, ID); @@ -129,12 +138,21 @@ def __init__( weights: Optional[Sequence[float] | float | int | str] = 1, aggregateby: Optional[str | dict] = "sum", properties: Optional[pd.DataFrame | dict[int, dict[T, dict[Any, Any]]]] = None, + misc_props_col: Optional[str] = None, level_col: str = "level", id_col: str = "id", cell_properties: Optional[ Sequence[T] | pd.DataFrame | dict[T, dict[T, dict[Any, Any]]] ] = None, + misc_cell_props_col: Optional[str] = None, ): + if misc_props_col or misc_cell_props_col: + warnings.warn( + "misc_props_col and misc_cell_props_col will be deprecated; all public references to these " + "arguments will be removed in a future release.", + DeprecationWarning, + ) + self._uid = uid self._static = static self._state_dict = {} diff --git a/hypernetx/classes/hypergraph.py b/hypernetx/classes/hypergraph.py index 7c077112..2a3c3037 100644 --- a/hypernetx/classes/hypergraph.py +++ b/hypernetx/classes/hypergraph.py @@ -541,8 +541,10 @@ def props2dict(df=None): weight_col=cell_weight_col, weights=cell_weights, cell_properties=cell_properties, + misc_cell_props_col=misc_cell_properties_col or "cell_properties", aggregateby=aggregateby or "sum", properties=properties, + misc_props_col=misc_properties_col, ) self._edges = self.E