Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/vnmabus/rdata.git into d…
Browse files Browse the repository at this point in the history
…evelop
  • Loading branch information
vnmabus committed Dec 12, 2023
2 parents 11e3568 + b37aa9f commit fcfa969
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 7 deletions.
19 changes: 16 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
rdata
=====

|build-status| |docs| |coverage| |pypi| |zenodo|
|build-status| |docs| |coverage| |repostatus| |versions| |pypi| |conda| |zenodo|

Read R datasets from Python.

Expand Down Expand Up @@ -152,13 +152,26 @@ Pandas `Categorical` objects:
:alt: Coverage Status
:scale: 100%
:target: https://codecov.io/gh/vnmabus/rdata/branch/develop

.. |repostatus| image:: https://www.repostatus.org/badges/latest/active.svg
:alt: Project Status: Active – The project has reached a stable, usable state and is being actively developed.
:target: https://www.repostatus.org/#active

.. |versions| image:: https://img.shields.io/pypi/pyversions/rdata
:alt: PyPI - Python Version
:scale: 100%

.. |pypi| image:: https://badge.fury.io/py/rdata.svg
:alt: Pypi version
:scale: 100%
:target: https://pypi.python.org/pypi/rdata/


.. |conda| image:: https://anaconda.org/conda-forge/rdata/badges/version.svg
:alt: Conda version
:scale: 100%
:target: https://anaconda.org/conda-forge/rdata

.. |zenodo| image:: https://zenodo.org/badge/DOI/10.5281/zenodo.6382237.svg
:alt: Zenodo DOI
:scale: 100%
:target: https://doi.org/10.5281/zenodo.6382237
:target: https://doi.org/10.5281/zenodo.6382237
13 changes: 9 additions & 4 deletions rdata/parser/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,16 +451,21 @@ def compact_seq_constructor(
reference=0,
)

n = int(state.value[0])
start = state.value[1]
stop = state.value[0]
step = state.value[2]

if is_int:
start = int(start)
stop = int(stop)
step = int(step)

value = np.arange(start, stop, step)
# Calculate stop with integer arithmetic
# and use built-in range() for numerical stability
stop = start + (n - 1) * step
value = np.array(range(start, stop + 1, step))
else:
# Calculate stop with floating-point arithmetic
stop = start + (n - 1) * step
value = np.linspace(start, stop, n)

return new_info, value

Expand Down
Binary file not shown.
Binary file not shown.
32 changes: 32 additions & 0 deletions rdata/tests/test_rdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,22 @@ def test_altrep_compact_intseq(self) -> None:
"test_altrep_compact_intseq": np.arange(1000),
})

def test_altrep_compact_intseq_asymmetric(self) -> None:
"""
Test alternative representation of sequences of ints.
This test an origin different from 0, to reproduce
issue #29.
"""
parsed = rdata.parser.parse_file(
TESTDATA_PATH / "test_altrep_compact_intseq_asymmetric.rda",
)
converted = rdata.conversion.convert(parsed)

np.testing.assert_equal(converted, {
"test_altrep_compact_intseq_asymmetric": np.arange(-5, 6),
})

def test_altrep_compact_realseq(self) -> None:
"""Test alternative representation of sequences of ints."""
parsed = rdata.parser.parse_file(
Expand All @@ -643,6 +659,22 @@ def test_altrep_compact_realseq(self) -> None:
"test_altrep_compact_realseq": np.arange(1000.0),
})

def test_altrep_compact_realseq_asymmetric(self) -> None:
"""
Test alternative representation of sequences of ints.
This test an origin different from 0, to reproduce
issue #29.
"""
parsed = rdata.parser.parse_file(
TESTDATA_PATH / "test_altrep_compact_realseq_asymmetric.rda",
)
converted = rdata.conversion.convert(parsed)

np.testing.assert_equal(converted, {
"test_altrep_compact_realseq_asymmetric": np.arange(-5.0, 6.0),
})

def test_altrep_deferred_string(self) -> None:
"""Test alternative representation of deferred strings."""
parsed = rdata.parser.parse_file(
Expand Down

0 comments on commit fcfa969

Please sign in to comment.