From 0abefc7ac8dabacb0c1d3297af7b207693ac1c9c Mon Sep 17 00:00:00 2001 From: Olaf Mersmann Date: Wed, 4 Nov 2026 13:47:26 +0100 Subject: [PATCH] [cocopp] replace six by the Python 3 builtins next and str and remove six from the dependencies again. six is still installed as a dependency of python-dateutil (via matplotlib). --- pyproject.toml | 1 - src/cocopp/bestalg.py | 3 +-- src/cocopp/comp2/pprldistr2.py | 9 ++++----- src/cocopp/ppfig.py | 5 ++--- src/cocopp/ppfigcons1.py | 5 ++--- src/cocopp/ppfigdim.py | 5 ++--- src/cocopp/pplogloss.py | 9 ++++----- src/cocopp/pproc.py | 37 +++++++++++++++++----------------- src/cocopp/readalign.py | 5 ++--- 9 files changed, 35 insertions(+), 44 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 671074a..ce5033e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,7 +42,6 @@ dependencies = [ "matplotlib >=3.5.0", "numpy >=1.21.0", "platformdirs >=3.8.1", - "six", ] dynamic = ["version"] diff --git a/src/cocopp/bestalg.py b/src/cocopp/bestalg.py index 750d68d..2ea325c 100644 --- a/src/cocopp/bestalg.py +++ b/src/cocopp/bestalg.py @@ -27,7 +27,6 @@ import warnings import numpy as np import tarfile -from six import advance_iterator from . import readalign, pproc from .toolsdivers import print_done @@ -266,7 +265,7 @@ def __init__(self, dict_alg, algId="Virtual Best Algorithm"): curLine = dictcurLine.setdefault(alg, np.array([np.inf, 0])) while curLine[0] > funval: try: - curLine = advance_iterator(it) + curLine = next(it) except StopIteration: break dictcurLine[alg] = curLine.copy() diff --git a/src/cocopp/comp2/pprldistr2.py b/src/cocopp/comp2/pprldistr2.py index 9e748ff..2fdb982 100644 --- a/src/cocopp/comp2/pprldistr2.py +++ b/src/cocopp/comp2/pprldistr2.py @@ -11,7 +11,6 @@ import matplotlib.pyplot as plt from .. import toolsstats, pproc, toolsdivers from ..ppfig import save_figure, consecutiveNumbers, plotUnifLogXMarkers -from six import advance_iterator # __all__ = [] @@ -244,17 +243,17 @@ def plotLogRel(indexEntries0, indexEntries1, isByInstance=True): it0 = iter(i0.funvals) it1 = iter(i1.funvals) try: - nline0 = advance_iterator(it0) + nline0 = next(it0) while nline0[0] < curevals: line0 = nline0 - nline0 = advance_iterator(it0) + nline0 = next(it0) except StopIteration: pass # we keep the last line obtained. try: - nline1 = advance_iterator(it1) + nline1 = next(it1) while nline1[0] < curevals: line1 = nline1 - nline1 = advance_iterator(it1) + nline1 = next(it1) except StopIteration: pass # we keep the last line obtained. diff --git a/src/cocopp/ppfig.py b/src/cocopp/ppfig.py index ef2fc9b..4975b4e 100644 --- a/src/cocopp/ppfig.py +++ b/src/cocopp/ppfig.py @@ -14,7 +14,6 @@ import numpy as np from matplotlib import pyplot as plt import shutil -from six import advance_iterator # from pdb import set_trace # absolute_import => . refers to where ppfig resides in the package: @@ -744,13 +743,13 @@ def generateData(dataSet, targetFuncValue): finally the median on successful runs. """ it = iter(reversed(dataSet.evals)) - i = advance_iterator(it) + i = next(it) prev = np.array([np.nan] * len(i)) while i[0] <= targetFuncValue: prev = i try: - i = advance_iterator(it) + i = next(it) except StopIteration: break diff --git a/src/cocopp/ppfigcons1.py b/src/cocopp/ppfigcons1.py index 112c6f3..a358b62 100644 --- a/src/cocopp/ppfigcons1.py +++ b/src/cocopp/ppfigcons1.py @@ -21,7 +21,6 @@ import matplotlib.pyplot as plt import numpy as np -from six import advance_iterator from . import genericsettings, toolsstats, bestalg, pproc, ppfig, ppfigparam, htmldesc, toolsdivers from . import testbedsettings @@ -202,13 +201,13 @@ def generateData(dataSet, targetFuncValue): """ it = iter(reversed(dataSet.evals)) - i = advance_iterator(it) + i = next(it) prev = np.array([np.nan] * len(i)) while i[0] <= targetFuncValue: prev = i try: - i = advance_iterator(it) + i = next(it) except StopIteration: break diff --git a/src/cocopp/ppfigdim.py b/src/cocopp/ppfigdim.py index 87ee404..8f13d66 100644 --- a/src/cocopp/ppfigdim.py +++ b/src/cocopp/ppfigdim.py @@ -58,7 +58,6 @@ import matplotlib.pyplot as plt import numpy as np -from six import advance_iterator from . import genericsettings, toolsstats, bestalg, pproc, ppfig, ppfigparam, htmldesc, toolsdivers from . import testbedsettings @@ -241,13 +240,13 @@ def generateData(dataSet, targetFuncValue): """ it = iter(reversed(dataSet.evals)) - i = advance_iterator(it) + i = next(it) prev = np.array([np.nan] * len(i)) while i[0] <= targetFuncValue: prev = i try: - i = advance_iterator(it) + i = next(it) except StopIteration: break diff --git a/src/cocopp/pplogloss.py b/src/cocopp/pplogloss.py index f19102a..8f81c97 100644 --- a/src/cocopp/pplogloss.py +++ b/src/cocopp/pplogloss.py @@ -20,7 +20,6 @@ except ImportError: # compatibility matplotlib 0.8 from matplotlib.transforms import blend_xy_sep_transform as blend -from six import advance_iterator from . import toolsstats, toolsdivers, bestalg, genericsettings, captions from .pptex import writeFEvals2 @@ -593,10 +592,10 @@ def generateSingleTableTex(dsList, funcs, mFE, d, prcOfInterest, EVALS, data, ou for i in dsList: it = reversed(i.evals) curline = None - nextline = advance_iterator(it) + nextline = next(it) while nextline[0] <= f_thresh: curline = nextline[1:] - nextline = advance_iterator(it) + nextline = next(it) if curline is None: tmpdata.extend(i.maxevals) else: @@ -660,10 +659,10 @@ def generateSingleTableHtml(dsList, funcs, mFE, d, prcOfInterest, EVALS, data, o for i in dsList: it = reversed(i.evals) curline = None - nextline = advance_iterator(it) + nextline = next(it) while nextline[0] <= f_thresh: curline = nextline[1:] - nextline = advance_iterator(it) + nextline = next(it) if curline is None: tmpdata.extend(i.maxevals) else: diff --git a/src/cocopp/pproc.py b/src/cocopp/pproc.py index 7d11d0f..d756256 100644 --- a/src/cocopp/pproc.py +++ b/src/cocopp/pproc.py @@ -31,7 +31,6 @@ import functools import collections import time -from six import string_types, advance_iterator import numpy import numpy as np import matplotlib.pyplot as plt @@ -375,7 +374,7 @@ def initialize(self): self.reference_data = bestalg.load_reference_algorithm(self.reference_algorithm, force=True) # TODO: remove targets smaller than 1e-8 - elif isinstance(self.reference_data, string_types): # self.reference_data in ('RANDOMSEARCH', 'IPOP-CMA-ES') should work + elif isinstance(self.reference_data, str): # self.reference_data in ('RANDOMSEARCH', 'IPOP-CMA-ES') should work self._short_info = "reference budgets from " + self.reference_data # dsl = DataSetList(os.path.join(sys.modules[globals()['__name__']].__file__.split('cocopp')[0], # 'cocopp', 'data', self.reference_data)) @@ -386,7 +385,7 @@ def initialize(self): dsd[(ds.funcId, ds.dim)] = ds self.reference_data = dsd elif isinstance(self.reference_data, list): - if not isinstance(self.reference_data[0], string_types): + if not isinstance(self.reference_data[0], str): raise ValueError( "RunlengthBasedTargetValues() expected a string, dict, or list of strings as second argument," + (" got a list of %s" % str(type(self.reference_data[0]))) @@ -2005,7 +2004,7 @@ def generateRLData(self, targets): it = reversed(self.evals) prevline = numpy.array([-numpy.inf] + [numpy.nan] * self.nbRuns()) try: - line = advance_iterator(it) + line = next(it) except StopIteration: # evals is an empty array return res # list() @@ -2014,7 +2013,7 @@ def generateRLData(self, targets): while line[0] <= t: prevline = line try: - line = advance_iterator(it) + line = next(it) except StopIteration: break res[t] = prevline.copy() @@ -2110,7 +2109,7 @@ def detERT(self, targets): prevline = numpy.array([-numpy.inf, numpy.inf]) try: - line = advance_iterator(it) + line = next(it) except StopIteration: # evals is an empty array return list() @@ -2119,7 +2118,7 @@ def detERT(self, targets): while line[0] <= t: prevline = line try: - line = advance_iterator(it) + line = next(it) except StopIteration: break res[t] = prevline.copy() # is copy necessary? Yes. @@ -2297,7 +2296,7 @@ def _detEvals2(self, targets): it = reversed(self.evals) prevline = numpy.array([-numpy.inf] + [numpy.nan] * self.nbRuns()) try: - line = advance_iterator(it) + line = next(it) except StopIteration: # evals is an empty array return tmp # list() @@ -2306,7 +2305,7 @@ def _detEvals2(self, targets): while line[0] <= t: prevline = line try: - line = advance_iterator(it) + line = next(it) except StopIteration: break tmp[t] = prevline.copy() @@ -2978,9 +2977,9 @@ def save_pickle(name, dsl): if _ignore_pickle_files or len(args) != 1 or len(kwargs) or sys.version_info[0] < 3: return fallback() arg1 = args[0] - if isinstance(arg1, string_types): + if isinstance(arg1, str): arg1 = [arg1] - if len(args) != 1 or not isinstance(arg1[0], string_types) or not findfiles.is_recognized_repository_filetype2(arg1[0]): + if len(args) != 1 or not isinstance(arg1[0], str) or not findfiles.is_recognized_repository_filetype2(arg1[0]): return fallback() try: import pickle @@ -3060,7 +3059,7 @@ def __init__(self, args=[], check_data_type=True): super(DataSetList, self).__init__() return - if isinstance(args, string_types): + if isinstance(args, str): args = [args] self._cocopp_version = _version.__version__ @@ -3078,7 +3077,7 @@ def __init__(self, args=[], check_data_type=True): fnames = [] # data file names alg_names = [] # may be the same algorithm name for (many) different fnames for name in args: - if isinstance(name, string_types) and findfiles.is_recognized_repository_filetype(name): + if isinstance(name, str) and findfiles.is_recognized_repository_filetype(name): # the found names may not at all reflect name anymore fnames.extend(findfiles.main(name)) else: @@ -3174,17 +3173,17 @@ def processIndexFile(self, indexFile, alg_name=None): while True: try: if "indicator" not in header: - header = advance_iterator(f) + header = next(f) while not header.strip(): # remove blank lines - header = advance_iterator(f) + header = next(f) nbLine += 1 - comment = advance_iterator(f) + comment = next(f) if not comment.startswith("%"): warnings.warn("Entry in file %s at line %d is faulty: " % (indexFile, nbLine) + "it will be skipped.") nbLine += 2 continue - data = advance_iterator(f) # this is the filename of the data file!? + data = next(f) # this is the filename of the data file!? data_file_names.append(data) nbLine += 3 # TODO: check that something is not wrong with the 3 lines. @@ -4105,10 +4104,10 @@ def parseinfoold(s): res = [] while True: try: - elem = advance_iterator(it) + elem = next(it) tmp = p.match(elem) while not tmp: - elem = advance_iterator(it) + elem + elem = next(it) + elem # add up elements of list_kv until we have a whole key = value elem0, elem1 = tmp.groups() diff --git a/src/cocopp/readalign.py b/src/cocopp/readalign.py index fdc734f..3cda667 100644 --- a/src/cocopp/readalign.py +++ b/src/cocopp/readalign.py @@ -26,7 +26,6 @@ from . import genericsettings, testbedsettings, dataformatsettings -from six import advance_iterator # CLASS DEFINITIONS @@ -118,7 +117,7 @@ def __init__(self, data, isHArray=False): self.isNearlyFinished = False self.isFinished = False self.currentLine = None - self.nextLine = advance_iterator(self.it) + self.nextLine = next(self.it) if isHArray: self.idxEvals = range(1, numpy.shape(data)[1]) else: @@ -134,7 +133,7 @@ def next(self): self.currentLine = self.nextLine.copy() # Update nextLine try: - self.nextLine = advance_iterator(self.it) + self.nextLine = next(self.it) except StopIteration: self.isNearlyFinished = True else: