Skip to content

Commit

Permalink
rename to common names for SNT and archive.Reader
Browse files Browse the repository at this point in the history
  • Loading branch information
relleums committed Jul 12, 2024
1 parent 2787408 commit bfa4154
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
13 changes: 5 additions & 8 deletions sparse_numeric_table/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import gzip
import copy

from .base import SparseNumericTable
from .base import _sub_dtypes
from .base import _intersection
from .base import _cut
from . import base


def open(file, mode="r", dtypes=None, compress=False, block_size=262_144):
Expand Down Expand Up @@ -208,16 +205,16 @@ def read_column(self, level_key, column_key):
return out.to_recarray()

def intersection(self, index, levels=None):
return _intersection(handle=self, index=index, levels=levels)
return base._intersection(handle=self, index=index, levels=levels)

def read_table(
def query(
self,
index=None,
indices=None,
levels_and_columns=None,
align_indices=False,
):
return _cut(
return base._query(
handle=self,
index=index,
indices=indices,
Expand Down Expand Up @@ -264,5 +261,5 @@ def concatenate(input_paths, output_path, dtypes):
with open(output_path, mode="w", dtypes=dtypes) as tout:
for input_path in input_paths:
with open(input_path, mode="r") as tin:
part = tin.read_table()
part = tin.query()
tout.append_table(part)
6 changes: 3 additions & 3 deletions sparse_numeric_table/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ def append(self, other):
def intersection(self, index, levels=None):
return _intersection(handle=self, index=index, levels=levels)

def cut(
def query(
self,
index=None,
indices=None,
levels_and_columns=None,
align_indices=False,
):
return _cut(
return _query(
handle=self,
index=index,
indices=indices,
Expand Down Expand Up @@ -176,7 +176,7 @@ def _intersection(handle, index, levels=None):
return inter


def _cut(
def _query(
handle,
index=None,
indices=None,
Expand Down
12 changes: 6 additions & 6 deletions sparse_numeric_table/tests/test_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_write_read_full_table():
f.append_table(my_table)

with snt.archive.open(path, "r") as f:
my_table_back = f.read_table()
my_table_back = f.query()

snt.testing.assert_tables_are_equal(my_table, my_table_back)

Expand All @@ -38,7 +38,7 @@ def test_read_only_part_of_table():
f.append_table(my_table)

with snt.archive.open(path, "r") as f:
partly_back = f.read_table(
partly_back = f.query(
levels_and_columns={
"elementary_school": ["idx", "num_friends"]
}
Expand Down Expand Up @@ -67,12 +67,12 @@ def test_column_commnad():
f.append_table(my_table)

with snt.archive.open(path, "r") as f:
partly_back = f.read_table(
partly_back = f.query(
levels_and_columns={"elementary_school": "__all__"}
)

with pytest.raises(KeyError):
_ = f.read_table(levels_and_columns={"elementary_school": "foo"})
_ = f.query(levels_and_columns={"elementary_school": "foo"})

np.testing.assert_array_equal(
my_table["elementary_school"],
Expand All @@ -92,7 +92,7 @@ def test_preserves_dtypes_without_writing_anything():
pass # do not write anything.

with snt.archive.open(path, "r") as f:
back = f.read_table()
back = f.query()

snt.testing.assert_dtypes_are_equal(table.dtypes, back.dtypes)

Expand All @@ -109,6 +109,6 @@ def test_preserves_dtypes_when_table_empty():
f.append_table(table)

with snt.archive.open(path, "r") as f:
back = f.read_table()
back = f.query()

snt.testing.assert_dtypes_are_equal(table.dtypes, back.dtypes)
12 changes: 6 additions & 6 deletions sparse_numeric_table/tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_from_records():
dtypes=dtypes,
)
with snt.archive.open(full_path, "r") as tin:
full_table = tin.read_table()
full_table = tin.query()

snt.testing.assert_dtypes_are_equal(a=full_table.dtypes, b=dtypes)

Expand All @@ -74,7 +74,7 @@ def test_write_read_full_table():
with snt.archive.open(zpath, "w", dtypes=table.dtypes) as tout:
tout.append_table(table)
with snt.archive.open(zpath, "r") as tin:
zback = tin.read_table()
zback = tin.query()
snt.testing.assert_dtypes_are_equal(table.dtypes, zback.dtypes)
snt.testing.assert_tables_are_equal(table, zback)

Expand Down Expand Up @@ -105,7 +105,7 @@ def test_write_read_empty_table():
with snt.archive.open(zpath, "w", dtypes=empty.dtypes) as tout:
tout.append_table(empty)
with snt.archive.open(zpath, "r") as tin:
zback = tin.read_table()
zback = tin.query()
snt.testing.assert_dtypes_are_equal(empty.dtypes, zback.dtypes)
snt.testing.assert_tables_are_equal(empty, zback)

Expand Down Expand Up @@ -285,7 +285,7 @@ def test_concatenate_several_tables():
dtypes=table_i_dtypes,
)
with snt.archive.open(output_path, "r") as tin:
full_table = tin.read_table()
full_table = tin.query()

snt.testing.assert_dtypes_are_equal(full_table.dtypes, table_i_dtypes)

Expand Down Expand Up @@ -327,7 +327,7 @@ def test_concatenate_empty_list_of_paths():
)

with snt.archive.open(output_path, "r") as tin:
empty_table = tin.read_table()
empty_table = tin.query()

snt.testing.assert_dtypes_are_equal(dtypes, empty_table.dtypes)
assert empty_table["elementary_school"]["idx"].shape[0] == 0
Expand Down Expand Up @@ -359,7 +359,7 @@ def test_only_index_in_level():
with snt.archive.open(path, "w", dtypes=table.dtypes) as tout:
tout.append_table(table)
with snt.archive.open(path, "r") as tin:
table_back = tin.read_table()
table_back = tin.query()
snt.testing.assert_dtypes_are_equal(table_back.dtypes, dtypes)
snt.testing.assert_tables_are_equal(table, table_back)

Expand Down

0 comments on commit bfa4154

Please sign in to comment.