gtfparse 3.1.0__tar.gz → 3.2.0__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.
Files changed (54) hide show
  1. {gtfparse-3.1.0/gtfparse.egg-info → gtfparse-3.2.0}/PKG-INFO +5 -1
  2. {gtfparse-3.1.0 → gtfparse-3.2.0}/README.md +4 -0
  3. {gtfparse-3.1.0 → gtfparse-3.2.0}/gtfparse/__init__.py +1 -1
  4. {gtfparse-3.1.0 → gtfparse-3.2.0}/gtfparse/read_gtf.py +52 -5
  5. {gtfparse-3.1.0 → gtfparse-3.2.0/gtfparse.egg-info}/PKG-INFO +5 -1
  6. {gtfparse-3.1.0 → gtfparse-3.2.0}/gtfparse.egg-info/SOURCES.txt +1 -0
  7. {gtfparse-3.1.0 → gtfparse-3.2.0}/tests/test_polars_compatibility.py +21 -3
  8. gtfparse-3.2.0/tests/test_polars_lazy_adapter.py +46 -0
  9. {gtfparse-3.1.0 → gtfparse-3.2.0}/tests/test_progress.py +21 -1
  10. {gtfparse-3.1.0 → gtfparse-3.2.0}/LICENSE +0 -0
  11. {gtfparse-3.1.0 → gtfparse-3.2.0}/MANIFEST.in +0 -0
  12. {gtfparse-3.1.0 → gtfparse-3.2.0}/benchmarks/README.md +0 -0
  13. {gtfparse-3.1.0 → gtfparse-3.2.0}/benchmarks/compare_readers.py +0 -0
  14. {gtfparse-3.1.0 → gtfparse-3.2.0}/benchmarks/compare_releases.py +0 -0
  15. {gtfparse-3.1.0 → gtfparse-3.2.0}/benchmarks/optimization-results.json +0 -0
  16. {gtfparse-3.1.0 → gtfparse-3.2.0}/benchmarks/optimization.md +0 -0
  17. {gtfparse-3.1.0 → gtfparse-3.2.0}/benchmarks/results.json +0 -0
  18. {gtfparse-3.1.0 → gtfparse-3.2.0}/gtfparse/_polars.py +0 -0
  19. {gtfparse-3.1.0 → gtfparse-3.2.0}/gtfparse/_read_csv.py +0 -0
  20. {gtfparse-3.1.0 → gtfparse-3.2.0}/gtfparse/attribute_parsing.py +0 -0
  21. {gtfparse-3.1.0 → gtfparse-3.2.0}/gtfparse/columns.py +0 -0
  22. {gtfparse-3.1.0 → gtfparse-3.2.0}/gtfparse/create_missing_features.py +0 -0
  23. {gtfparse-3.1.0 → gtfparse-3.2.0}/gtfparse/parsing_error.py +0 -0
  24. {gtfparse-3.1.0 → gtfparse-3.2.0}/gtfparse/write_gtf.py +0 -0
  25. {gtfparse-3.1.0 → gtfparse-3.2.0}/gtfparse.egg-info/dependency_links.txt +0 -0
  26. {gtfparse-3.1.0 → gtfparse-3.2.0}/gtfparse.egg-info/requires.txt +0 -0
  27. {gtfparse-3.1.0 → gtfparse-3.2.0}/gtfparse.egg-info/top_level.txt +0 -0
  28. {gtfparse-3.1.0 → gtfparse-3.2.0}/lint.sh +0 -0
  29. {gtfparse-3.1.0 → gtfparse-3.2.0}/pyproject.toml +0 -0
  30. {gtfparse-3.1.0 → gtfparse-3.2.0}/requirements.txt +0 -0
  31. {gtfparse-3.1.0 → gtfparse-3.2.0}/setup.cfg +0 -0
  32. {gtfparse-3.1.0 → gtfparse-3.2.0}/test.sh +0 -0
  33. {gtfparse-3.1.0 → gtfparse-3.2.0}/tests/__init__.py +0 -0
  34. {gtfparse-3.1.0 → gtfparse-3.2.0}/tests/data/B16.stringtie.head.gtf +0 -0
  35. {gtfparse-3.1.0 → gtfparse-3.2.0}/tests/data/ensembl_grch37.head.gtf +0 -0
  36. {gtfparse-3.1.0 → gtfparse-3.2.0}/tests/data/ensembl_grch37.head.gtf.gz +0 -0
  37. {gtfparse-3.1.0 → gtfparse-3.2.0}/tests/data/gencode.head.gtf +0 -0
  38. {gtfparse-3.1.0 → gtfparse-3.2.0}/tests/data/gencode.real.head.gtf +0 -0
  39. {gtfparse-3.1.0 → gtfparse-3.2.0}/tests/data/refseq.ucsc.small.gtf +0 -0
  40. {gtfparse-3.1.0 → gtfparse-3.2.0}/tests/data.py +0 -0
  41. {gtfparse-3.1.0 → gtfparse-3.2.0}/tests/test_attribute_optimization.py +0 -0
  42. {gtfparse-3.1.0 → gtfparse-3.2.0}/tests/test_attribute_values.py +0 -0
  43. {gtfparse-3.1.0 → gtfparse-3.2.0}/tests/test_columns.py +0 -0
  44. {gtfparse-3.1.0 → gtfparse-3.2.0}/tests/test_create_missing_features.py +0 -0
  45. {gtfparse-3.1.0 → gtfparse-3.2.0}/tests/test_ensembl_gtf.py +0 -0
  46. {gtfparse-3.1.0 → gtfparse-3.2.0}/tests/test_expand_attribute_column_false.py +0 -0
  47. {gtfparse-3.1.0 → gtfparse-3.2.0}/tests/test_expand_attributes.py +0 -0
  48. {gtfparse-3.1.0 → gtfparse-3.2.0}/tests/test_gencode_gtf.py +0 -0
  49. {gtfparse-3.1.0 → gtfparse-3.2.0}/tests/test_multiple_values_for_tag_attribute.py +0 -0
  50. {gtfparse-3.1.0 → gtfparse-3.2.0}/tests/test_parse_gtf_lines.py +0 -0
  51. {gtfparse-3.1.0 → gtfparse-3.2.0}/tests/test_read_stringtie_gtf.py +0 -0
  52. {gtfparse-3.1.0 → gtfparse-3.2.0}/tests/test_reader.py +0 -0
  53. {gtfparse-3.1.0 → gtfparse-3.2.0}/tests/test_refseq_gtf.py +0 -0
  54. {gtfparse-3.1.0 → gtfparse-3.2.0}/tests/test_write_gtf.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gtfparse
3
- Version: 3.1.0
3
+ Version: 3.2.0
4
4
  Summary: Parsing library for extracting data frames of genomic features from GTF files
5
5
  Author-email: Alex Rubinsteyn <alex.rubinsteyn@unc.edu>
6
6
  License-Expression: Apache-2.0
@@ -113,6 +113,10 @@ python -m pip install -e ".[dev]"
113
113
 
114
114
  `./format.sh` applies ruff formatting.
115
115
 
116
+ The development installer uses `python` from the active environment. Set
117
+ `PYTHON=/path/to/python ./develop.sh` to select an interpreter explicitly;
118
+ additional arguments are passed to pip.
119
+
116
120
  ## License
117
121
 
118
122
  Apache 2.0; see [LICENSE](LICENSE).
@@ -80,6 +80,10 @@ python -m pip install -e ".[dev]"
80
80
 
81
81
  `./format.sh` applies ruff formatting.
82
82
 
83
+ The development installer uses `python` from the active environment. Set
84
+ `PYTHON=/path/to/python ./develop.sh` to select an interpreter explicitly;
85
+ additional arguments are passed to pip.
86
+
83
87
  ## License
84
88
 
85
89
  Apache 2.0; see [LICENSE](LICENSE).
@@ -24,7 +24,7 @@ from .read_gtf import (
24
24
  )
25
25
  from .write_gtf import write_gtf
26
26
 
27
- __version__ = "3.1.0"
27
+ __version__ = "3.2.0"
28
28
 
29
29
  __all__ = [
30
30
  "GENCODE_BIOTYPE_ALIASES",
@@ -11,6 +11,7 @@
11
11
  # limitations under the License.
12
12
 
13
13
  import logging
14
+ import warnings
14
15
  from os.path import exists
15
16
 
16
17
  import pandas as pd
@@ -48,12 +49,42 @@ INTEGER_VERSION_COLUMNS = (
48
49
  def parse_with_polars_lazy(
49
50
  filepath_or_buffer, split_attributes=True, features=None, fix_quotes_columns=None
50
51
  ):
51
- """Read eagerly and return an optional Polars LazyFrame.
52
-
53
- As in earlier releases, file I/O happens before this function returns.
52
+ """Deprecated: read eagerly and return an optional Polars LazyFrame.
53
+
54
+ Despite its name, the whole file is read before this function returns,
55
+ so nothing is scanned lazily. The exact equivalent is
56
+ ``polars.from_pandas(parse_gtf(...)).lazy()``, which keeps the unexpanded
57
+ ``attribute`` and ``attribute_split`` columns this function returns. For
58
+ attributes expanded into columns (with read_gtf's version-column casts),
59
+ use ``read_gtf(..., result_type="polars").lazy()`` instead.
54
60
  Install ``gtfparse[polars]`` to use this compatibility adapter.
61
+
62
+ Deprecated since 3.2.0; will be removed in gtfparse 4.0.
63
+
64
+ Parameters
65
+ ----------
66
+ filepath_or_buffer, split_attributes, features, fix_quotes_columns
67
+ Passed to parse_gtf unchanged.
68
+
69
+ Returns
70
+ -------
71
+ polars.LazyFrame
72
+ A lazy view of the frame parse_gtf returns, already held in memory.
73
+
74
+ Warns
75
+ -----
76
+ DeprecationWarning
77
+ On every call.
55
78
  """
56
79
  polars = require_polars()
80
+ warnings.warn(
81
+ "parse_with_polars_lazy is deprecated and will be removed in gtfparse 4.0. "
82
+ "It reads the whole file eagerly; the exact equivalent is "
83
+ "polars.from_pandas(parse_gtf(...)).lazy(). For expanded attribute "
84
+ 'columns use read_gtf(..., result_type="polars").lazy().',
85
+ DeprecationWarning,
86
+ stacklevel=2,
87
+ )
57
88
  return polars.from_pandas(
58
89
  parse_gtf(filepath_or_buffer, split_attributes, features, fix_quotes_columns)
59
90
  ).lazy()
@@ -121,10 +152,14 @@ def parse_gtf(
121
152
 
122
153
 
123
154
  def parse_gtf_pandas(*args, **kwargs):
124
- """Like parse_gtf, also reporting a ``convert`` progress stage.
155
+ """Deprecated: like parse_gtf, also reporting a ``convert`` progress stage.
125
156
 
126
157
  Kept for compatibility from when parse_gtf returned Polars; parse_gtf now
127
- returns pandas itself, so the conversion stage does no work.
158
+ returns pandas itself, so the conversion stage does no work. Use
159
+ parse_gtf instead. The ``convert`` progress events are still emitted
160
+ while this function remains.
161
+
162
+ Deprecated since 3.2.0; will be removed in gtfparse 4.0.
128
163
 
129
164
  Parameters
130
165
  ----------
@@ -135,7 +170,19 @@ def parse_gtf_pandas(*args, **kwargs):
135
170
  -------
136
171
  pandas.DataFrame
137
172
  The same frame parse_gtf returns.
173
+
174
+ Warns
175
+ -----
176
+ DeprecationWarning
177
+ On every call.
138
178
  """
179
+ warnings.warn(
180
+ "parse_gtf_pandas is deprecated and will be removed in gtfparse 4.0. "
181
+ "Use parse_gtf, which returns the same pandas DataFrame but does not "
182
+ "emit the no-op 'convert' progress events.",
183
+ DeprecationWarning,
184
+ stacklevel=2,
185
+ )
139
186
  df = parse_gtf(*args, **kwargs)
140
187
  progress_callback = kwargs.get("progress_callback")
141
188
  if progress_callback is not None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gtfparse
3
- Version: 3.1.0
3
+ Version: 3.2.0
4
4
  Summary: Parsing library for extracting data frames of genomic features from GTF files
5
5
  Author-email: Alex Rubinsteyn <alex.rubinsteyn@unc.edu>
6
6
  License-Expression: Apache-2.0
@@ -113,6 +113,10 @@ python -m pip install -e ".[dev]"
113
113
 
114
114
  `./format.sh` applies ruff formatting.
115
115
 
116
+ The development installer uses `python` from the active environment. Set
117
+ `PYTHON=/path/to/python ./develop.sh` to select an interpreter explicitly;
118
+ additional arguments are passed to pip.
119
+
116
120
  ## License
117
121
 
118
122
  Apache 2.0; see [LICENSE](LICENSE).
@@ -38,6 +38,7 @@ tests/test_gencode_gtf.py
38
38
  tests/test_multiple_values_for_tag_attribute.py
39
39
  tests/test_parse_gtf_lines.py
40
40
  tests/test_polars_compatibility.py
41
+ tests/test_polars_lazy_adapter.py
41
42
  tests/test_progress.py
42
43
  tests/test_read_stringtie_gtf.py
43
44
  tests/test_reader.py
@@ -2,7 +2,7 @@ from io import StringIO
2
2
 
3
3
  import pytest
4
4
 
5
- from gtfparse import read_gtf, write_gtf
5
+ from gtfparse import parse_gtf, read_gtf, write_gtf
6
6
  from gtfparse.read_gtf import parse_with_polars_lazy
7
7
 
8
8
  polars = pytest.importorskip("polars")
@@ -29,9 +29,9 @@ def test_repeated_reads_preserve_categoricals(result_type):
29
29
 
30
30
 
31
31
  def test_categoricals_from_separate_lazy_reads_can_join():
32
- left = parse_with_polars_lazy(StringIO(GTF_TEXT))
32
+ left = read_gtf(StringIO(GTF_TEXT), result_type="polars").lazy()
33
33
  reversed_text = "\n".join(reversed(GTF_TEXT.splitlines())) + "\n"
34
- right = parse_with_polars_lazy(StringIO(reversed_text))
34
+ right = read_gtf(StringIO(reversed_text), result_type="polars").lazy()
35
35
  keys = ["seqname", "source", "feature", "strand"]
36
36
  joined = left.join(right, on=keys).sort("start").collect()
37
37
 
@@ -42,6 +42,24 @@ def test_categoricals_from_separate_lazy_reads_can_join():
42
42
  assert joined[key].dtype == polars.Categorical
43
43
 
44
44
 
45
+ def test_parse_with_polars_lazy_is_deprecated():
46
+ with pytest.warns(DeprecationWarning, match="parse_with_polars_lazy is deprecated") as caught:
47
+ lazy = parse_with_polars_lazy(StringIO(GTF_TEXT), features={"exon"})
48
+ assert len(caught) == 1
49
+ assert caught[0].filename == __file__
50
+ assert 'result_type="polars"' in str(caught[0].message)
51
+ assert "polars.from_pandas(parse_gtf(...)).lazy()" in str(caught[0].message)
52
+ assert isinstance(lazy, polars.LazyFrame)
53
+ collected = lazy.collect()
54
+ assert collected.columns[-2:] == ["attribute", "attribute_split"]
55
+ assert collected["feature"].to_list() == ["exon"]
56
+ assert collected["attribute"].to_list() == ['gene_id "g2";']
57
+ from polars.testing import assert_frame_equal
58
+
59
+ expected = polars.from_pandas(parse_gtf(StringIO(GTF_TEXT), features={"exon"}))
60
+ assert_frame_equal(collected, expected)
61
+
62
+
45
63
  @pytest.mark.skipif(not hasattr(polars, "Categories"), reason="Requires modern Polars")
46
64
  def test_modern_reads_do_not_toggle_global_string_cache(monkeypatch):
47
65
  def fail_on_cache_toggle():
@@ -0,0 +1,46 @@
1
+ """parse_with_polars_lazy behaviour that does not need Polars installed."""
2
+
3
+ import sys
4
+ import warnings
5
+
6
+ import pandas as pd
7
+ import pytest
8
+
9
+ from gtfparse import parse_gtf
10
+ from gtfparse.read_gtf import parse_with_polars_lazy
11
+
12
+ from .data import data_path
13
+
14
+ GTF_PATH = data_path("ensembl_grch37.head.gtf")
15
+
16
+
17
+ class RecordingPolars:
18
+ """Stand-in for the polars module that records the frame it is handed."""
19
+
20
+ class Frame:
21
+ def __init__(self, pandas_frame):
22
+ self.pandas_frame = pandas_frame
23
+
24
+ def lazy(self):
25
+ return ("lazy", self.pandas_frame)
26
+
27
+ @classmethod
28
+ def from_pandas(cls, pandas_frame):
29
+ return cls.Frame(pandas_frame)
30
+
31
+
32
+ def test_missing_polars_raises_install_hint_without_deprecation_warning(monkeypatch):
33
+ monkeypatch.setitem(sys.modules, "polars", None)
34
+ with warnings.catch_warnings(record=True) as caught:
35
+ warnings.simplefilter("always")
36
+ with pytest.raises(ImportError, match=r"gtfparse\[polars\]"):
37
+ parse_with_polars_lazy(GTF_PATH)
38
+ assert [w for w in caught if issubclass(w.category, DeprecationWarning)] == []
39
+
40
+
41
+ def test_adapter_warns_and_wraps_the_parse_gtf_frame(monkeypatch):
42
+ monkeypatch.setattr(sys.modules["gtfparse.read_gtf"], "require_polars", lambda: RecordingPolars)
43
+ with pytest.warns(DeprecationWarning, match="parse_with_polars_lazy is deprecated"):
44
+ kind, frame = parse_with_polars_lazy(GTF_PATH)
45
+ assert kind == "lazy"
46
+ pd.testing.assert_frame_equal(frame, parse_gtf(GTF_PATH))
@@ -80,7 +80,6 @@ def test_progress_with_supported_inputs(kind, tmp_path):
80
80
  [
81
81
  (parse_gtf, ["read"]),
82
82
  (parse_gtf_and_expand_attributes, ["read", "attributes"]),
83
- (parse_gtf_pandas, ["read", "convert"]),
84
83
  ],
85
84
  )
86
85
  def test_lower_level_progress(parser, stages):
@@ -90,6 +89,27 @@ def test_lower_level_progress(parser, stages):
90
89
  assert all(event[1:] == (2, 2) for event in events[1::2])
91
90
 
92
91
 
92
+ def test_parse_gtf_pandas_is_deprecated_and_keeps_convert_events():
93
+ events = []
94
+ with pytest.warns(DeprecationWarning, match="parse_gtf_pandas is deprecated") as caught:
95
+ result = parse_gtf_pandas(
96
+ StringIO(GTF), progress_callback=lambda *event: events.append(event)
97
+ )
98
+ assert len(caught) == 1
99
+ assert caught[0].filename == __file__
100
+ assert "Use parse_gtf" in str(caught[0].message)
101
+ assert "convert" in str(caught[0].message)
102
+ assert events == [("read", 0, None), ("read", 2, 2), ("convert", 0, None), ("convert", 2, 2)]
103
+ pd.testing.assert_frame_equal(result, parse_gtf(StringIO(GTF)))
104
+
105
+
106
+ @pytest.mark.filterwarnings("error::DeprecationWarning")
107
+ def test_supported_readers_do_not_emit_deprecation_warnings():
108
+ assert len(parse_gtf(StringIO(GTF))) == 2
109
+ assert len(parse_gtf_and_expand_attributes(StringIO(GTF))) == 2
110
+ assert len(read_gtf(StringIO(GTF))) == 2
111
+
112
+
93
113
  @pytest.mark.parametrize("rows", [0, 1, 10_000, 20_003])
94
114
  def test_attribute_progress_counts_rows_and_is_bounded(rows):
95
115
  events = []
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes