Skip to content

Commit

Permalink
back again with future stack true
Browse files Browse the repository at this point in the history
  • Loading branch information
l-kotzur committed Aug 9, 2024
1 parent f7f1fc8 commit d2ffb2f
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 27 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
8 changes: 4 additions & 4 deletions test/test_cluster_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions test/test_hierarchical.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions test/test_k_medoids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions test/test_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
11 changes: 0 additions & 11 deletions tsam/__init__.py
Original file line number Diff line number Diff line change
@@ -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.*",
)
4 changes: 2 additions & 2 deletions tsam/timeseriesaggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions tsam/utils/durationRepresentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
)
Expand All @@ -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 = []
Expand Down

0 comments on commit d2ffb2f

Please sign in to comment.