From d2ffb2fa776a6fa4cffdbef91ac11586b5995d8e Mon Sep 17 00:00:00 2001 From: l-kotzur Date: Fri, 9 Aug 2024 12:05:55 +0200 Subject: [PATCH] back again with future stack true --- setup.py | 1 + test/test_cluster_order.py | 8 ++++---- test/test_hierarchical.py | 4 ++-- test/test_k_medoids.py | 4 ++-- test/test_segmentation.py | 4 ++-- tsam/__init__.py | 11 ----------- tsam/timeseriesaggregation.py | 4 ++-- tsam/utils/durationRepresentation.py | 8 ++++---- 8 files changed, 17 insertions(+), 27 deletions(-) diff --git a/setup.py b/setup.py index 68858ce..c40ead7 100644 --- a/setup.py +++ b/setup.py @@ -16,6 +16,7 @@ long_description_content_type="text/markdown", url="https://github.com/FZJ-IEK3-VSA/tsam", include_package_data=True, + python_requires='>=3.9', packages=setuptools.find_packages(), install_requires=required_packages, setup_requires=["setuptools-git"], diff --git a/test/test_cluster_order.py b/test/test_cluster_order.py index 0948755..32e1105 100644 --- a/test/test_cluster_order.py +++ b/test/test_cluster_order.py @@ -103,21 +103,21 @@ def test_cluster_order(): orig_raw_predefClusterOrder[typPeriods_predefClusterOrder.columns] .unstack() .loc[sortedDaysOrig1, :] - .stack() + .stack(future_stack=True,) ) - test1 = typPeriods_predefClusterOrder.unstack().loc[sortedDaysTest1, :].stack() + test1 = typPeriods_predefClusterOrder.unstack().loc[sortedDaysTest1, :].stack(future_stack=True,) orig2 = ( orig_raw_predefClusterOrderAndClusterCenters[ typPeriods_predefClusterOrderAndClusterCenters.columns ] .unstack() .loc[sortedDaysOrig2, :] - .stack() + .stack(future_stack=True,) ) test2 = ( typPeriods_predefClusterOrderAndClusterCenters.unstack() .loc[sortedDaysTest2, :] - .stack() + .stack(future_stack=True,) ) np.testing.assert_array_almost_equal( diff --git a/test/test_hierarchical.py b/test/test_hierarchical.py index ac74406..ec37616 100644 --- a/test/test_hierarchical.py +++ b/test/test_hierarchical.py @@ -46,8 +46,8 @@ def test_hierarchical(): sortedDaysTest = typPeriods.groupby(level=0).sum().sort_values("GHI").index # rearange their order - orig = orig_raw[typPeriods.columns].unstack().loc[sortedDaysOrig, :].stack() - test = typPeriods.unstack().loc[sortedDaysTest, :].stack() + orig = orig_raw[typPeriods.columns].unstack().loc[sortedDaysOrig, :].stack(future_stack=True,) + test = typPeriods.unstack().loc[sortedDaysTest, :].stack(future_stack=True,) np.testing.assert_array_almost_equal(orig.values, test.values, decimal=4) diff --git a/test/test_k_medoids.py b/test/test_k_medoids.py index b373dbf..eca96ea 100644 --- a/test/test_k_medoids.py +++ b/test/test_k_medoids.py @@ -43,8 +43,8 @@ def test_k_medoids(): sortedDaysTest = typPeriods.groupby(level=0).sum().sort_values("GHI").index # rearange their order - orig = orig_raw[typPeriods.columns].unstack().loc[sortedDaysOrig, :].stack() - test = typPeriods.unstack().loc[sortedDaysTest, :].stack() + orig = orig_raw[typPeriods.columns].unstack().loc[sortedDaysOrig, :].stack(future_stack=True,) + test = typPeriods.unstack().loc[sortedDaysTest, :].stack(future_stack=True,) np.testing.assert_array_almost_equal(orig.values, test.values, decimal=4) diff --git a/test/test_segmentation.py b/test/test_segmentation.py index e7c2521..9ca5676 100644 --- a/test/test_segmentation.py +++ b/test/test_segmentation.py @@ -46,8 +46,8 @@ def test_segmentation(): sortedDaysTest = typPeriods.groupby(level=0).sum().sort_values("GHI").index # rearange their order - orig = orig_raw[typPeriods.columns].unstack().loc[sortedDaysOrig, :].stack() - test = typPeriods.unstack().loc[sortedDaysTest, :].stack() + orig = orig_raw[typPeriods.columns].unstack().loc[sortedDaysOrig, :].stack(future_stack=True,) + test = typPeriods.unstack().loc[sortedDaysTest, :].stack(future_stack=True,) np.testing.assert_array_almost_equal(orig.values, test.values, decimal=4) diff --git a/tsam/__init__.py b/tsam/__init__.py index 85b98a3..e69de29 100644 --- a/tsam/__init__.py +++ b/tsam/__init__.py @@ -1,11 +0,0 @@ -import sys - -if not sys.warnoptions: - import warnings - - warnings.filterwarnings( - action="ignore", - category=FutureWarning, - append=True, - message=r".*The previous implementation of stack is deprecated and will be removed in a future version of pandas.*", - ) \ No newline at end of file diff --git a/tsam/timeseriesaggregation.py b/tsam/timeseriesaggregation.py index 63794e5..4746d58 100644 --- a/tsam/timeseriesaggregation.py +++ b/tsam/timeseriesaggregation.py @@ -969,7 +969,7 @@ def createTypicalPeriods(self): # check for additional cluster parameters if self.evalSumPeriods: evaluationValues = ( - self.normalizedPeriodlyProfiles.stack(level=0) + self.normalizedPeriodlyProfiles.stack(future_stack=True,level=0) .sum(axis=1) .unstack(level=1) ) @@ -1239,7 +1239,7 @@ def predictOriginalData(self): columns=self.normalizedPeriodlyProfiles.columns, index=self.normalizedPeriodlyProfiles.index, ) - clustered_data_df = clustered_data_df.stack(level="TimeStep") + clustered_data_df = clustered_data_df.stack(future_stack=True,level="TimeStep") # back in form self.normalizedPredictedData = pd.DataFrame( diff --git a/tsam/utils/durationRepresentation.py b/tsam/utils/durationRepresentation.py index 155efdb..91be97f 100644 --- a/tsam/utils/durationRepresentation.py +++ b/tsam/utils/durationRepresentation.py @@ -57,7 +57,7 @@ def durationRepresentation( # get all the values of a certain attribute and cluster candidateValues = candidates.loc[indice[0], a] # sort all values - sortedAttr = candidateValues.stack().sort_values() + sortedAttr = candidateValues.stack(future_stack=True,).sort_values() # reindex and arrange such that every sorted segment gets represented by its mean sortedAttr.index = pd.MultiIndex.from_tuples(clean_index) representationValues = sortedAttr.unstack(level=0).mean(axis=1) @@ -97,8 +97,8 @@ def durationRepresentation( # concat centroid values and cluster weights for all clusters meansAndWeights = pd.concat( [ - pd.DataFrame(np.array(meanVals)).stack(), - pd.DataFrame(np.array(clusterLengths)).stack(), + pd.DataFrame(np.array(meanVals)).stack(future_stack=True,), + pd.DataFrame(np.array(clusterLengths)).stack(future_stack=True,), ], axis=1, ) @@ -107,7 +107,7 @@ def durationRepresentation( # save order of the sorted centroid values across all clusters order = meansAndWeightsSorted.index # sort all values of the original time series - sortedAttr = candidates.loc[:, a].stack().sort_values().values + sortedAttr = candidates.loc[:, a].stack(future_stack=True,).sort_values().values # take mean of sections of the original duration curve according to the cluster and its weight the # respective section is assigned to representationValues = []