eegdash 0.3.5.dev183002612__tar.gz → 0.3.6.dev97__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of eegdash might be problematic. Click here for more details.

Files changed (58) hide show
  1. {eegdash-0.3.5.dev183002612/eegdash.egg-info → eegdash-0.3.6.dev97}/PKG-INFO +2 -1
  2. eegdash-0.3.6.dev97/docs/source/dataset_summary.rst +201 -0
  3. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash/__init__.py +1 -1
  4. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash/api.py +137 -31
  5. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash/dataset.py +3 -1
  6. eegdash-0.3.6.dev97/eegdash/dataset_summary.csv +256 -0
  7. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash/registry.py +13 -3
  8. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97/eegdash.egg-info}/PKG-INFO +2 -1
  9. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash.egg-info/SOURCES.txt +1 -0
  10. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash.egg-info/requires.txt +1 -0
  11. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/pyproject.toml +1 -0
  12. eegdash-0.3.6.dev97/tests/test_challenge_kwargs.py +52 -0
  13. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/tests/test_dataset_registration.py +3 -3
  14. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/tests/test_init.py +1 -1
  15. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/tests/test_minirelease.py +3 -1
  16. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/tests/test_query.py +58 -0
  17. eegdash-0.3.5.dev183002612/docs/source/dataset_summary.rst +0 -85
  18. eegdash-0.3.5.dev183002612/eegdash/dataset_summary.csv +0 -255
  19. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/LICENSE +0 -0
  20. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/MANIFEST.in +0 -0
  21. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/README.md +0 -0
  22. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/docs/Makefile +0 -0
  23. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/docs/source/conf.py +0 -0
  24. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/docs/source/index.rst +0 -0
  25. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/docs/source/install/install.rst +0 -0
  26. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/docs/source/install/install_pip.rst +0 -0
  27. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/docs/source/install/install_source.rst +0 -0
  28. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/docs/source/overview.rst +0 -0
  29. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash/data_config.py +0 -0
  30. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash/data_utils.py +0 -0
  31. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash/features/__init__.py +0 -0
  32. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash/features/datasets.py +0 -0
  33. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash/features/decorators.py +0 -0
  34. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash/features/extractors.py +0 -0
  35. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash/features/feature_bank/__init__.py +0 -0
  36. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash/features/feature_bank/complexity.py +0 -0
  37. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash/features/feature_bank/connectivity.py +0 -0
  38. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash/features/feature_bank/csp.py +0 -0
  39. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash/features/feature_bank/dimensionality.py +0 -0
  40. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash/features/feature_bank/signal.py +0 -0
  41. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash/features/feature_bank/spectral.py +0 -0
  42. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash/features/feature_bank/utils.py +0 -0
  43. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash/features/inspect.py +0 -0
  44. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash/features/serialization.py +0 -0
  45. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash/features/utils.py +0 -0
  46. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash/mongodb.py +0 -0
  47. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash/preprocessing.py +0 -0
  48. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash/utils.py +0 -0
  49. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash.egg-info/dependency_links.txt +0 -0
  50. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/eegdash.egg-info/top_level.txt +0 -0
  51. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/setup.cfg +0 -0
  52. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/tests/test_api.py +0 -0
  53. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/tests/test_correctness.py +0 -0
  54. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/tests/test_dataset.py +0 -0
  55. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/tests/test_eegdash.py +0 -0
  56. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/tests/test_functional.py +0 -0
  57. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/tests/test_mongo_connection.py +0 -0
  58. {eegdash-0.3.5.dev183002612 → eegdash-0.3.6.dev97}/tests/test_offline.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: eegdash
3
- Version: 0.3.5.dev183002612
3
+ Version: 0.3.6.dev97
4
4
  Summary: EEG data for machine learning
5
5
  Author-email: Young Truong <dt.young112@gmail.com>, Arnaud Delorme <adelorme@gmail.com>, Aviv Dotan <avivd220@gmail.com>, Oren Shriki <oren70@gmail.com>, Bruno Aristimunha <b.aristimunha@gmail.com>
6
6
  License-Expression: GPL-3.0-only
@@ -59,6 +59,7 @@ Requires-Dist: numpydoc; extra == "docs"
59
59
  Requires-Dist: memory_profiler; extra == "docs"
60
60
  Requires-Dist: ipython; extra == "docs"
61
61
  Requires-Dist: lightgbm; extra == "docs"
62
+ Requires-Dist: plotly; extra == "docs"
62
63
  Provides-Extra: all
63
64
  Requires-Dist: eegdash[docs]; extra == "all"
64
65
  Requires-Dist: eegdash[dev]; extra == "all"
@@ -0,0 +1,201 @@
1
+ .. meta::
2
+ :hide_sidebar: true
3
+
4
+ :html_theme.sidebar_secondary.remove:
5
+ :html_theme.sidebar_primary.remove:
6
+
7
+ .. _data_summary:
8
+
9
+ EEGDash
10
+ ========
11
+
12
+ To leverage recent and ongoing advancements in large-scale computational methods and to ensure the preservation of scientific data generated from publicly funded research, the EEG-DaSh data archive will create a data-sharing resource for MEEG (EEG, MEG) data contributed by collaborators for machine learning (ML) and deep learning (DL) applications.
13
+
14
+ The archive is currently still in :bdg-danger:`beta testing` mode, so be kind.
15
+
16
+ .. raw:: html
17
+
18
+ <figure class="eegdash-figure" style="margin: 0 0 1.25rem 0;">
19
+
20
+ .. raw:: html
21
+ :file: ../build/dataset_bubble.html
22
+
23
+ .. raw:: html
24
+
25
+ <figcaption class="eegdash-caption">
26
+ Figure: Dataset landscape. Each bubble represents a dataset: x-axis shows the number of records,
27
+ y-axis the number of subjects, bubble area encodes on-disk size, and color indicates sampling frequency band.
28
+ Hover for details and use the legend to highlight groups.
29
+ </figcaption>
30
+ </figure>
31
+
32
+
33
+ .. raw:: html
34
+
35
+ <figure class="eegdash-figure" style="margin: 1.0rem 0 0 0;">
36
+
37
+
38
+ MEEG Datasets Table
39
+ ===================
40
+
41
+ The data in EEG-DaSh originates from a collaboration involving 25 laboratories, encompassing 27,053 participants. This extensive collection includes MEEG data, which is a combination of EEG and MEG signals. The data is sourced from various studies conducted by these labs,
42
+ involving both healthy subjects and clinical populations with conditions such as ADHD, depression, schizophrenia, dementia, autism, and psychosis. Additionally, data spans different mental states like sleep, meditation, and cognitive tasks.
43
+
44
+ In addition, EEG-DaSh will incorporate a subset of the data converted from `NEMAR <https://nemar.org/>`__, which includes 330 MEEG BIDS-formatted datasets, further expanding the archive with well-curated, standardized neuroelectromagnetic data.
45
+
46
+ .. raw:: html
47
+ :file: ../build/dataset_summary_table.html
48
+
49
+ .. raw:: html
50
+
51
+ <figcaption class="eegdash-caption">
52
+ Table: Sortable catalogue of EEG‑DaSh datasets. Use the “Filters” button to open column filters;
53
+ click a column header to jump directly to a filter pane. The Total row is pinned at the bottom.
54
+ * means that we use the median value across multiple recordings in the dataset, and empty cells
55
+ when the metainformation is not extracted yet.
56
+ </figcaption>
57
+ </figure>
58
+
59
+ .. raw:: html
60
+
61
+ <!-- jQuery + DataTables core -->
62
+ <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
63
+ <link rel="stylesheet" href="https://cdn.datatables.net/v/bm/dt-1.13.4/datatables.min.css"/>
64
+ <script src="https://cdn.datatables.net/v/bm/dt-1.13.4/datatables.min.js"></script>
65
+
66
+ <!-- Buttons + SearchPanes (+ Select required by SearchPanes) -->
67
+ <link rel="stylesheet" href="https://cdn.datatables.net/buttons/2.4.2/css/buttons.dataTables.min.css">
68
+ <script src="https://cdn.datatables.net/buttons/2.4.2/js/dataTables.buttons.min.js"></script>
69
+ <link rel="stylesheet" href="https://cdn.datatables.net/select/1.7.0/css/select.dataTables.min.css">
70
+ <link rel="stylesheet" href="https://cdn.datatables.net/searchpanes/2.3.1/css/searchPanes.dataTables.min.css">
71
+ <script src="https://cdn.datatables.net/select/1.7.0/js/dataTables.select.min.js"></script>
72
+ <script src="https://cdn.datatables.net/searchpanes/2.3.1/js/dataTables.searchPanes.min.js"></script>
73
+
74
+ <style>
75
+ /* Styling for the Total row (placed in tfoot) */
76
+ table.sd-table tfoot td {
77
+ font-weight: 600;
78
+ border-top: 2px solid rgba(0,0,0,0.2);
79
+ background: #f9fafb;
80
+ /* Match body cell padding to keep perfect alignment */
81
+ padding: 8px 10px !important;
82
+ vertical-align: middle;
83
+ }
84
+
85
+ /* Right-align numeric-like columns (2..8) consistently for body & footer */
86
+ table.sd-table tbody td:nth-child(n+2),
87
+ table.sd-table tfoot td:nth-child(n+2) {
88
+ text-align: right;
89
+ }
90
+ /* Keep first column (Dataset/Total) left-aligned */
91
+ table.sd-table tbody td:first-child,
92
+ table.sd-table tfoot td:first-child {
93
+ text-align: left;
94
+ }
95
+ </style>
96
+
97
+ <script>
98
+ // Helper: robustly extract values for SearchPanes when needed
99
+ function tagsArrayFromHtml(html) {
100
+ if (html == null) return [];
101
+ // If it's numeric or plain text, just return as a single value
102
+ if (typeof html === 'number') return [String(html)];
103
+ if (typeof html === 'string' && html.indexOf('<') === -1) return [html.trim()];
104
+ // Else parse any .tag elements inside HTML
105
+ var tmp = document.createElement('div');
106
+ tmp.innerHTML = html;
107
+ var tags = Array.from(tmp.querySelectorAll('.tag')).map(function(el){
108
+ return (el.textContent || '').trim();
109
+ });
110
+ return tags.length ? tags : [tmp.textContent.trim()];
111
+ }
112
+
113
+ // Helper: parse human-readable sizes like "4.31 GB" into bytes (number)
114
+ function parseSizeToBytes(text) {
115
+ if (!text) return 0;
116
+ var s = String(text).trim();
117
+ var m = s.match(/([\d,.]+)\s*(TB|GB|MB|KB|B)/i);
118
+ if (!m) return 0;
119
+ var value = parseFloat(m[1].replace(/,/g, ''));
120
+ var unit = m[2].toUpperCase();
121
+ var factor = { B:1, KB:1024, MB:1024**2, GB:1024**3, TB:1024**4 }[unit] || 1;
122
+ return value * factor;
123
+ }
124
+
125
+ $(function () {
126
+ // 1) Move the "Total" row into <tfoot> so sorting/filtering never moves it
127
+ $('.sortable').each(function(){
128
+ var $t = $(this);
129
+ var $tbody = $t.find('tbody');
130
+ var $total = $tbody.find('tr').filter(function(){
131
+ return $(this).find('td').eq(0).text().trim() === 'Total';
132
+ });
133
+ if ($total.length) {
134
+ var $tfoot = $t.find('tfoot');
135
+ if (!$tfoot.length) $tfoot = $('<tfoot/>').appendTo($t);
136
+ $total.appendTo($tfoot);
137
+ }
138
+ });
139
+
140
+ // 2) Initialize DataTable with SearchPanes button
141
+ var FILTER_COLS = [1,2,3,4,5,6];
142
+ // Detect the index of the size column by header text
143
+ var sizeIdx = (function(){
144
+ var idx = -1;
145
+ $('.sortable thead th').each(function(i){
146
+ var t = $(this).text().trim().toLowerCase();
147
+ if (t === 'size on disk' || t === 'size') idx = i;
148
+ });
149
+ return idx;
150
+ })();
151
+
152
+ var table = $('.sortable').DataTable({
153
+ dom: 'Blfrtip',
154
+ paging: false,
155
+ searching: true,
156
+ info: false,
157
+ language: {
158
+ search: 'Filter dataset:',
159
+ searchPanes: { collapse: { 0: 'Filters', _: 'Filters (%d)' } }
160
+ },
161
+ buttons: [{
162
+ extend: 'searchPanes',
163
+ text: 'Filters',
164
+ config: { cascadePanes: true, viewTotal: true, layout: 'columns-4', initCollapsed: false }
165
+ }],
166
+ columnDefs: (function(){
167
+ var defs = [
168
+ { searchPanes: { show: true }, targets: FILTER_COLS }
169
+ ];
170
+ if (sizeIdx !== -1) {
171
+ defs.push({
172
+ targets: sizeIdx,
173
+ render: function(data, type) {
174
+ if (type === 'sort' || type === 'type') {
175
+ return parseSizeToBytes(data);
176
+ }
177
+ return data;
178
+ }
179
+ });
180
+ }
181
+ return defs;
182
+ })()
183
+ });
184
+
185
+ // 3) UX: click a header to open the relevant filter pane
186
+ $('.sortable thead th').each(function (i) {
187
+ if ([1,2,3,4].indexOf(i) === -1) return;
188
+ $(this).css('cursor','pointer').attr('title','Click to filter this column');
189
+ $(this).on('click', function () {
190
+ table.button('.buttons-searchPanes').trigger();
191
+ setTimeout(function () {
192
+ var idx = [1,2,3,4].indexOf(i);
193
+ var $container = $(table.searchPanes.container());
194
+ var $pane = $container.find('.dtsp-pane').eq(idx);
195
+ var $title = $pane.find('.dtsp-title');
196
+ if ($title.length) $title.trigger('click');
197
+ }, 0);
198
+ });
199
+ });
200
+ });
201
+ </script>
@@ -7,4 +7,4 @@ __init__mongo_client()
7
7
 
8
8
  __all__ = ["EEGDash", "EEGDashDataset", "EEGChallengeDataset"]
9
9
 
10
- __version__ = "0.3.5.dev183002612"
10
+ __version__ = "0.3.6.dev97"
@@ -90,12 +90,16 @@ class EEGDash:
90
90
  ) -> list[Mapping[str, Any]]:
91
91
  """Find records in the MongoDB collection.
92
92
 
93
- This method can be called in two ways:
93
+ This method supports four usage patterns:
94
94
  1. With a pre-built MongoDB query dictionary (positional argument):
95
95
  >>> eegdash.find({"dataset": "ds002718", "subject": {"$in": ["012", "013"]}})
96
96
  2. With user-friendly keyword arguments for simple and multi-value queries:
97
97
  >>> eegdash.find(dataset="ds002718", subject="012")
98
98
  >>> eegdash.find(dataset="ds002718", subject=["012", "013"])
99
+ 3. With an explicit empty query to return all documents:
100
+ >>> eegdash.find({}) # fetches all records (use with care)
101
+ 4. By combining a raw query with kwargs (merged via logical AND):
102
+ >>> eegdash.find({"dataset": "ds002718"}, subject=["012", "013"]) # yields {"$and":[{"dataset":"ds002718"}, {"subject":{"$in":["012","013"]}}]}
99
103
 
100
104
  Parameters
101
105
  ----------
@@ -110,26 +114,34 @@ class EEGDash:
110
114
  list:
111
115
  A list of DB records (string-keyed dictionaries) that match the query.
112
116
 
113
- Raises
114
- ------
115
- ValueError
116
- If both a `query` dictionary and keyword arguments are provided.
117
-
118
117
  """
119
- if query is not None and kwargs:
120
- raise ValueError(
121
- "Provide either a positional 'query' dictionary or keyword arguments, not both."
122
- )
123
-
124
- final_query = {}
125
- if query is not None:
126
- final_query = query
127
- elif kwargs:
128
- final_query = self._build_query_from_kwargs(**kwargs)
118
+ final_query: dict[str, Any] | None = None
119
+
120
+ # Accept explicit empty dict {} to mean "match all"
121
+ raw_query = query if isinstance(query, dict) else None
122
+ kwargs_query = self._build_query_from_kwargs(**kwargs) if kwargs else None
123
+
124
+ # Determine presence, treating {} as a valid raw query
125
+ has_raw = isinstance(raw_query, dict)
126
+ has_kwargs = kwargs_query is not None
127
+
128
+ if has_raw and has_kwargs:
129
+ # Detect conflicting constraints on the same field (e.g., task specified
130
+ # differently in both places) and raise a clear error instead of silently
131
+ # producing an empty result.
132
+ self._raise_if_conflicting_constraints(raw_query, kwargs_query)
133
+ # Merge with logical AND so both constraints apply
134
+ if raw_query: # non-empty dict adds constraints
135
+ final_query = {"$and": [raw_query, kwargs_query]}
136
+ else: # {} adds nothing; use kwargs_query only
137
+ final_query = kwargs_query
138
+ elif has_raw:
139
+ # May be {} meaning match-all, or a non-empty dict
140
+ final_query = raw_query
141
+ elif has_kwargs:
142
+ final_query = kwargs_query
129
143
  else:
130
- # By default, an empty query {} returns all documents.
131
- # This can be dangerous, so we can either allow it or raise an error.
132
- # Let's require an explicit query for safety.
144
+ # Avoid accidental full scans
133
145
  raise ValueError(
134
146
  "find() requires a query dictionary or at least one keyword argument. "
135
147
  "To find all documents, use find({})."
@@ -224,9 +236,12 @@ class EEGDash:
224
236
  return record
225
237
 
226
238
  def _build_query_from_kwargs(self, **kwargs) -> dict[str, Any]:
227
- """Builds and validates a MongoDB query from user-friendly keyword arguments.
239
+ """Build and validate a MongoDB query from user-friendly keyword arguments.
228
240
 
229
- Translates list values into MongoDB's `$in` operator.
241
+ Improvements:
242
+ - Reject None values and empty/whitespace-only strings
243
+ - For list/tuple/set values: strip strings, drop None/empties, deduplicate, and use `$in`
244
+ - Preserve scalars as exact matches
230
245
  """
231
246
  # 1. Validate that all provided keys are allowed for querying
232
247
  unknown_fields = set(kwargs.keys()) - self._ALLOWED_QUERY_FIELDS
@@ -239,19 +254,108 @@ class EEGDash:
239
254
  # 2. Construct the query dictionary
240
255
  query = {}
241
256
  for key, value in kwargs.items():
242
- if isinstance(value, (list, tuple)):
243
- if not value:
257
+ # None is not a valid constraint
258
+ if value is None:
259
+ raise ValueError(
260
+ f"Received None for query parameter '{key}'. Provide a concrete value."
261
+ )
262
+
263
+ # Handle list-like values as multi-constraints
264
+ if isinstance(value, (list, tuple, set)):
265
+ cleaned: list[Any] = []
266
+ for item in value:
267
+ if item is None:
268
+ continue
269
+ if isinstance(item, str):
270
+ item = item.strip()
271
+ if not item:
272
+ continue
273
+ cleaned.append(item)
274
+ # Deduplicate while preserving order
275
+ cleaned = list(dict.fromkeys(cleaned))
276
+ if not cleaned:
244
277
  raise ValueError(
245
278
  f"Received an empty list for query parameter '{key}'. This is not supported."
246
279
  )
247
- # If the value is a list, use the `$in` operator for multi-search
248
- query[key] = {"$in": value}
280
+ query[key] = {"$in": cleaned}
249
281
  else:
250
- # Otherwise, it's a direct match
282
+ # Scalars: trim strings and validate
283
+ if isinstance(value, str):
284
+ value = value.strip()
285
+ if not value:
286
+ raise ValueError(
287
+ f"Received an empty string for query parameter '{key}'."
288
+ )
251
289
  query[key] = value
252
290
 
253
291
  return query
254
292
 
293
+ # --- Query merging and conflict detection helpers ---
294
+ def _extract_simple_constraint(self, query: dict[str, Any], key: str):
295
+ """Extract a simple constraint for a given key from a query dict.
296
+
297
+ Supports only top-level equality (key: value) and $in (key: {"$in": [...]})
298
+ constraints. Returns a tuple (kind, value) where kind is "eq" or "in". If the
299
+ key is not present or uses other operators, returns None.
300
+ """
301
+ if not isinstance(query, dict) or key not in query:
302
+ return None
303
+ val = query[key]
304
+ if isinstance(val, dict):
305
+ if "$in" in val and isinstance(val["$in"], (list, tuple)):
306
+ return ("in", list(val["$in"]))
307
+ return None # unsupported operator shape for conflict checking
308
+ else:
309
+ return ("eq", val)
310
+
311
+ def _raise_if_conflicting_constraints(
312
+ self, raw_query: dict[str, Any], kwargs_query: dict[str, Any]
313
+ ) -> None:
314
+ """Raise ValueError if both query sources define incompatible constraints.
315
+
316
+ We conservatively check only top-level fields with simple equality or $in
317
+ constraints. If a field appears in both queries and constraints are mutually
318
+ exclusive, raise an explicit error to avoid silent empty result sets.
319
+ """
320
+ if not raw_query or not kwargs_query:
321
+ return
322
+
323
+ # Only consider fields we generally allow; skip meta operators like $and
324
+ raw_keys = set(raw_query.keys()) & self._ALLOWED_QUERY_FIELDS
325
+ kw_keys = set(kwargs_query.keys()) & self._ALLOWED_QUERY_FIELDS
326
+ dup_keys = raw_keys & kw_keys
327
+ for key in dup_keys:
328
+ rc = self._extract_simple_constraint(raw_query, key)
329
+ kc = self._extract_simple_constraint(kwargs_query, key)
330
+ if rc is None or kc is None:
331
+ # If either side is non-simple, skip conflict detection for this key
332
+ continue
333
+
334
+ r_kind, r_val = rc
335
+ k_kind, k_val = kc
336
+
337
+ # Normalize to sets when appropriate for simpler checks
338
+ if r_kind == "eq" and k_kind == "eq":
339
+ if r_val != k_val:
340
+ raise ValueError(
341
+ f"Conflicting constraints for '{key}': query={r_val!r} vs kwargs={k_val!r}"
342
+ )
343
+ elif r_kind == "in" and k_kind == "eq":
344
+ if k_val not in r_val:
345
+ raise ValueError(
346
+ f"Conflicting constraints for '{key}': query in {r_val!r} vs kwargs={k_val!r}"
347
+ )
348
+ elif r_kind == "eq" and k_kind == "in":
349
+ if r_val not in k_val:
350
+ raise ValueError(
351
+ f"Conflicting constraints for '{key}': query={r_val!r} vs kwargs in {k_val!r}"
352
+ )
353
+ elif r_kind == "in" and k_kind == "in":
354
+ if len(set(r_val).intersection(k_val)) == 0:
355
+ raise ValueError(
356
+ f"Conflicting constraints for '{key}': disjoint sets {r_val!r} and {k_val!r}"
357
+ )
358
+
255
359
  def load_eeg_data_from_s3(self, s3path: str) -> xr.DataArray:
256
360
  """Load an EEGLAB .set file from an AWS S3 URI and return it as an xarray DataArray.
257
361
 
@@ -676,10 +780,8 @@ class EEGDashDataset(BaseConcatDataset):
676
780
  # If list is provided, let _build_query_from_kwargs turn it into $in later.
677
781
  query_kwargs.setdefault("dataset", dataset)
678
782
 
679
- if query and query_kwargs:
680
- raise ValueError(
681
- "Provide either a 'query' dictionary or keyword arguments for filtering, not both."
682
- )
783
+ # Allow mixing raw DB query with additional keyword filters. Both will be
784
+ # merged by EEGDash.find() (logical AND), so we do not raise here.
683
785
 
684
786
  try:
685
787
  if records is not None:
@@ -723,7 +825,7 @@ class EEGDashDataset(BaseConcatDataset):
723
825
  **base_dataset_kwargs,
724
826
  )
725
827
  )
726
- elif query or query_kwargs:
828
+ elif query is not None or query_kwargs:
727
829
  # This is the DB query path that we are improving
728
830
  datasets = self.find_datasets(
729
831
  query=query,
@@ -786,6 +888,10 @@ class EEGDashDataset(BaseConcatDataset):
786
888
  """
787
889
  datasets: list[EEGDashBaseDataset] = []
788
890
 
891
+ # Build records using either a raw query OR keyword filters, but not both.
892
+ # Note: callers may accidentally pass an empty dict for `query` along with
893
+ # kwargs. In that case, treat it as if no query was provided and rely on kwargs.
894
+ # Always delegate merging of raw query + kwargs to EEGDash.find
789
895
  self.records = self.eeg_dash.find(query, **query_kwargs)
790
896
 
791
897
  for record in self.records:
@@ -321,7 +321,9 @@ class EEGChallengeDataset(EEGDashDataset):
321
321
  )
322
322
 
323
323
  if self.mini:
324
- if query and "subject" in query:
324
+ # Disallow mixing subject selection with mini=True since mini already
325
+ # applies a predefined subject subset.
326
+ if (query and "subject" in query) or ("subject" in kwargs):
325
327
  raise ValueError(
326
328
  "Query using the parameters `subject` with the class EEGChallengeDataset and `mini==True` is not possible."
327
329
  "Please don't use the `subject` selection twice."