Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dimension links #469

Merged
merged 29 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
75f98c7
Code quality: Variable renames
achilleas-k Jun 26, 2020
6a083f8
New DimensionLink class
achilleas-k Jun 26, 2020
08f38ef
Allow creating range dimensions without ticks
achilleas-k Jul 14, 2020
ac55340
[LinkDimension] value and unit getters
achilleas-k Jul 14, 2020
d61dbc0
Base Dimension methods for accessing linked data
achilleas-k Jul 14, 2020
4f7bf55
Disable linking for SampledDimension
achilleas-k Jul 14, 2020
3f683e7
[DimensionLink] Delete old link before creating new
achilleas-k Jul 14, 2020
de4f455
Use get_by_name for opening subgroups
achilleas-k Jul 14, 2020
f39082c
RangeDimension.ticks: Read through to linked data
achilleas-k Jul 14, 2020
f21ab60
TestLinkDimension: RangeDimension->DA link tests
achilleas-k Jul 14, 2020
c53255f
Multidimensional indexing should use a tuple
achilleas-k Jul 15, 2020
f06e8d9
SetDimension.labels: Read through to linked data
achilleas-k Jul 15, 2020
a006340
TestLinkDimension: SetDimension->DA link tests
achilleas-k Jul 15, 2020
c73bb77
TestLinkDimension: Self link tests
achilleas-k Jul 15, 2020
b59c7ac
DimensionLink to DataFrame: Apply index to column
achilleas-k Jul 15, 2020
86b807f
Remove unnecessary SampledDimension redirect
achilleas-k Jul 15, 2020
a5d7be4
RangeDimension.unit: Read through to linked unit
achilleas-k Jul 15, 2020
55a28c6
RangeDimension.label: Read through to linked label
achilleas-k Jul 15, 2020
8c8f1c0
TestLinkDimension: DataFrame for Range and Set dimensions
achilleas-k Jul 15, 2020
44f005b
Remove AliasRangeDimension and DataFrameDimension
achilleas-k Jul 15, 2020
3a88408
Index validation for DataFrame dimension link
achilleas-k Jul 15, 2020
e3a0330
Index validation for DataArray dimension link
achilleas-k Jul 15, 2020
2fd8031
Test dimension link index errors
achilleas-k Jul 15, 2020
47cb753
TestLinkDimension: Remove unnecessary np.app() checks
achilleas-k Jul 16, 2020
ecc25cd
DimensionLink: Write through label and unit
achilleas-k Jul 16, 2020
c01021c
TestLinkDimension: Property change tests
achilleas-k Jul 16, 2020
86bdee5
Code quality: Remove all unused imports and variables
achilleas-k Jul 19, 2020
04063e7
Code quality: Remove unnecessary for loop
achilleas-k Jul 19, 2020
0ab71e7
[travis] Extra build without compat tests
achilleas-k Jul 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ matrix:
env: pymajor=3 coverage=1
dist: xenial
sudo: true
- python: "3.7"
os: linux
env: pymajor=3 nocompat=1
dist: xenial
- language: generic
os: osx
env: pymajor=2
Expand Down Expand Up @@ -56,25 +60,28 @@ addons:
- libboost-all-dev

before_install:
- nixprefix="/usr/local"
- export NIX_INCDIR=${nixprefix}/include/nixio-1.0
- export NIX_LIBDIR=${nixprefix}/lib
- export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:${nixprefix}/lib/pkgconfig
# build nix for compat tests
- if [[ -z "${nocompat}" ]]; then
nixprefix="/usr/local";
export NIX_INCDIR=${nixprefix}/include/nixio-1.0;
export NIX_LIBDIR=${nixprefix}/lib;
export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:${nixprefix}/lib/pkgconfig;
git clone --branch ${NIX_BRANCH} https://github.com/G-Node/nix /tmp/libnix;
pushd /tmp/libnix;
mkdir build;
pushd build;
cmake -DCMAKE_INSTALL_PREFIX=${nixprefix} ..;
make;
sudo make install;
popd;
popd;
fi
# For macOS python3
- export PATH="/usr/local/opt/python@3.8/bin:$PATH"
- alias pip2='pip'
- if [[ "${TRAVIS_OS_NAME}" != "osx" ]]; then pip${pymajor} install --upgrade numpy; fi
- pip${pymajor} install --upgrade h5py pytest pytest-xdist pytest-cov six;
- if [[ "${pymajor}" == 2 ]]; then pip${pymajor} install enum34; fi
- git clone --branch ${NIX_BRANCH} https://github.com/G-Node/nix /tmp/libnix
- pushd /tmp/libnix
- mkdir build
- pushd build
- cmake -DCMAKE_INSTALL_PREFIX=${nixprefix} ..
- make
- sudo make install
- popd
- popd
- which pip${pymajor}
- which python${pymajor}
- python${pymajor} --version
Expand All @@ -83,7 +90,11 @@ install:
- python${pymajor} setup.py build

script:
- pytest --cov=nixio --nix-compat -nauto;
- if [[ "${nocompat}" == 1 ]]; then
pytest --cov=nixio -nauto;
else
pytest --cov=nixio --nix-compat -nauto;
fi

after_success:
- if [[ "${coverage}" == 1 ]]; then
Expand Down
9 changes: 4 additions & 5 deletions nixio/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,10 @@ def create_data_frame(self, name="", type_="", col_dict=None,
else: # if col_names is None
if data is not None and type(data[0]) == np.void:
col_dtype = data[0].dtype
for i, dt in enumerate(col_dtype.fields.values()):
cn = list(col_dtype.fields.keys())
raw_dt = col_dtype.fields.values()
raw_dt = list(raw_dt)
raw_dt_list = [ele[0] for ele in raw_dt]
cn = list(col_dtype.fields.keys())
raw_dt = col_dtype.fields.values()
raw_dt = list(raw_dt)
raw_dt_list = [ele[0] for ele in raw_dt]
col_dict = OrderedDict(zip(cn, raw_dt_list))
if len(col_dtype.fields.values()) != len(col_dict):
raise exceptions.DuplicateColumnName
Expand Down
71 changes: 3 additions & 68 deletions nixio/data_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
from .source_link_container import SourceLinkContainer
from .datatype import DataType
from .dimensions import (Dimension, SampledDimension, RangeDimension,
SetDimension, DataFrameDimension,
DimensionType, DimensionContainer)
SetDimension, DimensionType, DimensionContainer)
from . import util
from .compression import Compression

from .exceptions import InvalidUnit, IncompatibleDimensions
from .exceptions import IncompatibleDimensions
from .section import Section


Expand Down Expand Up @@ -118,7 +117,7 @@ def append_sampled_dimension(self, sampling_interval, label=None,
self.force_updated_at()
return smpldim

def append_range_dimension(self, ticks, label=None, unit=None):
def append_range_dimension(self, ticks=None, label=None, unit=None):
"""
Append a new RangeDimension to the list of existing dimension
descriptors.
Expand All @@ -138,61 +137,6 @@ def append_range_dimension(self, ticks, label=None, unit=None):
self.force_updated_at()
return rdim

def append_data_frame_dimension(self, data_frame, column_idx=None):
"""
Append a new DataFrameDimension to the list of existing dimension
descriptors.

:param data_frame: The referenced DataFrame
:type data_frame: nix.DataFrame

:param column_idx: Index of the referenced column of the DataFrame.
The default column determines the default label,
ticks, and unit of this Dimension.
:type column_idx: int or None

:returns: Thew newly created DataFrameDimension.
:rtype: DataFrameDimension
"""
index = len(self.dimensions) + 1
dfdim = DataFrameDimension.create_new(self, index,
data_frame, column_idx)
if self.file.auto_update_timestamps:
self.force_updated_at()
return dfdim

def append_alias_range_dimension(self):
"""
Append a new RangeDimension that uses the data stored in this
DataArray as ticks. This works only(!) if the DataArray is 1-D and
the stored data is numeric. A ValueError will be raised otherwise.

:returns: The created dimension descriptor.
:rtype: RangeDimension

"""
if (len(self.data_extent) > 1 or
not DataType.is_numeric_dtype(self.dtype)):
raise ValueError("AliasRangeDimensions only allowed for 1D "
"numeric DataArrays.")
if self._dimension_count() > 0:
raise ValueError("Cannot append additional alias dimension. "
"There must only be one!")
# check if existing unit is SI
if self.unit:
u = self.unit
if not (util.units.is_si(u) or util.units.is_compound(u)):
raise InvalidUnit(
"AliasRangeDimensions are only allowed when SI or "
"composites of SI units are used. "
"Current SI unit is {}".format(u),
"DataArray.append_alias_range_dimension"
)
aliasdim = RangeDimension.create_new_alias(self, 1)
if self.file.auto_update_timestamps:
self.force_updated_at()
return aliasdim

def delete_dimensions(self):
"""
Delete all the dimension descriptors for this DataArray.
Expand Down Expand Up @@ -311,15 +255,6 @@ def unit(self, u):
if u == "":
u = None
util.check_attr_type(u, str)
if (self._dimension_count() == 1 and
self.dimensions[0].dimension_type == DimensionType.Range and
self.dimensions[0].is_alias and u is not None):
if not (util.units.is_si(u) or util.units.is_compound(u)):
raise InvalidUnit(
"[{}]: Non-SI units are not allowed if the DataArray "
"has an AliasRangeDimension.".format(u),
"DataArray.unit"
)
self._h5group.set_attr("unit", u)
if self.file.auto_update_timestamps:
self.force_updated_at()
Expand Down
2 changes: 1 addition & 1 deletion nixio/data_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def write_rows(self, rows, index):
self._write_data(rows, sl=index)
else:
cr_list = []
for i, cr in enumerate(rows):
for cr in rows:
cr_list.append(tuple(cr))
self._write_data(cr_list, sl=index)

Expand Down
Loading