|
1 | 1 | """Private functions to handle tabular data.""" |
2 | | -import numpy as np |
3 | 2 | from collections import OrderedDict |
4 | 3 | from copy import deepcopy |
5 | 4 |
|
| 5 | +from mne.utils import warn |
| 6 | +import numpy as np |
| 7 | + |
6 | 8 |
|
7 | 9 | def _combine_rows(data1, data2, drop_column=None): |
8 | 10 | """Add two OrderedDict's together and optionally drop repeated data. |
@@ -109,7 +111,10 @@ def _drop(data, values, column): |
109 | 111 | # Cast `values` to the same dtype as `new_data_col` to avoid a NumPy |
110 | 112 | # FutureWarning, see |
111 | 113 | # https://github.com/mne-tools/mne-bids/pull/372 |
112 | | - values = np.array(values, dtype=new_data_col.dtype) |
| 114 | + dtype = new_data_col.dtype |
| 115 | + if new_data_col.shape == (0,): |
| 116 | + dtype = np.array(values).dtype |
| 117 | + values = np.array(values, dtype=dtype) |
113 | 118 |
|
114 | 119 | mask = np.in1d(new_data_col, values, invert=True) |
115 | 120 | for key in new_data.keys(): |
@@ -147,8 +152,16 @@ def _from_tsv(fname, dtypes=None): |
147 | 152 | if not len(dtypes) == info.shape[1]: |
148 | 153 | raise ValueError('dtypes length mismatch. Provided: {0}, ' |
149 | 154 | 'Expected: {1}'.format(len(dtypes), info.shape[1])) |
| 155 | + empty_cols = 0 |
150 | 156 | for i, name in enumerate(column_names): |
151 | | - data_dict[name] = info[:, i].astype(dtypes[i]).tolist() |
| 157 | + values = info[:, i].astype(dtypes[i]).tolist() |
| 158 | + data_dict[name] = values |
| 159 | + if len(values) == 0: |
| 160 | + empty_cols += 1 |
| 161 | + |
| 162 | + if empty_cols == len(column_names): |
| 163 | + warn(f"TSV file is empty: '{fname}'") |
| 164 | + |
152 | 165 | return data_dict |
153 | 166 |
|
154 | 167 |
|
|
0 commit comments