From 415080917717fa144de677463cfd2d748d9c08ce Mon Sep 17 00:00:00 2001 From: crusaderky Date: Tue, 29 Oct 2024 16:07:40 +0000 Subject: [PATCH] Remove legacy hacks in ASV benchmarks --- benchmarks/delete_versions.py | 32 +------------------------- benchmarks/inmemoryarraydataset.py | 35 +++++------------------------ benchmarks/inmemorydataset.py | 36 +++++------------------------- 3 files changed, 11 insertions(+), 92 deletions(-) diff --git a/benchmarks/delete_versions.py b/benchmarks/delete_versions.py index 3903d3e0..28bfbfcc 100644 --- a/benchmarks/delete_versions.py +++ b/benchmarks/delete_versions.py @@ -5,41 +5,11 @@ import h5py import numpy -from versioned_hdf5 import VersionedHDF5File +from versioned_hdf5 import VersionedHDF5File, delete_versions filename = "delete_versions_bench.h5" -try: - from versioned_hdf5 import delete_versions -except ImportError: - from versioned_hdf5.replay import recreate_dataset, swap, tmp_group - - def delete_versions(f, versions_to_delete, names=("values",)): - """ - Modified replay.delete_version to delete multiple versions. - """ - if isinstance(f, VersionedHDF5File): - f = f.f - - def callback(dataset, version_name): - if version_name in versions_to_delete: - return - return dataset - - newf = tmp_group(f) - - for name in names: - recreate_dataset(f, name, newf, callback=callback) - - swap(f, newf) - - for version in versions_to_delete: - del f["_version_data/versions"][version] - - del newf[newf.name] - - class TimeDeleting: params = [10, 30, 50] timeout = 1000 diff --git a/benchmarks/inmemoryarraydataset.py b/benchmarks/inmemoryarraydataset.py index fd36618f..9aa3c00b 100644 --- a/benchmarks/inmemoryarraydataset.py +++ b/benchmarks/inmemoryarraydataset.py @@ -1,20 +1,11 @@ import os import h5py +import numpy as np from versioned_hdf5 import VersionedHDF5File from versioned_hdf5.wrappers import InMemoryArrayDataset -try: - from versioned_hdf5.wrappers import DatasetWrapper -except ImportError: - - class DatasetWrapper: - pass - - -import numpy as np - class TimeInMemoryArrayDataset: timeout = 1000 @@ -31,11 +22,7 @@ def time_getattr(self): data=np.arange(10000).reshape((100, 10, 10)), chunks=(3, 3, 3), ) - assert ( - isinstance(dataset, InMemoryArrayDataset) - or isinstance(dataset, DatasetWrapper) - and isinstance(dataset.dataset, InMemoryArrayDataset) - ) + assert isinstance(dataset.dataset, InMemoryArrayDataset) dataset[:, 0, 0:6] def time_setattr(self): @@ -47,11 +34,7 @@ def time_setattr(self): data=np.arange(10000).reshape((100, 10, 10)), chunks=(3, 3, 3), ) - assert ( - isinstance(dataset, InMemoryArrayDataset) - or isinstance(dataset, DatasetWrapper) - and isinstance(dataset.dataset, InMemoryArrayDataset) - ) + assert isinstance(dataset.dataset, InMemoryArrayDataset) dataset[:, 0, 0:6] = -1 def time_resize_bigger(self): @@ -63,11 +46,7 @@ def time_resize_bigger(self): data=np.arange(10000).reshape((100, 10, 10)), chunks=(3, 3, 3), ) - assert ( - isinstance(dataset, InMemoryArrayDataset) - or isinstance(dataset, DatasetWrapper) - and isinstance(dataset.dataset, InMemoryArrayDataset) - ) + assert isinstance(dataset.dataset, InMemoryArrayDataset) dataset.resize((100, 100, 100)) def time_resize_smaller(self): @@ -79,9 +58,5 @@ def time_resize_smaller(self): data=np.arange(10000).reshape((100, 10, 10)), chunks=(3, 3, 3), ) - assert ( - isinstance(dataset, InMemoryArrayDataset) - or isinstance(dataset, DatasetWrapper) - and isinstance(dataset.dataset, InMemoryArrayDataset) - ) + assert isinstance(dataset.dataset, InMemoryArrayDataset) dataset.resize((10, 10, 10)) diff --git a/benchmarks/inmemorydataset.py b/benchmarks/inmemorydataset.py index 7b2906c0..6bcd813f 100644 --- a/benchmarks/inmemorydataset.py +++ b/benchmarks/inmemorydataset.py @@ -1,20 +1,10 @@ import os import h5py - +import numpy as np from versioned_hdf5 import VersionedHDF5File from versioned_hdf5.wrappers import InMemoryDataset -try: - from versioned_hdf5.wrappers import DatasetWrapper -except ImportError: - - class DatasetWrapper: - pass - - -import numpy as np - class TimeInMemoryDataset: timeout = 1000 @@ -44,11 +34,7 @@ def setup(self): def time_getitem(self): dataset = self.versioned_file["version1"]["data"] - assert ( - isinstance(dataset, InMemoryDataset) - or isinstance(dataset, DatasetWrapper) - and isinstance(dataset.dataset, InMemoryDataset) - ) + assert isinstance(dataset.dataset, InMemoryDataset) dataset[:, 0, 0:6] def time_setitem(self): @@ -56,11 +42,7 @@ def time_setitem(self): self.setup() with self.versioned_file.stage_version("version2") as g: dataset = g["data"] - assert ( - isinstance(dataset, InMemoryDataset) - or isinstance(dataset, DatasetWrapper) - and isinstance(dataset.dataset, InMemoryDataset) - ) + assert isinstance(dataset.dataset, InMemoryDataset) dataset[:, 0, 0:6] = -1 def time_resize_bigger(self): @@ -68,11 +50,7 @@ def time_resize_bigger(self): self.setup() with self.versioned_file.stage_version("version2") as g: dataset = g["data"] - assert ( - isinstance(dataset, InMemoryDataset) - or isinstance(dataset, DatasetWrapper) - and isinstance(dataset.dataset, InMemoryDataset) - ) + assert isinstance(dataset.dataset, InMemoryDataset) dataset.resize((100, 100, 100)) def time_resize_smaller(self): @@ -80,9 +58,5 @@ def time_resize_smaller(self): self.setup() with self.versioned_file.stage_version("version2") as g: dataset = g["data"] - assert ( - isinstance(dataset, InMemoryDataset) - or isinstance(dataset, DatasetWrapper) - and isinstance(dataset.dataset, InMemoryDataset) - ) + assert isinstance(dataset.dataset, InMemoryDataset) dataset.resize((10, 10, 10))