From d6d26bd5e029908a79153424270da407a4d560f0 Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Fri, 26 Apr 2024 23:08:34 +0200 Subject: [PATCH] remove Python2 crumbs --- docs/conf.py | 2 +- docs/installing.rst | 1 - setup.cfg | 1 - spectral_cube/_moments.py | 2 -- spectral_cube/analysis_utilities.py | 1 - spectral_cube/conftest.py | 1 - spectral_cube/cube_utils.py | 8 +------- spectral_cube/dask_spectral_cube.py | 2 -- spectral_cube/io/__init__.py | 1 - spectral_cube/io/casa_image.py | 2 -- spectral_cube/io/casa_masks.py | 2 -- spectral_cube/io/class_lmv.py | 7 ++----- spectral_cube/io/core.py | 2 -- spectral_cube/io/fits.py | 3 --- spectral_cube/lower_dimensional_structures.py | 2 -- spectral_cube/masks.py | 3 --- spectral_cube/np_compat.py | 2 -- spectral_cube/spectral_axis.py | 2 -- spectral_cube/spectral_cube.py | 8 ++------ spectral_cube/stokes_spectral_cube.py | 8 +------- spectral_cube/tests/__init__.py | 2 -- spectral_cube/tests/helpers.py | 2 -- spectral_cube/tests/setup_package.py | 2 -- spectral_cube/tests/test_casafuncs.py | 2 -- spectral_cube/tests/test_io.py | 2 -- spectral_cube/tests/test_masks.py | 2 -- spectral_cube/tests/test_moments.py | 2 -- spectral_cube/tests/test_performance.py | 2 -- spectral_cube/tests/test_projection.py | 2 -- spectral_cube/tests/test_spectral_axis.py | 2 -- spectral_cube/tests/test_spectral_cube.py | 2 -- spectral_cube/tests/test_subcubes.py | 2 -- spectral_cube/tests/test_visualization.py | 2 -- spectral_cube/tests/test_wcs_utils.py | 2 -- spectral_cube/tests/utilities.py | 2 -- spectral_cube/wcs_utils.py | 2 -- spectral_cube/ytcube.py | 5 +---- 37 files changed, 8 insertions(+), 89 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index e6897f1b9..a837314cc 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -192,4 +192,4 @@ # continue # dtype, target = line.split(None, 1) # target = target.strip() -# nitpick_ignore.append((dtype, six.u(target))) +# nitpick_ignore.append((dtype, str(target))) diff --git a/docs/installing.rst b/docs/installing.rst index 08f557248..0d36a7f1c 100644 --- a/docs/installing.rst +++ b/docs/installing.rst @@ -20,7 +20,6 @@ This package has the following dependencies: * `dask `_, used for the :class:`~spectral_cube.DaskSpectralCube` class * `zarr `_ and `fsspec `_, used for storing computations to disk when using the dask-enabled classes. -* `six `_ * `casa-formats-io `_ Installation diff --git a/setup.cfg b/setup.cfg index de940362c..3187d2679 100644 --- a/setup.cfg +++ b/setup.cfg @@ -17,7 +17,6 @@ install_requires = astropy numpy>=1.8.0 radio_beam>=0.3.3 - six dask[array] joblib casa-formats-io diff --git a/spectral_cube/_moments.py b/spectral_cube/_moments.py index b19bcbd16..9a98ff58a 100644 --- a/spectral_cube/_moments.py +++ b/spectral_cube/_moments.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import numpy as np from .cube_utils import iterator_strategy diff --git a/spectral_cube/analysis_utilities.py b/spectral_cube/analysis_utilities.py index 25f732bb6..a2b74b30e 100644 --- a/spectral_cube/analysis_utilities.py +++ b/spectral_cube/analysis_utilities.py @@ -1,7 +1,6 @@ import numpy as np from astropy import units as u -from six.moves import zip, range from astropy.wcs import WCS from astropy.utils.console import ProgressBar from astropy import log diff --git a/spectral_cube/conftest.py b/spectral_cube/conftest.py index b8a306161..e20d9fe77 100644 --- a/spectral_cube/conftest.py +++ b/spectral_cube/conftest.py @@ -1,7 +1,6 @@ # this contains imports plugins that configure py.test for astropy tests. # by importing them here in conftest.py they are discoverable by py.test # no matter how it is invoked within the source tree. -from __future__ import print_function, absolute_import, division import os from astropy.units.equivalencies import pixel_scale diff --git a/spectral_cube/cube_utils.py b/spectral_cube/cube_utils.py index cb23aad94..07f01fd25 100644 --- a/spectral_cube/cube_utils.py +++ b/spectral_cube/cube_utils.py @@ -1,14 +1,8 @@ -from __future__ import print_function, absolute_import, division - import contextlib import warnings from copy import deepcopy -try: - import builtins -except ImportError: - # python2 - import __builtin__ as builtins +import builtins import dask.array as da import numpy as np diff --git a/spectral_cube/dask_spectral_cube.py b/spectral_cube/dask_spectral_cube.py index 08125222a..d0fae797c 100644 --- a/spectral_cube/dask_spectral_cube.py +++ b/spectral_cube/dask_spectral_cube.py @@ -2,8 +2,6 @@ A class to represent a 3-d position-position-velocity spectral cube. """ -from __future__ import print_function, absolute_import, division - import uuid import inspect import warnings diff --git a/spectral_cube/io/__init__.py b/spectral_cube/io/__init__.py index f117f7d1e..e69de29bb 100644 --- a/spectral_cube/io/__init__.py +++ b/spectral_cube/io/__init__.py @@ -1 +0,0 @@ -from __future__ import print_function, absolute_import, division diff --git a/spectral_cube/io/casa_image.py b/spectral_cube/io/casa_image.py index 2e0fce9b5..6d5e21620 100644 --- a/spectral_cube/io/casa_image.py +++ b/spectral_cube/io/casa_image.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import warnings from astropy import units as u from astropy.io import registry as io_registry diff --git a/spectral_cube/io/casa_masks.py b/spectral_cube/io/casa_masks.py index 5c0d641c1..fb140006f 100644 --- a/spectral_cube/io/casa_masks.py +++ b/spectral_cube/io/casa_masks.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import numpy as np from astropy.io import fits import tempfile diff --git a/spectral_cube/io/class_lmv.py b/spectral_cube/io/class_lmv.py index 4b40d3919..f36004d7a 100644 --- a/spectral_cube/io/class_lmv.py +++ b/spectral_cube/io/class_lmv.py @@ -1,6 +1,3 @@ -from __future__ import print_function, absolute_import, division - -import six import numpy as np import struct import warnings @@ -252,8 +249,8 @@ def read_lmv_tofits(fileobj): if isinstance(v, tuple) else fits.header.Card(''.join(s for s in k if s in string.printable), ''.join(s for s in v if s in string.printable) - if isinstance(v, six.string_types) else v) - for k,v in six.iteritems(header) + if isinstance(v, str) else v) + for k,v in header.items() if k not in bad_kws] Header = fits.Header(cards) hdu = fits.PrimaryHDU(data=data, header=Header) diff --git a/spectral_cube/io/core.py b/spectral_cube/io/core.py index b3ad728f2..a26f0c0d7 100644 --- a/spectral_cube/io/core.py +++ b/spectral_cube/io/core.py @@ -5,8 +5,6 @@ # the unified I/O framework from Astropy which is used to implement this, see # http://docs.astropy.org/en/stable/io/unified.html -from __future__ import print_function, absolute_import, division - from pathlib import PosixPath import warnings diff --git a/spectral_cube/io/fits.py b/spectral_cube/io/fits.py index 23daf0249..affd72265 100644 --- a/spectral_cube/io/fits.py +++ b/spectral_cube/io/fits.py @@ -1,6 +1,3 @@ -from __future__ import print_function, absolute_import, division - -import six import dask import warnings diff --git a/spectral_cube/lower_dimensional_structures.py b/spectral_cube/lower_dimensional_structures.py index f827e6de4..bb5f56c40 100644 --- a/spectral_cube/lower_dimensional_structures.py +++ b/spectral_cube/lower_dimensional_structures.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import warnings import numpy as np diff --git a/spectral_cube/masks.py b/spectral_cube/masks.py index 70dfb55cb..089ddf349 100644 --- a/spectral_cube/masks.py +++ b/spectral_cube/masks.py @@ -1,11 +1,8 @@ -from __future__ import print_function, absolute_import, division - import abc import uuid import warnings import tempfile -from six.moves import zip import numpy as np from numpy.lib.stride_tricks import as_strided diff --git a/spectral_cube/np_compat.py b/spectral_cube/np_compat.py index 99477baac..d8b7faa96 100644 --- a/spectral_cube/np_compat.py +++ b/spectral_cube/np_compat.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import numpy as np def allbadtonan(function): diff --git a/spectral_cube/spectral_axis.py b/spectral_cube/spectral_axis.py index ac73552b4..fbfcfc05c 100644 --- a/spectral_cube/spectral_axis.py +++ b/spectral_cube/spectral_axis.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import numpy as np from astropy import wcs diff --git a/spectral_cube/spectral_cube.py b/spectral_cube/spectral_cube.py index a7dab37a4..ea42a099f 100644 --- a/spectral_cube/spectral_cube.py +++ b/spectral_cube/spectral_cube.py @@ -2,8 +2,6 @@ A class to represent a 3-d position-position-velocity spectral cube. """ -from __future__ import print_function, absolute_import, division - import warnings from functools import wraps import operator @@ -13,8 +11,6 @@ import tempfile import textwrap from pathlib import PosixPath -import six -from six.moves import zip, range import dask.array as da import astropy.wcs @@ -2022,7 +2018,7 @@ def subcube_from_ds9region(self, ds9_region, allow_empty=False): """ import regions - if isinstance(ds9_region, six.string_types): + if isinstance(ds9_region, str): if hasattr(regions, 'DS9Parser'): region_list = regions.DS9Parser(ds9_region).shapes.to_regions() else: @@ -2046,7 +2042,7 @@ def subcube_from_crtfregion(self, crtf_region, allow_empty=False): """ import regions - if isinstance(crtf_region, six.string_types): + if isinstance(crtf_region, str): region_list = regions.CRTFParser(crtf_region).shapes.to_regions() else: raise TypeError("{0} should be a CRTF string".format(crtf_region)) diff --git a/spectral_cube/stokes_spectral_cube.py b/spectral_cube/stokes_spectral_cube.py index 2ecf294ac..bd95dc755 100644 --- a/spectral_cube/stokes_spectral_cube.py +++ b/spectral_cube/stokes_spectral_cube.py @@ -1,6 +1,3 @@ -from __future__ import print_function, absolute_import, division - -import six import numpy as np from astropy.io.registry import UnifiedReadWriteMethod @@ -113,10 +110,7 @@ def wcs(self): return self._wcs def __dir__(self): - if six.PY2: - return self.components + dir(type(self)) + list(self.__dict__) - else: - return self.components + super(StokesSpectralCube, self).__dir__() + return self.components + super(StokesSpectralCube, self).__dir__() @property def components(self): diff --git a/spectral_cube/tests/__init__.py b/spectral_cube/tests/__init__.py index 313f77c16..70cf9e083 100644 --- a/spectral_cube/tests/__init__.py +++ b/spectral_cube/tests/__init__.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import os diff --git a/spectral_cube/tests/helpers.py b/spectral_cube/tests/helpers.py index d9e3dcbe8..27c4ce5a2 100644 --- a/spectral_cube/tests/helpers.py +++ b/spectral_cube/tests/helpers.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - from astropy import units as u from numpy.testing import assert_allclose as assert_allclose_numpy, assert_array_equal diff --git a/spectral_cube/tests/setup_package.py b/spectral_cube/tests/setup_package.py index a5a5a412f..5b6e3931a 100644 --- a/spectral_cube/tests/setup_package.py +++ b/spectral_cube/tests/setup_package.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - def get_package_data(): return { _ASTROPY_PACKAGE_NAME_ + '.tests': ['coveragerc', 'data/*.fits', 'data/*.hdr', 'data/*.lmv', 'data/*reg'] diff --git a/spectral_cube/tests/test_casafuncs.py b/spectral_cube/tests/test_casafuncs.py index 97910c7a2..875a7e9c8 100644 --- a/spectral_cube/tests/test_casafuncs.py +++ b/spectral_cube/tests/test_casafuncs.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import os import shutil from itertools import product diff --git a/spectral_cube/tests/test_io.py b/spectral_cube/tests/test_io.py index e927d8058..80bc2b946 100644 --- a/spectral_cube/tests/test_io.py +++ b/spectral_cube/tests/test_io.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import numpy as np from astropy.io import fits as pyfits from astropy import units as u diff --git a/spectral_cube/tests/test_masks.py b/spectral_cube/tests/test_masks.py index dbd4bbf8f..c0d72de37 100644 --- a/spectral_cube/tests/test_masks.py +++ b/spectral_cube/tests/test_masks.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import pytest import itertools import operator diff --git a/spectral_cube/tests/test_moments.py b/spectral_cube/tests/test_moments.py index a098dfbb9..ef276f18e 100644 --- a/spectral_cube/tests/test_moments.py +++ b/spectral_cube/tests/test_moments.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import warnings from packaging.version import Version, parse diff --git a/spectral_cube/tests/test_performance.py b/spectral_cube/tests/test_performance.py index c0c80b96a..b40a6a73f 100644 --- a/spectral_cube/tests/test_performance.py +++ b/spectral_cube/tests/test_performance.py @@ -4,8 +4,6 @@ For now this is just for SpectralCube, not DaskSpectralCube. """ -from __future__ import print_function, absolute_import, division - import numpy as np import pytest diff --git a/spectral_cube/tests/test_projection.py b/spectral_cube/tests/test_projection.py index edd4e7102..70a36a8ef 100644 --- a/spectral_cube/tests/test_projection.py +++ b/spectral_cube/tests/test_projection.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import warnings import pytest import numpy as np diff --git a/spectral_cube/tests/test_spectral_axis.py b/spectral_cube/tests/test_spectral_axis.py index 4fff19076..5c741b7cd 100644 --- a/spectral_cube/tests/test_spectral_axis.py +++ b/spectral_cube/tests/test_spectral_axis.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - from astropy import wcs from astropy.io import fits from astropy import units as u diff --git a/spectral_cube/tests/test_spectral_cube.py b/spectral_cube/tests/test_spectral_cube.py index 9b3457def..a0c5122f6 100644 --- a/spectral_cube/tests/test_spectral_cube.py +++ b/spectral_cube/tests/test_spectral_cube.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import re import copy import operator diff --git a/spectral_cube/tests/test_subcubes.py b/spectral_cube/tests/test_subcubes.py index 9ab5b1eb8..a979d94a7 100644 --- a/spectral_cube/tests/test_subcubes.py +++ b/spectral_cube/tests/test_subcubes.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import pytest from packaging.version import Version, parse diff --git a/spectral_cube/tests/test_visualization.py b/spectral_cube/tests/test_visualization.py index 82104b5b3..12b67611c 100644 --- a/spectral_cube/tests/test_visualization.py +++ b/spectral_cube/tests/test_visualization.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import pytest from packaging.version import Version, parse diff --git a/spectral_cube/tests/test_wcs_utils.py b/spectral_cube/tests/test_wcs_utils.py index 720dfa8f4..d832aeb8a 100644 --- a/spectral_cube/tests/test_wcs_utils.py +++ b/spectral_cube/tests/test_wcs_utils.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import pytest import warnings diff --git a/spectral_cube/tests/utilities.py b/spectral_cube/tests/utilities.py index 1224e57c4..6a3ed655d 100644 --- a/spectral_cube/tests/utilities.py +++ b/spectral_cube/tests/utilities.py @@ -3,8 +3,6 @@ Utilities for tests. ''' -from six.moves import zip - import numpy as np import astropy.units as u from astropy.io import fits diff --git a/spectral_cube/wcs_utils.py b/spectral_cube/wcs_utils.py index 182df22e6..364afad41 100644 --- a/spectral_cube/wcs_utils.py +++ b/spectral_cube/wcs_utils.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import numpy as np from astropy.wcs import WCS import warnings diff --git a/spectral_cube/ytcube.py b/spectral_cube/ytcube.py index 2102d0afe..20968971f 100644 --- a/spectral_cube/ytcube.py +++ b/spectral_cube/ytcube.py @@ -1,6 +1,3 @@ -from __future__ import print_function, absolute_import, division - -import six import os import subprocess import numpy as np @@ -214,7 +211,7 @@ def quick_isocontour(self, level='3 sigma', title='', description='', ------- The result of the `yt.surface.export_sketchfab` function """ - if isinstance(level, six.string_types): + if isinstance(level, str): sigma = self.cube.std().value level = float(level.split()[0]) * sigma