Skip to content

Commit

Permalink
Add support for adding rows to a table (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjperkins authored Sep 8, 2023
1 parent 8bd07e2 commit 688af31
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 1 deletion.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ jobs:
run: |
cd $HOME
virtualenv $HOME/venv
source $HOME/venv/bin/activate && pip install --find-links=${{ github.workspace }}/wheelhouse arcae[test]
export WHEELHOUSE=${{ github.workspace }}/wheelhouse
export PYABI=${{ matrix.python[1] }}
export WHEEL=$(find $HWEELHOUSE -type f | grep $PYABI)
echo "Installing $WHEEL"
source $HOME/venv/bin/activate && pip install $WHEEL[test]
source $HOME/venv/bin/activate && py.test -s -vvv --pyargs arcae
upload-to-test-pypi:
Expand Down
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ History

X.Y.Z (YYYY-MM-DD)
------------------
* Add support for adding rows to a table (:pr:`53`)
* Create and use JSON Table Descriptors and Data Managers (:pr:`51`)
* Use ccache, if available (:pr:`50`)
* Use vcpkg's internal github actions binary caching (:pr:`49`)
Expand Down
2 changes: 2 additions & 0 deletions arcae/arrow_tables.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ cdef extern from "../cpp/safe_table_proxy.h" namespace "arcae" nogil:
CResult[unsigned int] ncolumns " SafeTableProxy::ncolumns"()
CResult[vector[string]] columns " SafeTableProxy::columns"()
CResult[vector[shared_ptr[CCasaTable]]] partition " SafeTableProxy::partition"(const vector[string] & partition_columns, const vector[string] & sort_columns)
CResult[bool] addrows " SafeTableProxy::addrows"(unsigned int nrows)


cdef extern from "../cpp/table_factory.h" namespace "arcae" nogil:
cdef CResult[shared_ptr[CCasaTable]] copen_table" arcae::open_table"(
Expand Down
2 changes: 2 additions & 0 deletions arcae/arrow_tables.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ cdef class Table:

return result

def addrows(self, nrows: int):
return GetResultValue(self.c_table.get().addrows(nrows))

class Configuration(MutableMapping):
def __getitem__(self, key: str):
Expand Down
13 changes: 13 additions & 0 deletions arcae/tests/test_descriptors.py → arcae/tests/test_descriptor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from numpy.testing import assert_array_equal

from arcae.lib.arrow_tables import Table
from arcae.lib.arrow_tables import ms_descriptor

Expand All @@ -9,6 +11,17 @@ def test_descriptor_basic():
assert isinstance(ms_descriptor("SPECTRAL_WINDOW"), dict)


def test_ms_addrows(tmp_path_factory):
ms = tmp_path_factory.mktemp("test") / "test.ms"
with Table.ms_from_descriptor(str(ms)) as T:
T.addrows(10)
assert T.nrow() == 10
AT = T.to_arrow()
assert len(AT) == 10
assert_array_equal(AT.column("TIME"), 0)
assert_array_equal(AT.column("ANTENNA1"), 0)
assert_array_equal(AT.column("ANTENNA2"), 0)

def test_ms_and_weather_subtable(tmp_path_factory):
ms = tmp_path_factory.mktemp("test") / "test.ms"
with Table.ms_from_descriptor(str(ms)) as T:
Expand Down
11 changes: 11 additions & 0 deletions cpp/safe_table_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,17 @@ SafeTableProxy::partition(
}


Result<bool>
SafeTableProxy::addrows(casacore::uInt nrows) {
ARROW_RETURN_NOT_OK(FailIfClosed());

return run_isolated([this, nrows]() -> Result<bool> {
this->table_proxy->addRow(nrows);
return true;
});
}


Result<bool>
SafeTableProxy::close() {
if(!is_closed) {
Expand Down
2 changes: 2 additions & 0 deletions cpp/safe_table_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class SafeTableProxy {
const std::vector<std::string> & partition_columns={},
const std::vector<std::string> & sort_columns={}) const;

arrow::Result<bool> addrows(casacore::uInt nrows);

arrow::Result<bool> close();
};

Expand Down

0 comments on commit 688af31

Please sign in to comment.