Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 4924902

Browse files
committed
Fix quirks in pandas test behaviour
For the current state of the code, this change is not required. It will, however, save someone fixing this in future, when actually wanting to use a newer OpenSAFELY Python image. However, the tests currently rely on a quirky behaviour of `.all()` in pandas that has been fixed. In the version of pandas inside the `python:latest` image (v1.0.1), the behaviour is that `.all()` can return an `dtype=object` instead of a Boolean, and our tests as written pass. In later versions of pandas, `.all()` returns a Boolean instead, and our tests fail. We can rewrite the tests to work both prior to and post this pandas fix. This was checked by running the tests with the `Dockerfile` as provided, and editing the `Dockerfile` to use the `v2` OpenSAFELY Python image. See pandas-dev/pandas#12863.
1 parent bfe23b4 commit 4924902

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

interactive_templates/templates/v2/tests/test_measures.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ def test_calculate_total_counts(df):
100100

101101
obs = measures.calculate_total_counts(df, date, group="total", group_value="total")
102102

103-
assert obs["group"].all() == "total"
104-
assert obs["group_value"].all() == "total"
103+
assert obs["group"].eq("total").all()
104+
assert obs["group_value"].eq("total").all()
105105

106106
assert len(obs) == 1
107107
assert obs.columns.tolist() == [
@@ -113,7 +113,7 @@ def test_calculate_total_counts(df):
113113
]
114114

115115
# assert date is correct
116-
assert obs["date"].all() == date
116+
assert obs["date"].eq(date).all()
117117

118118
# assert that the sum of the event_measure and population columns is correct
119119
assert obs["event_measure"].iloc[0] == df["event_measure"].sum()
@@ -139,7 +139,7 @@ def test_calculate_group_counts(df):
139139
]
140140

141141
# assert date is correct
142-
assert obs["date"].all() == date
142+
assert obs["date"].eq(date).all()
143143

144144
# assert that the sum of the event_measure and population columns is correct
145145
assert (

0 commit comments

Comments
 (0)