Skip to content

Commit

Permalink
Renaming module feature_table as table (scikit-bio#1997)
Browse files Browse the repository at this point in the history
* renamed feature_table as table

* added table to documentation

* fixed docstring format
  • Loading branch information
qiyunzhu authored Mar 26, 2024
1 parent a2ca94a commit f521c1e
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 39 deletions.
1 change: 1 addition & 0 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,6 @@ API Reference
workflow
diversity
stats
table
metadata
util
1 change: 1 addition & 0 deletions doc/source/table.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. automodule:: skbio.table
4 changes: 2 additions & 2 deletions skbio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from skbio.tree import TreeNode, nj
from skbio.io import read, write
from skbio.stats.ordination import OrdinationResults
from skbio.feature_table import Table
from skbio.table import Table
import skbio.diversity # noqa
import skbio.stats.evolve # noqa

Expand All @@ -37,7 +37,7 @@
"read",
"write",
"OrdinationResults",
"Table"
"Table",
]

__credits__ = "https://github.com/scikit-bio/scikit-bio/graphs/contributors"
Expand Down
10 changes: 5 additions & 5 deletions skbio/diversity/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ def _check_taxa_alias(taxa, tree, otu_ids):


def _table_to_numpy(table):
"""Convert a skbio.feature_table.Table to a dense representation.
"""Convert a skbio.table.Table to a dense representation.
This is a stop-gap solution to allow current Table objects to interoperate
with existing driver methods, until they transition to be "sparse" aware.
"""
sample_ids = list(table.ids())
obs_ids = list(table.ids(axis='observation'))
obs_ids = list(table.ids(axis="observation"))

if table.is_empty():
counts = np.array([[]] * len(sample_ids))
Expand All @@ -185,11 +185,11 @@ def _validate_table(counts, ids, kwargs):
if ids is not None:
raise ValueError("Cannot provide a `Table` as `counts` and `ids`")

if 'taxa' in kwargs:
if "taxa" in kwargs:
raise ValueError("Cannot provide a `Table` as `counts` and `taxa`")

dense_counts, sample_ids, feature_ids = _table_to_numpy(counts)
if 'tree' in kwargs:
kwargs['taxa'] = feature_ids
if "tree" in kwargs:
kwargs["taxa"] = feature_ids

return dense_counts, sample_ids
2 changes: 1 addition & 1 deletion skbio/diversity/tests/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import numpy.testing as npt

from skbio import DistanceMatrix, TreeNode
from skbio.feature_table import Table, example_table
from skbio.table import Table, example_table
from skbio.util._testing import assert_series_almost_equal
from skbio.diversity import (alpha_diversity, beta_diversity,
partial_beta_diversity,
Expand Down
2 changes: 1 addition & 1 deletion skbio/diversity/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import numpy.testing as npt

from skbio import TreeNode
from skbio.feature_table import example_table
from skbio.table import example_table
from skbio.diversity._util import (_validate_counts_vector,
_validate_counts_matrix,
_validate_taxa_and_tree,
Expand Down
28 changes: 14 additions & 14 deletions skbio/io/format/biom.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
--------------
**Has Sniffer: Yes**
+------+------+---------------------------------------------------------------+
|Reader|Writer| Object Class |
+======+======+===============================================================+
|Yes |Yes |:mod:`skbio.feature_table.Table` |
+------+------+---------------------------------------------------------------+
+------+------+-------------------------------------------------------+
|Reader|Writer| Object Class |
+======+======+=======================================================+
|Yes |Yes |:mod:`skbio.table.Table` |
+------+------+-------------------------------------------------------+
Format Specification
--------------------
Expand All @@ -36,7 +36,7 @@
>>> import io, skbio
>>> f = io.BytesIO()
>>> skbio.feature_table.example_table.write(f) # doctest: +ELLIPSIS
>>> skbio.table.example_table.write(f) # doctest: +ELLIPSIS
<_io.BytesIO object at ...>
>>> roundtrip = skbio.read(f, into=skbio.Table)
>>> roundtrip
Expand All @@ -60,7 +60,7 @@

import skbio
from skbio.io import create_format
from skbio.feature_table import Table
from skbio.table import Table

from .. import BIOMFormatError

Expand Down Expand Up @@ -102,29 +102,29 @@ def _biom_sniffer(fh):


@biom.reader(Table)
def _biom_to_feature_table_into(fh):
return _biom_to_feature_table(fh)
def _biom_to_table_into(fh):
return _biom_to_table(fh)


@biom.reader(None)
def _biom_to_feature_table_default(fh):
def _biom_to_table_default(fh):
# skbio.read('foo.biom', format='biom')
# will return a generator, that subsequently iterates the table.
# returning a single item tuple yields expected behavior such that:
# next(skbio.read('foo.biom', format='biom')) == Table
return (_biom_to_feature_table(fh),)
return (_biom_to_table(fh),)


def _biom_to_feature_table(fh):
def _biom_to_table(fh):
h5grp = h5py.File(fh, "r")
return Table.from_hdf5(h5grp)


@biom.writer(Table)
def _sktable_to_biom(obj, fh):
_feature_table_to_biom(obj, fh)
_table_to_biom(obj, fh)


def _feature_table_to_biom(obj, fh):
def _table_to_biom(obj, fh):
h5grp = h5py.File(fh, "w")
obj.to_hdf5(h5grp, f"Written by scikit-bio version {skbio.__version__}")
14 changes: 7 additions & 7 deletions skbio/io/format/tests/test_biom.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

import h5py

from skbio.feature_table import Table, example_table
from skbio.table import Table, example_table
from skbio.io.format.biom import (
_biom_to_feature_table, _feature_table_to_biom, _biom_sniffer)
_biom_to_table, _table_to_biom, _biom_sniffer)


class BIOMFormatTests(unittest.TestCase):
Expand Down Expand Up @@ -52,13 +52,13 @@ def test_sniffer(self):
self.assertEqual(_biom_sniffer(self.nonbiom_hdf5_path), (False, {}))
self.assertEqual(_biom_sniffer(self.difbiomver_path), (False, {}))

def test_biom_to_feature_table(self):
tab = _biom_to_feature_table(self.valid_biom_path)
def test_biom_to_table(self):
tab = _biom_to_table(self.valid_biom_path)
self.assertEqual(tab, self.table)

def test_feature_table_to_biom(self):
_feature_table_to_biom(self.table, self.writable_biom_path)
roundtrip = _biom_to_feature_table(self.writable_biom_path)
def test_table_to_biom(self):
_table_to_biom(self.table, self.writable_biom_path)
roundtrip = _biom_to_table(self.writable_biom_path)
self.assertEqual(roundtrip, self.table)


Expand Down
10 changes: 5 additions & 5 deletions skbio/feature_table/__init__.py → skbio/table/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
r"""Feature Table (:mod:`skbio.feature_table`)
==========================
r"""Feature Table (:mod:`skbio.table`)
==================================
.. currentmodule:: skbio.feature_table
.. currentmodule:: skbio.table
This module provides support for interaction with BIOM Tables.
Expand All @@ -14,6 +14,6 @@
#
# The full license is in the file LICENSE.txt, distributed with this software.
# ----------------------------------------------------------------------------
from skbio.feature_table._base import Table, example_table
from skbio.table._base import Table, example_table

__all__ = ['Table', 'example_table']
__all__ = ["Table", "example_table"]
2 changes: 1 addition & 1 deletion skbio/feature_table/_base.py → skbio/table/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

from biom import Table, example_table

Table.default_write_format = 'biom'
Table.default_write_format = "biom"
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
# ----------------------------------------------------------------------------

from unittest import TestCase, main
from skbio.feature_table import Table
from skbio.table import Table
import numpy as np


class FeatureTable(TestCase):
def test_feature_table(self):
class TableTests(TestCase):
def test_table(self):
data = np.arange(40).reshape(10, 4)
sample_ids = ['S%d' % i for i in range(4)]
observ_ids = ['O%d' % i for i in range(10)]
Expand Down

0 comments on commit f521c1e

Please sign in to comment.