Skip to content

Commit

Permalink
Update timestamps function in TsTzSpanSet
Browse files Browse the repository at this point in the history
  • Loading branch information
Diviloper committed Feb 24, 2024
1 parent 5452e3c commit 868930d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
7 changes: 4 additions & 3 deletions pymeos/pymeos/collections/time/tstzspanset.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def timestamp_n(self, n: int) -> datetime:
raise IndexError(f"Index {n} out of bounds")
return timestamptz_to_datetime(tstzspanset_timestamptz_n(self._inner, n + 1))

def timestamps(self) -> List[datetime]:
def timestamps(self) -> TsTzSet:
"""
Returns the list of distinct timestamps in ``self``.
Returns:
Expand All @@ -166,8 +166,9 @@ def timestamps(self) -> List[datetime]:
MEOS Functions:
spanset_timestamptzs
"""
ts, count = tstzspanset_timestamps(self._inner)
return [timestamptz_to_datetime(ts[i]) for i in range(count)]
from .tstzset import TsTzSet

return TsTzSet(_inner=tstzspanset_timestamps(self._inner))

def start_span(self) -> TsTzSpan:
"""
Expand Down
2 changes: 1 addition & 1 deletion pymeos/tests/collections/time/dateset_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_to_spanset(self):
)

spanset = self.date_set.to_spanset()

assert spanset == expected


Expand Down
15 changes: 9 additions & 6 deletions pymeos/tests/collections/time/tstzspanset_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from pymeos import (
TsTzSpan,
TsTzSet,
TsTzSpanSet,
TFloatInst,
TFloatSeq,
Expand Down Expand Up @@ -123,12 +124,14 @@ def test_timestamp_n(self):
)

def test_timestamps(self):
assert self.tstzspanset.timestamps() == [
datetime(2019, 9, 1, tzinfo=timezone.utc),
datetime(2019, 9, 2, tzinfo=timezone.utc),
datetime(2019, 9, 3, tzinfo=timezone.utc),
datetime(2019, 9, 4, tzinfo=timezone.utc),
]
assert self.tstzspanset.timestamps() == TsTzSet(
elements=[
datetime(2019, 9, 1, tzinfo=timezone.utc),
datetime(2019, 9, 2, tzinfo=timezone.utc),
datetime(2019, 9, 3, tzinfo=timezone.utc),
datetime(2019, 9, 4, tzinfo=timezone.utc),
]
)

def test_num_tstzspans(self):
assert self.tstzspanset.num_spans() == 2
Expand Down
5 changes: 1 addition & 4 deletions pymeos/tests/main/tfloat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2052,10 +2052,7 @@ def test_derivative(self, temporal, expected):

@pytest.mark.parametrize(
"temporal",
[
tfi,
tfds
],
[tfi, tfds],
ids=["Instant", "Discrete Sequence"],
)
def test_derivative_without_linear_interpolation_raises(self, temporal):
Expand Down

0 comments on commit 868930d

Please sign in to comment.