sercol 1.2.2__tar.gz → 1.2.4__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.
@@ -1,10 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sercol
3
- Version: 1.2.2
3
+ Version: 1.2.4
4
4
  Summary: Rich collection class with grouping and filtering helpers
5
5
  Author-email: Alex Rubinsteyn <alex.rubinsteyn@unc.edu>
6
6
  License-Expression: Apache-2.0
7
7
  Project-URL: Homepage, https://github.com/openvax/sercol
8
+ Project-URL: Documentation, https://openvax.github.io/sercol/
8
9
  Project-URL: Bug Tracker, https://github.com/openvax/sercol/issues
9
10
  Classifier: Development Status :: 4 - Beta
10
11
  Classifier: Environment :: Console
@@ -34,6 +34,7 @@ packages = ["sercol"]
34
34
 
35
35
  [project.urls]
36
36
  "Homepage" = "https://github.com/openvax/sercol"
37
+ "Documentation" = "https://openvax.github.io/sercol/"
37
38
  "Bug Tracker" = "https://github.com/openvax/sercol/issues"
38
39
 
39
40
  [tool.ruff]
@@ -41,8 +42,25 @@ target-version = "py311"
41
42
 
42
43
  [tool.ruff.lint]
43
44
  select = ["E", "F"]
44
- ignore = ["F821", "E501", "F841", "E731", "E741", "E722", "E721"]
45
+ ignore = ["E501", "E741"]
45
46
 
46
47
  [tool.ruff.lint.per-file-ignores]
47
48
  "__init__.py" = ["F401"]
48
49
  "test*/*" = ["F401"]
50
+
51
+ [dependency-groups]
52
+ lint = [
53
+ "ruff",
54
+ "ty>=1.1,<2",
55
+ "pandas-stubs>=3,<4",
56
+ ]
57
+
58
+ [tool.ty.environment]
59
+ python-version = "3.11"
60
+
61
+ [tool.ty.src]
62
+ include = ["sercol"]
63
+
64
+ [tool.ty.rules]
65
+ unused-ignore-comment = "error"
66
+ unused-type-ignore-comment = "error"
@@ -10,9 +10,10 @@
10
10
  # See the License for the specific language governing permissions and
11
11
  # limitations under the License.
12
12
 
13
+ """Serializable collection container with grouping, filtering, and export helpers."""
13
14
 
14
15
  from .collection import Collection
15
16
 
16
- __version__ = "1.2.2"
17
+ __version__ = "1.2.4"
17
18
 
18
19
  __all__ = ["Collection", "__version__"]
@@ -10,6 +10,8 @@
10
10
  # See the License for the specific language governing permissions and
11
11
  # limitations under the License.
12
12
 
13
+ """Core ``Collection`` class with grouping, filtering, and serialization."""
14
+
13
15
  import inspect
14
16
  import numbers
15
17
  import os.path
@@ -29,6 +31,44 @@ _SCALAR_TYPES = (str, bytes, numbers.Number, type(None))
29
31
  _HASHED_ELEMENTS_PER_END = 4
30
32
 
31
33
 
34
+ def _bind_clone_args(cls, kwargs):
35
+ """Adapt and validate ``kwargs`` against ``cls``'s constructor signature."""
36
+ kwargs = dict(kwargs)
37
+ signature = inspect.signature(cls)
38
+ parameters = signature.parameters
39
+ args = []
40
+ first = next(iter(parameters.values()), None)
41
+ if (
42
+ "elements" in kwargs and
43
+ "elements" not in parameters and
44
+ first is not None and
45
+ first.name not in kwargs and
46
+ first.default is first.empty and
47
+ first.kind in (
48
+ first.POSITIONAL_ONLY,
49
+ first.POSITIONAL_OR_KEYWORD)):
50
+ args.append(kwargs.pop("elements"))
51
+ if not any(p.kind is p.VAR_KEYWORD for p in parameters.values()):
52
+ for name in _OPTIONAL_STATE:
53
+ if name in kwargs and name not in parameters:
54
+ del kwargs[name]
55
+ try:
56
+ signature.bind(*args, **kwargs)
57
+ except TypeError as error:
58
+ raise TypeError(
59
+ "Can't clone %s: its constructor %s%s doesn't fit the arguments "
60
+ "(%s) which clone_with_new_elements() passes (%s). Override "
61
+ "clone_with_new_elements() in %s, or call it with "
62
+ "drop_keywords, rename_dict or extra_kwargs." % (
63
+ cls.__name__,
64
+ cls.__name__,
65
+ signature,
66
+ ", ".join(["<elements>"] * len(args) + sorted(kwargs)),
67
+ error,
68
+ cls.__name__)) from error
69
+ return args, kwargs
70
+
71
+
32
72
  class Collection(serializable.Serializable):
33
73
  """
34
74
  Collection base class with grouping and filtering functions.
@@ -252,44 +292,13 @@ class Collection(serializable.Serializable):
252
292
  kwargs.update(extra_kwargs or {})
253
293
 
254
294
  cls = self.__class__
255
- signature = inspect.signature(cls)
256
- parameters = signature.parameters
257
- args = []
258
- first = next(iter(parameters.values()), None)
259
- if (
260
- "elements" in kwargs and
261
- "elements" not in parameters and
262
- first is not None and
263
- first.name not in kwargs and
264
- first.default is first.empty and
265
- first.kind in (
266
- first.POSITIONAL_ONLY,
267
- first.POSITIONAL_OR_KEYWORD)):
268
- args.append(kwargs.pop("elements"))
269
- if not any(p.kind is p.VAR_KEYWORD for p in parameters.values()):
270
- for name in _OPTIONAL_STATE:
271
- if name in kwargs and name not in parameters:
272
- del kwargs[name]
273
- try:
274
- signature.bind(*args, **kwargs)
275
- except TypeError as error:
276
- raise TypeError(
277
- "Can't clone %s: its constructor %s%s doesn't fit the arguments "
278
- "(%s) which clone_with_new_elements() passes (%s). Override "
279
- "clone_with_new_elements() in %s, or call it with "
280
- "drop_keywords, rename_dict or extra_kwargs." % (
281
- cls.__name__,
282
- cls.__name__,
283
- signature,
284
- ", ".join(["<elements>"] * len(args) + sorted(kwargs)),
285
- error,
286
- cls.__name__)) from error
295
+ args, kwargs = _bind_clone_args(cls, kwargs)
287
296
  return cls(*args, **kwargs)
288
297
 
289
298
  @property
290
299
  def source(self):
291
300
  """
292
- Returns the single source name for a variant collection if it is unique,
301
+ Returns the single source name for a collection if it is unique,
293
302
  otherwise raises an error.
294
303
  """
295
304
  if len(self.sources) == 0:
@@ -347,9 +356,9 @@ class Collection(serializable.Serializable):
347
356
  def to_string(self, limit=None):
348
357
  """
349
358
  Create a string representation of this collection, showing up to
350
- `limit` items (all of them when `limit` is None).
359
+ ``limit`` items (all of them when ``limit`` is None).
351
360
 
352
- Raises ValueError when `limit` is negative.
361
+ Raises ValueError when ``limit`` is negative.
353
362
  """
354
363
  if limit is not None and limit < 0:
355
364
  raise ValueError("limit must not be negative, got %r" % (limit,))
@@ -516,17 +525,17 @@ class Collection(serializable.Serializable):
516
525
  Parameters
517
526
  ----------
518
527
  key_fn : callable
519
- Given an element of this collection, returns a key into `value_dict`
528
+ Given an element of this collection, returns a key into ``value_dict``
520
529
 
521
530
  value_dict : dict
522
- Dict from keys returned by `key_fn` to float values
531
+ Dict from keys returned by ``key_fn`` to float values
523
532
 
524
533
  threshold : float
525
- Only keep elements whose value in `value_dict` is above this
534
+ Only keep elements whose value in ``value_dict`` is above this
526
535
  threshold.
527
536
 
528
537
  default_value : float
529
- Value to use for elements whose key is not in `value_dict`
538
+ Value to use for elements whose key is not in ``value_dict``
530
539
 
531
540
  Returns
532
541
  -------
@@ -545,7 +554,7 @@ class Collection(serializable.Serializable):
545
554
  value_dict,
546
555
  threshold,
547
556
  default_value=0.0):
548
- """Like filter_above_threshold but `multi_key_fn` returns multiple
557
+ """Like ``filter_above_threshold`` but ``multi_key_fn`` returns multiple
549
558
  keys and the element is kept if any of them have a value above
550
559
  the given threshold.
551
560
 
@@ -553,17 +562,17 @@ class Collection(serializable.Serializable):
553
562
  ----------
554
563
  multi_key_fn : callable
555
564
  Given an element of this collection, returns multiple keys
556
- into `value_dict`
565
+ into ``value_dict``
557
566
 
558
567
  value_dict : dict
559
- Dict from keys returned by `multi_key_fn` to float values
568
+ Dict from keys returned by ``multi_key_fn`` to float values
560
569
 
561
570
  threshold : float
562
- Only keep elements whose value in `value_dict` is above this
571
+ Only keep elements whose value in ``value_dict`` is above this
563
572
  threshold.
564
573
 
565
574
  default_value : float
566
- Value to use for elements whose key is not in `value_dict`
575
+ Value to use for elements whose key is not in ``value_dict``
567
576
 
568
577
  Returns
569
578
  -------
@@ -571,9 +580,7 @@ class Collection(serializable.Serializable):
571
580
  A collection of the same class, as ``filter`` returns.
572
581
  """
573
582
  def filter_fn(x):
574
- for key in multi_key_fn(x):
575
- value = value_dict.get(key, default_value)
576
- if value > threshold:
577
- return True
578
- return False
583
+ return any(
584
+ value_dict.get(key, default_value) > threshold
585
+ for key in multi_key_fn(x))
579
586
  return self.filter(filter_fn)
@@ -1,10 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sercol
3
- Version: 1.2.2
3
+ Version: 1.2.4
4
4
  Summary: Rich collection class with grouping and filtering helpers
5
5
  Author-email: Alex Rubinsteyn <alex.rubinsteyn@unc.edu>
6
6
  License-Expression: Apache-2.0
7
7
  Project-URL: Homepage, https://github.com/openvax/sercol
8
+ Project-URL: Documentation, https://openvax.github.io/sercol/
8
9
  Project-URL: Bug Tracker, https://github.com/openvax/sercol/issues
9
10
  Classifier: Development Status :: 4 - Beta
10
11
  Classifier: Environment :: Console
File without changes
File without changes
File without changes
File without changes