Skip to content

Commit a9839a1

Browse files
authored
Merge pull request #16 from rmnldwg/release-0.2.3
Release 0.2.3
2 parents 01cbcd5 + 0aca73e commit a9839a1

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

CHANGELOG.md

+19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [0.2.3] - 2024-12-05
6+
7+
### 🚀 Features
8+
9+
- Add `central` to shortname columns
10+
11+
### 🐛 Bug Fixes
12+
13+
- `&` and `|` with `None` return original `Q`. Previously, `Q(...) | None` would return a query that evaluated to `True` everywhere.
14+
15+
### 📚 Documentation
16+
17+
- List defined operators on `Q` (`&`, `|`, `~`, `==`) in the docstring of `CombineQMixin`.
18+
19+
### 🧪 Testing
20+
21+
- ensure that `&` and `|` with `None` return original `Q`.
22+
523
## [0.2.2] - 2024-12-03
624

725
### 🚀 Features
@@ -202,6 +220,7 @@ Initial implementation of the lyDATA library.
202220
<!-- generated by git-cliff -->
203221
<!-- markdownlint-disable-file MD024 -->
204222

223+
[0.2.3]: https://github.com/rmnldwg/lydata/compare/0.2.2..0.2.3
205224
[0.2.2]: https://github.com/rmnldwg/lydata/compare/0.2.1..0.2.2
206225
[0.2.1]: https://github.com/rmnldwg/lydata/compare/0.2.0..0.2.1
207226
[0.2.0]: https://github.com/rmnldwg/lydata/compare/0.1.2..0.2.0

lydata/accessor.py

+27-5
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,34 @@ def _get_all_true(df: pd.DataFrame) -> pd.Series:
5555

5656

5757
class CombineQMixin:
58-
"""Mixin class for combining queries."""
58+
"""Mixin class for combining queries.
59+
60+
Four operators are defined for combining queries:
61+
62+
1. ``&`` for logical AND operations.
63+
The returned object is an :py:class:`AndQ` instance and - when executed -
64+
returns a boolean mask where both queries are satisfied. When the right-hand
65+
side is ``None``, the left-hand side query object is returned unchanged.
66+
2. ``|`` for logical OR operations.
67+
The returned object is an :py:class:`OrQ` instance and - when executed -
68+
returns a boolean mask where either query is satisfied. When the right-hand
69+
side is ``None``, the left-hand side query object is returned unchanged.
70+
3. ``~`` for inverting a query.
71+
The returned object is a :py:class:`NotQ` instance and - when executed -
72+
returns a boolean mask where the query is not satisfied.
73+
4. ``==`` for checking if two queries are equal.
74+
Two queries are equal if their column names, operators, and values are equal.
75+
Note that this does not check if the queries are semantically equal, i.e., if
76+
they would return the same result when executed.
77+
"""
5978

6079
def __and__(self, other: QTypes | None) -> AndQ:
6180
"""Combine two queries with a logical AND."""
62-
other = other or NoneQ()
63-
return AndQ(self, other)
81+
return self if other is None else AndQ(self, other)
6482

6583
def __or__(self, other: QTypes | None) -> OrQ:
6684
"""Combine two queries with a logical OR."""
67-
other = other or NoneQ()
68-
return OrQ(self, other)
85+
return self if other is None else OrQ(self, other)
6986

7087
def __invert__(self) -> NotQ:
7188
"""Negate the query."""
@@ -166,6 +183,8 @@ class AndQ(CombineQMixin):
166183
1 True
167184
2 False
168185
dtype: bool
186+
>>> all((q1 & None).execute(df) == q1.execute(df))
187+
True
169188
"""
170189

171190
def __init__(self, q1: QTypes, q2: QTypes) -> None:
@@ -198,6 +217,8 @@ class OrQ(CombineQMixin):
198217
1 False
199218
2 True
200219
Name: col1, dtype: bool
220+
>>> all((q1 | None).execute(df) == q1.execute(df))
221+
True
201222
"""
202223

203224
def __init__(self, q1: QTypes, q2: QTypes) -> None:
@@ -257,6 +278,7 @@ def execute(self, df: pd.DataFrame) -> pd.Series:
257278

258279

259280
QTypes = Q | AndQ | OrQ | NotQ | None
281+
"""Type for a query object or a combination of query objects."""
260282

261283

262284
class C:

lydata/utils.py

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def get_default_column_map() -> _ColumnMap:
120120
_ColumnSpec("midext", ("tumor", "1", "extension")),
121121
_ColumnSpec("subsite", ("tumor", "1", "subsite")),
122122
_ColumnSpec("volume", ("tumor", "1", "volume")),
123+
_ColumnSpec("central", ("tumor", "1", "central")),
123124
]
124125
)
125126

0 commit comments

Comments
 (0)