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..17ffa56 100644 --- a/casacore/tables/tablehelper.py +++ b/casacore/tables/tablehelper.py @@ -26,6 +26,7 @@ # $Id: tableutil.py,v 1.6 2006/11/08 00:12:55 gvandiep Exp $ import numpy +import pathlib import re from ..quanta import quantity @@ -51,6 +52,8 @@ def _remove_prefix(name): """Strip the possible prefix 'Table: ' from one or more table names.""" if isinstance(name, str): return _do_remove_prefix(name) + elif isinstance(name, pathlib.Path): + return name return [_do_remove_prefix(nm) for nm in name] diff --git a/tests/test_table.py b/tests/test_table.py index 3d25cca..0a3c41e 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_support(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)