From 1b084d56ca66d73ed05fd83b5657c0824f4b72c5 Mon Sep 17 00:00:00 2001 From: Ryan Ly Date: Fri, 4 Jun 2021 18:02:01 -0700 Subject: [PATCH 1/3] Fix postprocess set of fields in custom class generator (#626) * Fix postprocess set of fields in custom class generator * Update changelog * Update changelog --- CHANGELOG.md | 5 +++++ src/hdmf/build/__init__.py | 2 +- src/hdmf/build/classgenerator.py | 7 ++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af8b8930b..a00a384ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # HDMF Changelog +## HDMF 2.5.7 (June 4, 2021) + +### Bug fix +- Fix generation of extension classes that extend MultiContainerInterface and use a custom _fieldsname. @rly (#626) + ## HDMF 2.5.6 (May 19, 2021) ### Bug fix diff --git a/src/hdmf/build/__init__.py b/src/hdmf/build/__init__.py index 5f467d916..ea5d21152 100644 --- a/src/hdmf/build/__init__.py +++ b/src/hdmf/build/__init__.py @@ -1,5 +1,5 @@ from .builders import Builder, DatasetBuilder, GroupBuilder, LinkBuilder, ReferenceBuilder, RegionBuilder -from .classgenerator import CustomClassGenerator +from .classgenerator import CustomClassGenerator, MCIClassGenerator from .errors import (BuildError, OrphanContainerBuildError, ReferenceTargetNotBuiltError, ContainerConfigurationError, ConstructError) from .manager import BuildManager, TypeMap diff --git a/src/hdmf/build/classgenerator.py b/src/hdmf/build/classgenerator.py index edd95a6e7..db4f326d3 100644 --- a/src/hdmf/build/classgenerator.py +++ b/src/hdmf/build/classgenerator.py @@ -268,9 +268,10 @@ def post_process(cls, classdict, bases, docval_args, spec): :param spec: The spec for the container class to generate. """ # convert classdict['__fields__'] from list to tuple if present - fields = classdict.get(bases[0]._fieldsname) - if fields is not None: - classdict[bases[0]._fieldsname] = tuple(fields) + for b in bases: + fields = classdict.get(b._fieldsname) + if fields is not None and not isinstance(fields, tuple): + classdict[b._fieldsname] = tuple(fields) # if spec provides a fixed name for this type, remove the 'name' arg from docval_args so that values cannot # be passed for a name positional or keyword arg From 36db0e8d937694423d79ba4973b82ab1eaa2ef86 Mon Sep 17 00:00:00 2001 From: Ryan Ly Date: Tue, 8 Jun 2021 18:05:31 -0700 Subject: [PATCH 2/3] Update docs (#627) Co-authored-by: Oliver Ruebel --- CHANGELOG.md | 5 + docs/CONTRIBUTING.rst | 27 +++-- docs/source/_static/theme_overrides.css | 7 ++ docs/source/building_api.rst | 2 +- docs/source/conf.py | 4 +- docs/source/extensions.rst | 2 +- docs/source/getting_started.rst | 129 --------------------- docs/source/index.rst | 42 +++---- docs/source/install_developers.rst | 146 ++++++++++++++++++++++++ docs/source/install_users.rst | 32 ++++++ docs/source/validation.rst | 9 +- 11 files changed, 238 insertions(+), 167 deletions(-) create mode 100644 docs/source/_static/theme_overrides.css delete mode 100644 docs/source/getting_started.rst create mode 100644 docs/source/install_developers.rst create mode 100644 docs/source/install_users.rst diff --git a/CHANGELOG.md b/CHANGELOG.md index a00a384ab..985a4edb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # HDMF Changelog +## HDMF 2.5.8 (Upcoming) + +### Minor improvements +- Improve Sphinx documentation. @rly (#627) + ## HDMF 2.5.7 (June 4, 2021) ### Bug fix diff --git a/docs/CONTRIBUTING.rst b/docs/CONTRIBUTING.rst index 8798a50cc..3d4aef8a3 100644 --- a/docs/CONTRIBUTING.rst +++ b/docs/CONTRIBUTING.rst @@ -1,5 +1,5 @@ -How to contribute to HDMF software and documents -================================================= +Contributing Guide +================== .. _sec-code-of-conduct: @@ -87,13 +87,27 @@ From your local copy directory, use the following commands. Styleguides ----------- +Python Code Styleguide +^^^^^^^^^^^^^^^^^^^^^^ + +Before you create a Pull Request, make sure you are following the HDMF style guide (PEP8_). +To check whether your code conforms to the HDMF style guide, simply run the flake8_ tool in the project's root +directory. + +.. _flake8: http://flake8.pycqa.org/en/latest/ +.. _PEP8: https://www.python.org/dev/peps/pep-0008/ + +.. code:: + + $ flake8 + Git Commit Message Styleguide ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ * Use the present tense ("Add feature" not "Added feature") * The first should be short and descriptive. * Additional details may be included in further paragraphs. -* If a commit fixes an issues, then include "Fix #X" where X is the number of the issue. +* If a commit fixes an issue, then include "Fix #X" where X is the number of the issue. * Reference relevant issues and pull requests liberally after the first line. Documentation Styleguide @@ -101,18 +115,13 @@ Documentation Styleguide All documentations is written in reStructuredText (RST) using Sphinx. -Python Code Styleguide -^^^^^^^^^^^^^^^^^^^^^^ - -Python coding style is checked via ``flake8`` for automatic checking of PEP8 style during pull requests. - Endorsement ----------- Please do not take working with an organization (e.g., during a hackathon or via GitHub) as an endorsement of your work or your organization. It's okay to say e.g., “We worked with XXXXX to advance science” but not e.g., “XXXXX supports our work on HDMF”.” License and Copyright -======================= +--------------------- See the `license `_ files for details about the copyright and license. diff --git a/docs/source/_static/theme_overrides.css b/docs/source/_static/theme_overrides.css new file mode 100644 index 000000000..c20ed242f --- /dev/null +++ b/docs/source/_static/theme_overrides.css @@ -0,0 +1,7 @@ +.wy-side-nav-search .wy-dropdown>a.icon img.logo, .wy-side-nav-search>a.icon img.logo { + width: 150px; +} + +.wy-nav-content { + max-width: 1000px !important; +} diff --git a/docs/source/building_api.rst b/docs/source/building_api.rst index 3ad6041cb..a0105ec92 100644 --- a/docs/source/building_api.rst +++ b/docs/source/building_api.rst @@ -1,4 +1,4 @@ -Building API classes +Building API Classes ==================== After you have written an extension, you will need a Pythonic way to interact with the data model. To do this, diff --git a/docs/source/conf.py b/docs/source/conf.py index d9de691ed..b08c12574 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -175,7 +175,7 @@ # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -# html_static_path = ['_static'] +html_static_path = ['_static'] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. @@ -325,5 +325,5 @@ def skip(app, what, name, obj, skip, options): def setup(app): app.connect('builder-inited', run_apidoc) - app.add_css_file("theme_overrides.css") # overrides for wide tables in RTD theme + app.add_css_file("theme_overrides.css") app.connect("autodoc-skip-member", skip) diff --git a/docs/source/extensions.rst b/docs/source/extensions.rst index 9a8075060..0f5614744 100644 --- a/docs/source/extensions.rst +++ b/docs/source/extensions.rst @@ -1,6 +1,6 @@ .. _extending-standard: -Extending standards +Extending Standards =================== The following page will discuss how to extend a standard using HDMF. diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst deleted file mode 100644 index 2236b9cf1..000000000 --- a/docs/source/getting_started.rst +++ /dev/null @@ -1,129 +0,0 @@ -.. _getting_started: - ------------- -Dependencies ------------- - -HDMF has the following minimum requirements, which must be installed before you can get started using HDMF. - -#. Python 3.6, 3.7, or 3.8 -#. pip - ------------- -Installation ------------- - -Install release from PyPI -------------------------- - -The `Python Package Index (PyPI) `_ is a repository of software for the Python programming language. - -To install or update the HDMF distribution from PyPI, simply run: - -.. code:: - - $ pip install -U hdmf - -This will automatically install the following required dependencies: - - #. h5py - #. numpy - #. scipy - #. pandas - #. ruamel.yaml - -Install release from conda-forge --------------------------------- - -conda-forge_ is a community-led collection of recipes, build infrastructure, -and distributions for the conda_ package manager. - -.. _conda-forge: https://conda-forge.org/#about -.. _conda: https://conda.io/docs/ - -To install or update the HDMF distribution from conda-forge using conda, simply run: - -.. code:: - - $ conda install -c conda-forge hdmf - - -Install latest pre-release --------------------------- - -To try out the latest features and also set up continuous integration of your own project against the -latest version of HDMF, install the latest release from GitHub. - -.. code:: - - $ pip install -U hdmf --find-links https://github.com/hdmf-dev/hdmf/releases/tag/latest --no-index - - --------------- -For developers --------------- - -Install from Git repository ---------------------------- - -For development, an editable install in a virtual environment is recommended. First, create a new virtual environment -located at `~/hdmf` using the virtualenv_ tool. - -.. _virtualenv: https://virtualenv.pypa.io/en/stable/ - -.. code:: - - $ pip install -U virtualenv - $ virtualenv ~/hdmf - $ source ~/hdmf/bin/activate - -Alternatively, you can use the conda_ environment and package manager to create your virtual environment. This may -work better on Windows. - -.. code:: - - $ conda create --name hdmf-dev python=3.8 - $ conda activate hdmf-dev - -Then clone the git repository for HDMF, install the HDMF package requirements using the pip_ Python package manager, and -install HDMF. - -.. _pip: https://pip.pypa.io/en/stable/ - -.. code:: - - $ git clone --recurse-submodules git@github.com:hdmf-dev/hdmf.git - $ cd hdmf - $ pip install -r requirements.txt - $ pip install -e . - -Run tests ---------- - -For running the tests, it is required to install the development requirements. Within a virtual environment, run the -following code, which will clone the git repository for HDMF, install the HDMF package requirements using pip, -install HDMF, and run tests using the tox_ automated testing tool. - -.. _tox: https://tox.readthedocs.io/en/latest/ - -.. code:: - - $ cd hdmf - $ pip install -r requirements.txt -r requirements-dev.txt - $ pip install -e . - $ tox - - -Following the HDMF Style Guide ------------------------------- - -Before you create a Pull Request, make sure you are following the HDMF style guide (PEP8_). -To check whether your code conforms to the HDMF style guide, make sure you have the development requirements installed -(see above) and then simply run the flake8_ tool in the project's root directory. - -.. _flake8: http://flake8.pycqa.org/en/latest/ -.. _PEP8: https://www.python.org/dev/peps/pep-0008/ - -.. code:: - - $ flake8 diff --git a/docs/source/index.rst b/docs/source/index.rst index 251cf29ae..fb2b08c04 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -1,8 +1,3 @@ -.. HDMF documentation master file, created by - sphinx-quickstart on Thu Nov 17 10:41:07 2016. - You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. - The Hierarchical Data Modeling Framework ======================================== @@ -17,19 +12,21 @@ with the intention of providing it as an open-source tool for other scientific c If you use HDMF in your research, please use the following citation: -A. J. Tritt et al., "HDMF: Hierarchical Data Modeling Framework for Modern Science Data Standards," -2019 IEEE International Conference on Big Data (Big Data), Los Angeles, CA, USA, 2019, pp. 165-179, -doi: 10.1109/BigData47090.2019.9005648. + A. J. Tritt et al., "HDMF: Hierarchical Data Modeling Framework for Modern Science Data Standards," + 2019 IEEE International Conference on Big Data (Big Data), Los Angeles, CA, USA, 2019, pp. 165-179, + doi: 10.1109/BigData47090.2019.9005648. .. toctree:: + :hidden: :maxdepth: 2 :caption: Getting Started - getting_started - contributing + install_users + tutorials/index .. toctree:: + :hidden: :maxdepth: 2 :caption: Overview @@ -37,20 +34,29 @@ doi: 10.1109/BigData47090.2019.9005648. overview_software_architecture overview_citing + .. toctree:: + :hidden: :maxdepth: 2 :caption: Resources - tutorials/index + api_docs extensions building_api - validation export - api_docs - software_process + validation + +.. toctree:: + :hidden: + :caption: For Developers + + install_developers + contributing make_roundtrip_test + software_process .. toctree:: + :hidden: :maxdepth: 2 :caption: For Maintainers @@ -58,14 +64,8 @@ doi: 10.1109/BigData47090.2019.9005648. update_requirements .. toctree:: + :hidden: :maxdepth: 2 :caption: Legal legal - -Indices and tables -================== - -* :ref:`genindex` -* :ref:`modindex` -* :ref:`search` diff --git a/docs/source/install_developers.rst b/docs/source/install_developers.rst new file mode 100644 index 000000000..dacdb52d6 --- /dev/null +++ b/docs/source/install_developers.rst @@ -0,0 +1,146 @@ +.. _install_developers: + +------------------------------ +Installing HDMF for Developers +------------------------------ + +Set up a virtual environment +---------------------------- + +For development, we recommend installing HDMF in a virtual environment in editable mode. You can use +the virtualenv_ tool to create a new virtual environment. Or you can use the +`conda package and environment management system`_ for managing virtual environments. + +.. _virtualenv: https://virtualenv.pypa.io/en/stable/ +.. _conda package and environment management system: https://conda.io/projects/conda/en/latest/index.html + +Option 1: Using virtualenv +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +First, install the latest version of the ``virtualenv`` tool and use it to create a new virtual environment. This +virtual environment will be stored in the ``venv`` directory in the current directory. + +.. code:: bash + + pip install -U virtualenv + virtualenv venv + +On macOS or Linux, run the following to activate your new virtual environment: + +.. code:: bash + + source venv/bin/activate + +On Windows, run the following to activate your new virtual environment: + +.. code:: batch + + venv\Scripts\activate + +This virtual environment is a space where you can install Python packages that are isolated from other virtual +environments. This is especially useful when working on multiple Python projects that have different package +requirements and for testing Python code with different sets of installed packages or versions of Python. + +Activate your newly created virtual environment using the above command whenever you want to work on HDMF. You can also +deactivate it using the ``deactivate`` command to return to the base environment. + +Option 2: Using conda +^^^^^^^^^^^^^^^^^^^^^ + +First, install Anaconda_ to install the ``conda`` tool. Then create and +activate a new virtual environment called "venv" with Python 3.8 installed. + +.. code:: bash + + conda create --name venv python=3.8 + conda activate venv + +Similar to a virtual environment created with ``virtualenv``, a conda environment +is a space where you can install Python packages that are isolated from other virtual +environments. In general, you should use ``conda install`` instead of ``pip install`` to install packages +in a conda environment. + +Activate your newly created virtual environment using the above command whenever you want to work on HDMF. You can also +deactivate it using the ``conda deactivate`` command to return to the base environment. + +.. _Anaconda: https://www.anaconda.com/distribution + +Install from GitHub +------------------- + +After you have created and activated a virtual environment, clone the HDMF git repository from GitHub, install the +package requirements using the pip_ Python package manager, and install HDMF in editable mode. + +.. _pip: https://pip.pypa.io/en/stable/ + +.. code:: bash + + git clone --recurse-submodules https://github.com/hdmf-dev/hdmf.git + cd hdmf + pip install -r requirements.txt -r requirements-dev.txt -r requirements-doc.txt + pip install -e . + +.. note:: + + When using ``conda``, you may use ``pip install`` to install dependencies as shown above; however, it is generally + recommended that dependencies should be installed via ``conda install``, e.g., + + .. code:: bash + + conda install --file=requirements.txt --file=requirements-dev.txt --file=requirements-doc.txt + +Run tests +--------- + +You can run the full test suite with the following command: + +.. code:: bash + + python test.py + +You could also run the full test suite by installing and running the ``pytest`` tool, +a popular testing tool that provides more options for configuring test runs. + +First, install ``pytest``: + +.. code:: bash + + pip install pytest + +Then run the full test suite: + +.. code:: bash + + pytest + +You can also run a specific test module or class, or you can configure ``pytest`` to start the +Python debugger (PDB) prompt on an error, e.g., + +.. code:: bash + + pytest tests/unit/test_container.py # run all tests in the module + pytest tests/unit/test_container.py::TestContainer # run all tests in this class + pytest tests/unit/test_container.py::TestContainer::test_constructor # run this test method + pytest --pdb tests/unit/test_container.py # start pdb on error + + +Finally, you can run tests across multiple Python versions using the tox_ automated testing tool. Running ``tox`` will +create a virtual environment, install dependencies, and run the test suite for Python 3.6, 3.7, 3.8, and 3.9. +This can take some time to run. + +.. _pytest: https://docs.pytest.org/ +.. _tox: https://tox.readthedocs.io/en/latest/ + +.. code:: bash + + tox + +Install latest pre-release +-------------------------- + +To try out the latest features or set up continuous integration of your own project against the +latest version of HDMF, install the latest release from GitHub. + +.. code:: bash + + pip install -U hdmf --find-links https://github.com/hdmf-dev/hdmf/releases/tag/latest --no-index diff --git a/docs/source/install_users.rst b/docs/source/install_users.rst new file mode 100644 index 000000000..769c1e345 --- /dev/null +++ b/docs/source/install_users.rst @@ -0,0 +1,32 @@ +.. _install_users: + +--------------- +Installing HDMF +--------------- + +HDMF requires having Python 3.6, 3.7, or 3.8 installed. If you don't have Python installed and want the simplest way to +get started, we recommend you install and use the `Anaconda Distribution`_. It includes Python, NumPy, and many other +commonly used packages for scientific computing and data science. + +HDMF can be installed with ``pip``, ``conda``, or from source. HDMF works on Windows, macOS, and Linux. + +Option 1: Using pip +------------------- + +If you are a beginner to programming in Python and using Python tools, we recommend that you install HDMF by running +the following command in a terminal or command prompt: + +.. code:: + + pip install hdmf + +Option 2: Using conda +--------------------- + +You can also install HDMF using ``conda`` by running the following command in a terminal or command prompt: + +.. code:: + + conda install -c conda-forge hdmf + +.. _Anaconda Distribution: https://www.anaconda.com/distribution diff --git a/docs/source/validation.rst b/docs/source/validation.rst index cc5f47009..c4034b87b 100644 --- a/docs/source/validation.rst +++ b/docs/source/validation.rst @@ -1,21 +1,22 @@ .. _validating: -Validating HDMF data +Validating HDMF Data ==================== -Validation is of NWB files is available through :py:mod:`~pynwb`. See the `PyNWB documentation +Validation of NWB files is available through :py:mod:`~pynwb`. See the `PyNWB documentation `_ for more information. -------- .. note:: - + A simple interface for validating HDMF structured data through the command line like for PyNWB files is not yet implemented. If you would like this functionality to be available through :py:mod:`~hdmf`, then please upvote `this issue `_. .. - Validating HDMF structured data is is handled by a command-line tool available in :py:mod:`~hdmf`. The validator can be invoked like so: + Validating HDMF structured data is handled by a command-line tool available in :py:mod:`~hdmf`. + The validator can be invoked like so: .. code-block:: bash From 929ec93232bfa1069c764abc7b3b280ab0fc0c1e Mon Sep 17 00:00:00 2001 From: Ryan Ly Date: Wed, 16 Jun 2021 13:54:41 -0700 Subject: [PATCH 3/3] Fix incorrect dtype precision upgrade for VectorIndex (#631) --- CHANGELOG.md | 9 +++-- src/hdmf/common/table.py | 17 +++++---- tests/unit/common/test_table.py | 63 +++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 985a4edb0..940054e8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,14 +1,19 @@ # HDMF Changelog -## HDMF 2.5.8 (Upcoming) +## HDMF 2.5.8 (June 16, 2021) ### Minor improvements - Improve Sphinx documentation. @rly (#627) +### Bug fix +- Fix error with representing an indexed table column when the `VectorIndex` dtype precision is upgraded more + than one step, e.g., uint8 to uint32. This can happen when, for example, a single `add_row` call is used to + add more than 65535 elements to an empty indexed column. @rly (#631) + ## HDMF 2.5.7 (June 4, 2021) ### Bug fix -- Fix generation of extension classes that extend MultiContainerInterface and use a custom _fieldsname. @rly (#626) +- Fix generation of extension classes that extend `MultiContainerInterface` and use a custom _fieldsname. @rly (#626) ## HDMF 2.5.6 (May 19, 2021) diff --git a/src/hdmf/common/table.py b/src/hdmf/common/table.py index 39107e074..3199957e4 100644 --- a/src/hdmf/common/table.py +++ b/src/hdmf/common/table.py @@ -107,28 +107,33 @@ def add_vector(self, arg, **kwargs): def __check_precision(self, idx): """ - Check precision of current dataset and, if - necessary, adjust precision to accommodate new value. + Check precision of current dataset and, if necessary, adjust precision to accommodate new value. Returns: unsigned integer encoding of idx """ if idx > self.__maxval: - nbits = (np.log2(self.__maxval + 1) * 2) + while idx > self.__maxval: + nbits = (np.log2(self.__maxval + 1) * 2) # 8->16, 16->32, 32->64 + if nbits == 128: # pragma: no cover + msg = ('Cannot store more than 18446744073709551615 elements in a VectorData. Largest dtype ' + 'allowed for VectorIndex is uint64.') + raise ValueError(msg) + self.__maxval = 2 ** nbits - 1 self.__uint = np.dtype('uint%d' % nbits).type - self.__maxval = 2 ** nbits - 1 self.__adjust_precision(self.__uint) return self.__uint(idx) def __adjust_precision(self, uint): """ - Adjust precision of data to specificied unsigned integer precision + Adjust precision of data to specificied unsigned integer precision. """ if isinstance(self.data, list): for i in range(len(self.data)): self.data[i] = uint(self.data[i]) elif isinstance(self.data, np.ndarray): - self._VectorIndex__data = self.data.astype(uint) + # use self._Data__data to work around restriction on resetting self.data + self._Data__data = self.data.astype(uint) else: raise ValueError("cannot adjust precision of type %s to %s", (type(self.data), uint)) diff --git a/tests/unit/common/test_table.py b/tests/unit/common/test_table.py index 0508d837a..24d71eb96 100644 --- a/tests/unit/common/test_table.py +++ b/tests/unit/common/test_table.py @@ -1838,3 +1838,66 @@ def test_dtr_references(self): 'y': [read_group1, read_group2]}, index=pd.Index(data=[102, 103], name='id')) pd.testing.assert_frame_equal(ret, expected) + + +class TestVectorIndexDtype(TestCase): + + def set_up_array_index(self): + data = VectorData(name='data', description='desc') + index = VectorIndex(name='index', data=np.array([]), target=data) + return index + + def set_up_list_index(self): + data = VectorData(name='data', description='desc') + index = VectorIndex(name='index', data=[], target=data) + return index + + def test_array_inc_precision(self): + index = self.set_up_array_index() + index.add_vector(np.empty((255, ))) + self.assertEqual(index.data[0], 255) + self.assertEqual(index.data.dtype, np.uint8) + + def test_array_inc_precision_1step(self): + index = self.set_up_array_index() + index.add_vector(np.empty((65535, ))) + self.assertEqual(index.data[0], 65535) + self.assertEqual(index.data.dtype, np.uint16) + + def test_array_inc_precision_2steps(self): + index = self.set_up_array_index() + index.add_vector(np.empty((65536, ))) + self.assertEqual(index.data[0], 65536) + self.assertEqual(index.data.dtype, np.uint32) + + def test_array_prev_data_inc_precision_2steps(self): + index = self.set_up_array_index() + index.add_vector(np.empty((255, ))) # dtype is still uint8 + index.add_vector(np.empty((65536, ))) + self.assertEqual(index.data[0], 255) # make sure the 255 is upgraded + self.assertEqual(index.data.dtype, np.uint32) + + def test_list_inc_precision(self): + index = self.set_up_list_index() + index.add_vector(list(range(255))) + self.assertEqual(index.data[0], 255) + self.assertEqual(type(index.data[0]), np.uint8) + + def test_list_inc_precision_1step(self): + index = self.set_up_list_index() + index.add_vector(list(range(65535))) + self.assertEqual(index.data[0], 65535) + self.assertEqual(type(index.data[0]), np.uint16) + + def test_list_inc_precision_2steps(self): + index = self.set_up_list_index() + index.add_vector(list(range(65536))) + self.assertEqual(index.data[0], 65536) + self.assertEqual(type(index.data[0]), np.uint32) + + def test_list_prev_data_inc_precision_2steps(self): + index = self.set_up_list_index() + index.add_vector(list(range(255))) + index.add_vector(list(range(65536 - 255))) + self.assertEqual(index.data[0], 255) # make sure the 255 is upgraded + self.assertEqual(type(index.data[0]), np.uint32)