Skip to content

Commit

Permalink
Merge pull request #62 from astrofrog/bump-minimum-python-39
Browse files Browse the repository at this point in the history
Bump minimum required Python version to 3.9
  • Loading branch information
astrofrog authored Apr 17, 2024
2 parents 1723239 + b770d2a commit b3da1ee
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 47 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@ jobs:
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v1
with:
envs: |
- linux: py38-test-casa-oldestdeps
- linux: py38-test-casa
- linux: py39-test
- linux: py310-test
- linux: py311-test-devdeps
- linux: py39-test-oldestdeps
- linux: py310-test-casa
- linux: py311-test
- linux: py312-test-devdeps
- macos: py38-test-casa
- macos: py39-test
- macos: py310-test
- macos: py311-test-devdeps
- macos: py310-test-casa
- macos: py311-test
- macos: py312-test-devdeps
- windows: py38-test
- windows: py39-test
- windows: py310-test
- windows: py311-test-devdeps
- windows: py311-test
- windows: py312-test-devdeps
# NOTE: the tests below are disabled for now until tox-conda is compatible with tox 4
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ the file format and have re-used some of the data class names. Therefore, since
be considered translations of casacore into Python, we license casa-formats-io under the same LGPL license as casacore.


casa-formats-io supports python versions >=3.8.
casa-formats-io supports python versions >=3.9.
13 changes: 7 additions & 6 deletions casa_formats_io/casa_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import print_function, absolute_import, division

from math import prod
import os
from math import ceil
import uuid
Expand Down Expand Up @@ -46,7 +47,7 @@ def __init__(self, filename, totalshape, chunkshape, chunkoversample=None,
self.dtype = dtype
self.ndim = len(self.shape)
self._stacks = np.ceil(np.array(totalshape) / np.array(chunkshape)).astype(int)
self._chunksize = np.product(chunkshape)
self._chunksize = prod(chunkshape)
self._itemsize = itemsize
self._memmap = memmap
self._offset = offset
Expand Down Expand Up @@ -97,7 +98,7 @@ def __getitem__(self, item):
if self._itemsize == 1:

if self._memmap:
n_native = np.product(self._chunkoversample)
n_native = prod(self._chunkoversample)
rounded_up_chunksize = ceil(self._chunksize / n_native / 8) * n_native
offset = offset // self._chunksize * rounded_up_chunksize
array_uint8 = np.fromfile(self._filename, dtype=np.uint8,
Expand Down Expand Up @@ -180,22 +181,22 @@ def image_to_dask(imagename, memmap=True, mask=False, target_chunksize=None):

# chunkshape defines how the chunks (array subsets) are written to disk
chunkshape = tuple(dm.default_tile_shape)
chunksize = np.product(chunkshape)
chunksize = prod(chunkshape)

# the total shape defines the final output array shape
totalshape = dm.cube_shapes[0]

# we expect that the total size of the array will be determined by finding
# the number of chunks along each dimension rounded up
totalsize = np.product(np.ceil(totalshape / chunkshape)) * chunksize
totalsize = prod(np.ceil(totalshape / chunkshape)) * chunksize

# the file size helps us figure out what the dtype of the array is
filesize = os.stat(img_fn).st_size

# the ratio between these tells you how many chunks must be combined
# to create a final stack
stacks = np.ceil(totalshape / chunkshape).astype(int)
nchunks = int(np.product(stacks))
nchunks = int(prod(stacks))

# check that the file size is as expected and determine the data dtype
if mask:
Expand Down Expand Up @@ -247,7 +248,7 @@ def image_to_dask(imagename, memmap=True, mask=False, target_chunksize=None):
factors = [f for f in range(stacks[dim] + 1) if stacks[dim] % f == 0]
for factor in factors:
chunkoversample[dim] = factor
if np.product(chunkoversample) * chunksize > target_chunksize:
if prod(chunkoversample) * chunksize > target_chunksize:
chunkoversample = previous_chunkoversample
finished = True
break
Expand Down
2 changes: 1 addition & 1 deletion casa_formats_io/casa_low_level_io/casa_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def getdminfo(filename, endian='>'):

if isinstance(dm, StandardStMan):

dminfo['COLUMNS'] = np.array(sorted(col.name for col in colset.columns), '<U16')
dminfo['COLUMNS'] = np.array(sorted(col.name for col in colset.columns), 'U')
dminfo['NAME'] = dm.name
dminfo['SEQNR'] = 0
dminfo['TYPE'] = 'StandardStMan'
Expand Down
8 changes: 2 additions & 6 deletions casa_formats_io/casa_low_level_io/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def read_iposition(f):
'float': ('float', read_float32, np.float32),
'double': ('double', read_float64, np.float64),
'dcomplex': ('void', read_complex128, np.complex128),
'string': ('String', read_string, '<U16'),
'string': ('String', read_string, 'U'),
'int': ('Int', read_int32, int),
'uint': ('uInt', read_int32, int)
}
Expand All @@ -172,7 +172,7 @@ def read_iposition(f):
TO_DTYPE['int'] = 'i4'
TO_DTYPE['uint'] = 'u4'
TO_DTYPE['short'] = 'i2'
TO_DTYPE['string'] = '<U16'
TO_DTYPE['string'] = 'U'
TO_DTYPE['bool'] = 'bool'
TO_DTYPE['record'] = 'O'

Expand All @@ -192,10 +192,6 @@ def read_as_numpy_array(f, value_type, nelem, shape=None, length_modifier=0):
if value_type == 'string':
array = np.array([read_string(f, length_modifier=length_modifier)
for i in range(nelem)])
if nelem > 0:
# HACK: only needed for getdesc comparisons
if max([len(s) for s in array]) < 16:
array = array.astype('<U16')
elif value_type == 'bool':
length = int(np.ceil(nelem / 8)) * 8
array = np.unpackbits(np.frombuffer(f.read(length), dtype='uint8'),
Expand Down
12 changes: 6 additions & 6 deletions casa_formats_io/casa_low_level_io/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,17 @@ def read(cls, f):
elif rectype == 'table':
self.values[name] = 'Table: ' + os.path.abspath(os.path.join(f.original_filename, read_string(f)))
elif rectype == 'arrayint':
self.values[name] = read_array(f, 'int')
self.values[name] = read_array(f, 'int').astype('<i4')
elif rectype == 'arrayuint':
self.values[name] = read_array(f, 'uint')
self.values[name] = read_array(f, 'uint').astype('<u4')
elif rectype == 'arrayfloat':
self.values[name] = read_array(f, 'float')
self.values[name] = read_array(f, 'float').astype('<f4')
elif rectype == 'arraydouble':
self.values[name] = read_array(f, 'double')
self.values[name] = read_array(f, 'double').astype('<f8')
elif rectype == 'arraycomplex':
self.values[name] = read_array(f, 'complex')
self.values[name] = read_array(f, 'complex').astype('<c8')
elif rectype == 'arraydcomplex':
self.values[name] = read_array(f, 'dcomplex')
self.values[name] = read_array(f, 'dcomplex').astype('<c16')
elif rectype == 'arraystr':
self.values[name] = read_array(f, 'string')
elif rectype == 'record':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_getdminfo(tmp_path, shape):
# the Numpy arrays inside). Older versions of casatools represent some of
# the vectors as int32 instead of native int but our implementation uses
# native int so strip any mention of int32 from reference output
assert pformat(actual) == pformat(reference).replace(', dtype=int32', '')
assert pformat(actual) == pformat(reference).replace(', dtype=int32', '').replace('U3', 'U16')


def test_getdminfo_large():
Expand Down Expand Up @@ -83,7 +83,6 @@ def filename(request):
return request.getfixturevalue(request.param)


@pytest.mark.openfiles_ignore
@pytest.mark.skipif('not CASATOOLS_INSTALLED')
def test_generic_table_read(tmp_path):

Expand Down Expand Up @@ -122,7 +121,7 @@ def test_generic_table_read(tmp_path):
keywords['scalars']['s_' + name] = t[name][0]
keywords['arrays']['a_' + name] = t[name]

tb.open(filename_casa)
tb.open(filename_casa, nomodify=False)
tb.putkeywords(keywords)
tb.flush()
tb.close()
Expand All @@ -138,10 +137,7 @@ def test_generic_table_read(tmp_path):

actual_getdminfo = getdminfo(filename_casa, endian='<')

# FIXME: For some reason IndexLength is zero in the CASA output
actual_getdminfo['*1']['SPEC']['IndexLength'] = 0

assert pformat(actual_getdminfo) == pformat(reference_getdminfo)
assert pformat(actual_getdminfo).replace('<U16', '<U8') == pformat(reference_getdminfo)

tnew = Table.read(filename_casa)

Expand All @@ -155,7 +151,7 @@ def test_getdesc_floatarray():

desc = getdesc(os.path.join(DATA, 'floatarray.image'))
trc = desc['_keywords_']['masks']['mask0']['box']['trc']
assert trc.dtype == np.dtype('>f4')
assert trc.dtype == np.dtype('<f4')
assert_equal(trc, [512, 512, 1, 100])


Expand Down Expand Up @@ -246,7 +242,6 @@ def test_ms_tables(tablename):
tb.close()


@pytest.mark.openfiles_ignore
@pytest.mark.skipif('not CASATOOLS_INSTALLED')
def test_vector_columns(tmp_path):

Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ to provide:
At this time (November 2020), only reading .image datasets is supported. Reading measurement sets
(.ms) or writing data of any kind are not yet supported.

casa-formats-io supports python versions >=3.8.
casa-formats-io supports python versions >=3.9.

Using casa-formats-io
---------------------
Expand Down
9 changes: 3 additions & 6 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ install_requires =
astropy>=4.0
numpy>=1.21
dask[array]>=2.0
python_requires = >=3.8
python_requires = >=3.9

[options.extras_require]
test =
Expand All @@ -28,7 +28,7 @@ docs =
casa =
# Note that it looks like there is a casatools bug in 6.4.3.8
# https://github.com/radio-astro-tools/casa-formats-io/issues/39
casatools>=6.2.0.124,<6.4.3.8
casatools>=6.2.0.12

[options.package_data]
casa_formats_io.tests = data/*, data/*/*, data/*/*/*, data/*/*/*/*
Expand All @@ -37,9 +37,6 @@ casa_formats_io.casa_low_level_io.tests = data/*, data/*/*, data/*/*/*, data/*/*
[tool:pytest]
minversion = 3.0
norecursedirs = build docs/_build
doctest_plus = enabled
filterwarnings =
error::ResourceWarning

[coverage:run]
omit =
Expand Down Expand Up @@ -79,4 +76,4 @@ glue.plugins =
casa_ms_reader = casa_formats_io.glue_factory:setup

[bdist_wheel]
py_limited_api = cp38
py_limited_api = cp39
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist =
py{38,39,310}-test{,-oldestdeps,-devdeps,-casa}{,-conda}
py{39,310,311,312}-test{,-oldestdeps,-devdeps,-casa}{,-conda}
build_docs
codestyle
requires =
Expand Down

0 comments on commit b3da1ee

Please sign in to comment.