Skip to content

Commit cbe6ad9

Browse files
authored
Merge pull request #2 from AidanCooper/compare_populations_bug
Fix issue #1
2 parents 4ab3e1a + b5ba968 commit cbe6ad9

File tree

5 files changed

+39
-10
lines changed

5 files changed

+39
-10
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [0.1.1] - 2022-01-19
9+
10+
### Fixed
11+
12+
- Fixed `MAIC.compare_populations` bug [[#1](https://github.com/AidanCooper/indcomp/issues/1)]
13+
14+
## [0.1.0] - 2022-01-17
15+
16+
Initial alpha release

indcomp/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
- Simulated Treatment Comparison (STC)
99
"""
1010

11-
__version__ = "0.1.0"
11+
__version__ = "0.1.1"
1212

1313
from ._maic import MAIC

indcomp/_maic.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,18 @@ def compare_populations(
174174
raise e.NoWeightsException()
175175

176176
# create grid
177-
ncols = min(ncols, len(variables))
178-
nrows = len(variables) // ncols
179-
remainder = len(variables) % ncols
177+
if len(variables) == 1:
178+
ncols, nrows, remainder = 1, 1, 0
179+
else:
180+
ncols = min(ncols, len(variables))
181+
nrows = len(variables) // ncols
182+
remainder = len(variables) % ncols
180183
fig, axes = plt.subplots(nrows, ncols, figsize=(ncols * 4, nrows * 4))
181184
fig.patch.set_facecolor("white")
182-
axes = axes.flatten()
185+
if len(variables) == 1:
186+
axes = [axes]
187+
else:
188+
axes = axes.flatten()
183189
for r in range(1, remainder + 1):
184190
axes[-r].axis("off")
185191

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setup(
88
name="indcomp",
9-
version="0.1.0",
9+
version="0.1.1",
1010
description="Perform indirect treatment comparison (ITC) analyses",
1111
long_description=README,
1212
long_description_content_type="text/markdown",

tests/test_maic.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,19 @@ def data_NICE_DSU18():
1919
return (df_ind, df_tar)
2020

2121

22-
@pytest.fixture
23-
def correct_config_maic(data_NICE_DSU18):
22+
@pytest.fixture(
23+
params=[
24+
{"age.mean": ("mean", "age")},
25+
{"age.mean": ("mean", "age"), "age.sd": ("std", "age", "age.mean")},
26+
]
27+
)
28+
def correct_config_maic(request, data_NICE_DSU18):
2429
"""Return a correctly configued MAIC instance"""
2530
df_ind, df_tar = data_NICE_DSU18
2631
return MAIC(
2732
df_ind,
2833
df_tar,
29-
{"age.mean": ("mean", "age"), "age.sd": ("std", "age", "age.mean")},
34+
request.param,
3035
)
3136

3237

@@ -123,7 +128,9 @@ def test_maic_methods(correct_config_maic):
123128
# calculate_weights
124129
with optional_step("calculate_weights") as calculate_weights:
125130
maic.calc_weights()
126-
assert np.isclose(maic.ESS_, 178.56, atol=0.01)
131+
assert np.isclose(maic.ESS_, 178.56, atol=0.01) or np.isclose(
132+
maic.ESS_, 188.89, atol=0.01
133+
)
127134
yield calculate_weights
128135

129136
# plot_weights

0 commit comments

Comments
 (0)