Skip to content

Commit

Permalink
Remove dependency on six
Browse files Browse the repository at this point in the history
  • Loading branch information
tammojan committed Aug 28, 2024
1 parent 5d00cd9 commit 67dbd86
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 49 deletions.
6 changes: 2 additions & 4 deletions casacore/fitting/fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

from ._fitting import fitting
import numpy as NUM
import six
from casacore.functionals import *
from six import string_types


class fitserver(object):
Expand Down Expand Up @@ -102,13 +100,13 @@ def init(self, n=0, ftype="real", colfac=1.0e-8, lmfac=1.0e-3, fid=0):
return False

def _gettype(self, ftype):
if isinstance(ftype, string_types):
if isinstance(ftype, str):
ftype = ftype.lower()
if ftype not in self._typeids:
raise TypeError("Illegal fitting type")
else:
return self._typeids[ftype]
elif isinstance(ftype, six.integer_types):
elif isinstance(ftype, int):
if ftype not in self._typeids.values():
raise TypeError("Illegal fitting type")
else:
Expand Down
9 changes: 4 additions & 5 deletions casacore/functionals/functional.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from six import string_types, integer_types
from ._functionals import _functional

import numpy
Expand All @@ -20,19 +19,19 @@ def _decorator(func):

class functional(_functional):
def __init__(self, name=None, order=-1, params=None, mode=None, dtype=0):
if isinstance(dtype, string_types):
if isinstance(dtype, str):
dtypes = {'real': 0, 'complex': 1}
dtype = dtypes.get(dtype.lower())
if numpy.iscomplexobj(params):
dtype = 1
self._dtype = dtype
progtext = ""
if not isinstance(name, string_types):
if not isinstance(name, str):
raise TypeError("'name' was not of type string")
if not (isinstance(order, integer_types) or isinstance(order, string_types)):
if not (isinstance(order, int) or isinstance(order, str)):
raise TypeError("'order' was not of type integer or string")
else:
if isinstance(order, string_types):
if isinstance(order, str):
progtext = order
order = -1
# our own functionals server
Expand Down
9 changes: 4 additions & 5 deletions casacore/images/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

from __future__ import print_function

from six import string_types, integer_types
from ._images import Image
import numpy
import numpy.ma as nma
Expand Down Expand Up @@ -128,7 +127,7 @@ def __init__(self, imagename, axis=0, maskname="", images=(), values=None,
if isinstance(imagename, tuple) or isinstance(imagename, list):
if len(imagename) == 0:
raise ValueError('No images given in list or tuple')
if isinstance(imagename[0], string_types):
if isinstance(imagename[0], str):
# Concatenate from image names
Image.__init__(self, imagename, axis)
opened = True
Expand All @@ -137,7 +136,7 @@ def __init__(self, imagename, axis=0, maskname="", images=(), values=None,
Image.__init__(self, imagename, axis, 0, 0)
opened = True
if not opened:
if not isinstance(imagename, string_types):
if not isinstance(imagename, str):
raise ValueError("first argument must be name or" +
" sequence of images or names")
if shape is None:
Expand Down Expand Up @@ -259,7 +258,7 @@ def attrgetrow(self, groupname, key, value=None):
It can only be used for unique attribute keys. An IndexError exception
is raised if no or multiple matches are found.
"""
if not isinstance(key, string_types):
if not isinstance(key, str):
return self._attrgetrow(groupname, key)
# The key is an attribute name whose value has to be found.
rownrs = self.attrfindrows(groupname, key, value)
Expand Down Expand Up @@ -610,7 +609,7 @@ def view(self, tempname='/tmp/tempimage'):

def _adaptAxes(self, axes):
# If axes is a single integer value, turn it into a list.
if isinstance(axes, integer_types):
if isinstance(axes, int):
axes = [axes]
# ImageProxy expects Fortran-numbered axes.
# So reverse the axes.
Expand Down
7 changes: 3 additions & 4 deletions casacore/measures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import casacore.quanta as dq
import os

from six import string_types

if 'MEASURESDATA' in os.environ.keys():
if 'AIPSPATH' not in os.environ.keys():
Expand Down Expand Up @@ -436,7 +435,7 @@ def tofrequency(self, rf, v0, rfq):
"""
if is_measure(rfq) and rfq['type'] == 'frequency':
rfq = dq.quantity(rfq['m0'])
elif isinstance(rfq, string_types):
elif isinstance(rfq, str):
rfq = dq.quantity(rfq)
if is_measure(v0) and v0['type'] == 'doppler' \
and dq.is_quantity(rfq) \
Expand Down Expand Up @@ -488,7 +487,7 @@ def todoppler(self, rf, v0, rfq):
"""
if is_measure(rfq) and rfq['type'] == 'frequency':
rfq = dq.quantity(rfq['m0'])
elif isinstance(rfq, string_types):
elif isinstance(rfq, str):
rfq = dq.quantity(rfq)
if is_measure(v0):
if v0['type'] == 'radialvelocity':
Expand Down Expand Up @@ -823,7 +822,7 @@ def riseset(self, crd, ev="5deg"):
"""

a = self.rise(crd, ev)
if isinstance(a['rise'], string_types):
if isinstance(a['rise'], str):
return {"rise": {"last": a[0], "utc": a[0]},
"set": {"last": a[1], "utc": a[1]},
"solved": False}
Expand Down
3 changes: 1 addition & 2 deletions casacore/quanta/quantity.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from six import string_types
from ._quanta import QuantVec
from ._quanta import Quantity
from ._quanta import from_string, from_dict, from_dict_v
Expand Down Expand Up @@ -52,7 +51,7 @@ def quantity(*args):
"""
if len(args) == 1:
if isinstance(args[0], string_types):
if isinstance(args[0], str):
# use copy constructor to create quantity from string
return Quantity(from_string(args[0]))
elif isinstance(args[0], dict):
Expand Down
3 changes: 1 addition & 2 deletions casacore/tables/msutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#
from __future__ import print_function

from six import string_types
import numpy as np
from casacore.tables.table import (table, taql,
_required_ms_desc,
Expand Down Expand Up @@ -315,7 +314,7 @@ def msconcat(names, newname, concatTime=False):
for key in keywords:
if key != 'SORTED_TABLE':
val = keywords[key]
if isinstance(val, string_types):
if isinstance(val, str):
tsub = table(val, ack=False)
tsubn = tsub.copy(newname + '/' + key, deep=True)
tnew.putkeyword(key, tsubn)
Expand Down
29 changes: 13 additions & 16 deletions casacore/tables/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

from __future__ import print_function

from six import string_types
from ._tables import (Table,
_default_ms,
_default_ms_subtable,
Expand All @@ -47,8 +46,6 @@

from .tablehelper import (_add_prefix, _remove_prefix, _do_remove_prefix,
_format_row)
import six


def default_ms(name, tabdesc=None, dminfo=None):
"""
Expand Down Expand Up @@ -344,7 +341,7 @@ def __init__(self, tablename, tabledesc=False, nrow=0, readonly=True,
# - concatenate open tables (ConcatTable)
tabname = _remove_prefix(tablename)
lockopt = lockoptions
if isinstance(lockoptions, string_types):
if isinstance(lockoptions, str):
lockopt = {'option': lockoptions}
if isinstance(tabledesc, dict):
# Create a new table.
Expand All @@ -371,15 +368,15 @@ def __init__(self, tablename, tabledesc=False, nrow=0, readonly=True,
opt = 5
if _delete:
opt = 6
if isinstance(tabname, string_types):
if isinstance(tabname, str):
Table.__init__(self, tabname, lockopt, opt)
if ack:
print('Successful', typstr, 'open of',
lockopt['option'] + '-locked table',
tabname + ':',
self.ncols(), 'columns,',
self.nrows(), 'rows')
elif isinstance(tabname[0], string_types):
elif isinstance(tabname[0], str):
# Concatenate and open named tables.
Table.__init__(self, tabname, concatsubtables,
lockopt, opt)
Expand Down Expand Up @@ -1277,7 +1274,7 @@ def fieldnames(self, keyword=''):
of the struct value of the i-th keyword.
"""
if isinstance(keyword, string_types):
if isinstance(keyword, str):
return self._getfieldnames('', keyword, -1)
else:
return self._getfieldnames('', '', keyword)
Expand All @@ -1299,7 +1296,7 @@ def colfieldnames(self, columnname, keyword=''):
of the struct value of the i-th keyword.
"""
if isinstance(keyword, string_types):
if isinstance(keyword, str):
return self._getfieldnames(columnname, keyword, -1)
else:
return self._getfieldnames(columnname, '', keyword)
Expand Down Expand Up @@ -1327,7 +1324,7 @@ def getkeyword(self, keyword):
of the i-th keyword.
"""
if isinstance(keyword, string_types):
if isinstance(keyword, str):
return self._getkeyword('', keyword, -1)
else:
return self._getkeyword('', '', keyword)
Expand All @@ -1338,7 +1335,7 @@ def getcolkeyword(self, columnname, keyword):
It is similar to :func:`getkeyword`.
"""
if isinstance(keyword, string_types):
if isinstance(keyword, str):
return self._getkeyword(columnname, keyword, -1)
else:
return self._getkeyword(columnname, '', keyword)
Expand Down Expand Up @@ -1366,7 +1363,7 @@ def getsubtables(self):
keyset = self.getkeywords()
names = []
for key, value in keyset.items():
if isinstance(value, string_types) and value.find('Table: ') == 0:
if isinstance(value, str) and value.find('Table: ') == 0:
names.append(_do_remove_prefix(value))
return names

Expand Down Expand Up @@ -1402,7 +1399,7 @@ def putkeyword(self, keyword, value, makesubrecord=False):
val = value
if isinstance(val, table):
val = _add_prefix(val.name())
if isinstance(keyword, string_types):
if isinstance(keyword, str):
return self._putkeyword('', keyword, -1, makesubrecord, val)
else:
return self._putkeyword('', '', keyword, makesubrecord, val)
Expand All @@ -1416,7 +1413,7 @@ def putcolkeyword(self, columnname, keyword, value, makesubrecord=False):
val = value
if isinstance(val, table):
val = _add_prefix(val.name())
if isinstance(keyword, string_types):
if isinstance(keyword, str):
return self._putkeyword(columnname, keyword, -1,
makesubrecord, val)
else:
Expand Down Expand Up @@ -1451,7 +1448,7 @@ def removekeyword(self, keyword):
the i-th keyword.
"""
if isinstance(keyword, string_types):
if isinstance(keyword, str):
self._removekeyword('', keyword, -1)
else:
self._removekeyword('', '', keyword)
Expand All @@ -1462,7 +1459,7 @@ def removecolkeyword(self, columnname, keyword):
It is similar to :func:`removekeyword`.
"""
if isinstance(keyword, string_types):
if isinstance(keyword, str):
self._removekeyword(columnname, keyword, -1)
else:
self._removekeyword(columnname, '', keyword)
Expand All @@ -1482,7 +1479,7 @@ def getdesc(self, actual=True):
# as these aren't valid. (See tabledefinehypercolumn)
hcdefs = tabledesc.get('_define_hypercolumn_', {})

for c, hcdef in six.iteritems(hcdefs):
for c, hcdef in hcdefs.items():
if "HCcoordnames" in hcdef and len(hcdef["HCcoordnames"]) == 0:
del hcdef["HCcoordnames"]
if "HCidnames" in hcdef and len(hcdef["HCidnames"]) == 0:
Expand Down
9 changes: 4 additions & 5 deletions casacore/tables/tablehelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#
# $Id: tableutil.py,v 1.6 2006/11/08 00:12:55 gvandiep Exp $

from six import string_types, integer_types
import numpy
import re
from ..quanta import quantity
Expand All @@ -42,15 +41,15 @@ def _add_prefix(name):
def _do_remove_prefix(name):
"""Strip the possible prefix 'Table: ' from a table name."""
res = name
if isinstance(res, string_types):
if isinstance(res, str):
if res.find('Table: ') == 0:
res = res.replace('Table: ', '', 1)
return res


def _remove_prefix(name):
"""Strip the possible prefix 'Table: ' from one or more table names."""
if isinstance(name, string_types):
if isinstance(name, str):
return _do_remove_prefix(name)
return [_do_remove_prefix(nm) for nm in name]

Expand Down Expand Up @@ -114,13 +113,13 @@ def _check_key_slice(key, nrows, name):
def _value_type_name(value):
if isinstance(value, bool):
return 'boolean'
if isinstance(value, integer_types):
if isinstance(value, int):
return 'integer'
if isinstance(value, float):
return 'double'
if isinstance(value, complex):
return 'dcomplex'
if isinstance(value, string_types):
if isinstance(value, str):
return 'string'
if isinstance(value, dict):
return 'record'
Expand Down
5 changes: 2 additions & 3 deletions casacore/tables/tableutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

from collections import defaultdict

import six
from .table import table
from .tablehelper import _remove_prefix, _value_type_name

Expand Down Expand Up @@ -525,7 +524,7 @@ def __init__(self):

# Iterate through the table columns, grouping them
# by their dataManagerGroup
for c, d in six.iteritems(tabdesc):
for c, d in tabdesc.items():
if c in ('_define_hypercolumn_', '_keywords_', '_private_keywords_'):
continue

Expand Down Expand Up @@ -568,7 +567,7 @@ def __init__(self):
'SPEC' : dm_group.spec,
'SEQNR': i
} for i, (group, dm_group)
in enumerate(six.iteritems(dm_groups))
in enumerate(dm_groups.items())
}

# Create the old glish names for them.
Expand Down
3 changes: 1 addition & 2 deletions casacore/util/substitute.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
# 520 Edgemont Road
# Charlottesville, VA 22903-2475 USA

from six import string_types
import numpy as np

__all__ = ['getlocals', 'getvariable', 'substitute']
Expand Down Expand Up @@ -266,7 +265,7 @@ def substitutevar(v):
def substituteonevar(v):
# A string needs to be enclosed in quotes.
# A vector value is enclosed in square brackets and separated by commas.
if isinstance(v, string_types):
if isinstance(v, str):
return substitutestring(v)
# A numeric or boolean value is converted to a string.
# A vector value is enclosed in square brackets and separated by commas.
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ classifiers=[
]
dependencies = [
"numpy",
"six",
]

[project.urls]
Expand Down

0 comments on commit 67dbd86

Please sign in to comment.