diff --git a/casacore/tables/table.py b/casacore/tables/table.py index 9d54d38..74b8413 100755 --- a/casacore/tables/table.py +++ b/casacore/tables/table.py @@ -315,6 +315,9 @@ def __init__(self, tablename, tabledesc=False, nrow=0, readonly=True, _columnnames=[], _datatypes=[], _oper=0, _delete=False): """Open or create a table.""" + import pathlib + if isinstance(tablename, pathlib.Path): + tablename = str(tablename) if _oper == 1: # This is the readascii constructor. tabname = _remove_prefix(tablename) diff --git a/casacore/tables/tablehelper.py b/casacore/tables/tablehelper.py index 7de6d2a..bfcd6f2 100644 --- a/casacore/tables/tablehelper.py +++ b/casacore/tables/tablehelper.py @@ -51,7 +51,9 @@ def _remove_prefix(name): """Strip the possible prefix 'Table: ' from one or more table names.""" if isinstance(name, str): return _do_remove_prefix(name) - return [_do_remove_prefix(nm) for nm in name] + elif hasattr(name, "__iter__"): + return [_do_remove_prefix(nm) for nm in name] + return name def _check_index(key, name): diff --git a/tests/test_table.py b/tests/test_table.py index 3d25cca..35179d8 100644 --- a/tests/test_table.py +++ b/tests/test_table.py @@ -1,4 +1,5 @@ """Tests for tables module.""" +import pathlib import unittest from casacore.tables import (makescacoldesc, makearrcoldesc, table, maketabdesc, tableexists, tableiswritable, @@ -58,6 +59,14 @@ def test_tableinfo(self): t.close() tabledelete("ttable.py_tmp.tab1") + def test_path_suppoert(self): + """Test table names can be given as Path objects.""" + c1 = makescacoldesc("col", 0) + path = pathlib.Path("ttable.py_tmp.tab1") + t = table(path, maketabdesc([c1]), ack=False) + t.close() + tabledelete(path) + def test_tableascii(self): """Testing ASCII table.""" c1 = makescacoldesc("coli", 0)