Skip to content

Commit

Permalink
minor updates to make compatible with requirement updates
Browse files Browse the repository at this point in the history
  • Loading branch information
karink520 committed Aug 29, 2023
1 parent 8e6ddc3 commit 5abcc87
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 20 deletions.
10 changes: 1 addition & 9 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use "--disable=all --enable=classes
# --disable=W".
disable=bad-continuation,
fixme,
disable=fixme,
no-else-return,
too-many-lines

Expand Down Expand Up @@ -130,13 +129,6 @@ max-line-length=100
# Maximum number of lines in a module.
max-module-lines=1000

# List of optional constructs for which whitespace checking is disabled. `dict-
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
# `empty-line` allows space-only lines.
no-space-check=trailing-comma,
dict-separator

# Allow the body of a class to be on the same line as the declaration if body
# contains single statement.
single-line-class-stmt=no
Expand Down
5 changes: 2 additions & 3 deletions pyei/greiner_quinn_gibbs_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ def sample_theta(internal_cell_counts_samp, theta_prev, omega_prev, mu_samp, Sig

unif_samp = st.uniform.rvs(size=1)
if unif_samp < acc_prob:

return theta_proposed
else:
return theta_prev
Expand Down Expand Up @@ -478,7 +477,7 @@ def sample_internal_cell_counts(theta_samp, prev_internal_counts_samp):
return prev_internal_counts_samp


@njit(parallel=True)
@njit(parallel=True, nopython=False)

This comment has been minimized.

Copy link
@sklam

sklam Oct 17, 2023

Numba is in the middle of removing object-mode fallback and we are looking for code that are relying on it by setting nopython=False instead of forcing objectmode use with forceobj=True. If it's convenient, can you reply to numba/numba#9247 as to why this use of nopython=False is needed?

The code will not benefit from parallel=True if the code falls into object-mode. Function using prange should have nopython=True which is the default of njit. If there is a problem prevent the use of nopython=True, it is likely a Numba bug or a missing feature.

def get_initial_internal_count_sample(group_counts, vote_counts, precinct_pops):
"""
Sets an initial value of internal counts that is compatible with the
Expand Down Expand Up @@ -530,7 +529,7 @@ def get_initial_internal_count_sample(group_counts, vote_counts, precinct_pops):
/ precinct_pops[i]
)
prop_for_binom = vote_counts[i, c] / precinct_pops[i]
samp = np.random.binomial(count_for_binom, prop_for_binom)
samp = np.random.binomial(n=int(count_for_binom), p=int(prop_for_binom))

samp = min(samp, vote_counts_remaining[i, c])
samp = min(samp, group_counts_remaining[i, r])
Expand Down
2 changes: 1 addition & 1 deletion pyei/io_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def to_netcdf(ei_object, filepath):
mode = "a"
for attr in ["demographic_group_fractions", "votes_fractions"]: # array atts
data = xr.DataArray(getattr(ei_object, attr), name=attr)
data.to_netcdf(filepath, mode=mode, group=attr)
data.to_netcdf(filepath, mode=mode, group=attr, engine="netcdf4")
data.close()


Expand Down
7 changes: 3 additions & 4 deletions pyei/plot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ def plot_boxplots(
fig.subplots_adjust(hspace=1)

for plot_idx in range(num_plots):

samples_df = pd.DataFrame(
{legend[i]: sampled_voting_prefs[:, i, plot_idx] for i in range(num_boxes_per_plot)}
)
Expand Down Expand Up @@ -391,9 +390,9 @@ def plot_summary(
sns.despine(ax=ax_hist)
sns.despine(ax=ax_box, left=True)
# plot custom boxplot, with two boxplots in the same row
plot_props = dict(fliersize=5, linewidth=2, whis=[2.5, 97.5])
flier1_props = dict(marker="o", markerfacecolor=colors[0], alpha=0.5)
flier2_props = dict(marker="d", markerfacecolor=colors[1], alpha=0.5)
plot_props = {"fliersize": 5, "linewidth": 2, "whis": [2.5, 97.5]}
flier1_props = {"marker": "o", "markerfacecolor": colors[0], "alpha": 0.5}
flier2_props = {"marker": "d", "markerfacecolor": colors[1], "alpha": 0.5}
sns.boxplot(
x=sampled_voting_prefs[:, 0, 0],
orient="h",
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ numpy
jax
numpyro
jaxlib
numba
numba
netCDF4
1 change: 0 additions & 1 deletion test/test_goodmans_er.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,5 @@ def test_goodman_er_bayes_bounds(goodmans_er_bayes_examples):


def test_goodman_er_bayes_plot(goodmans_er_bayes_examples):

ax = goodmans_er_bayes_examples["bayes_goodman_ei_weighted"].plot()
assert ax is not None
1 change: 0 additions & 1 deletion test/test_greiner_quinn.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ def test_theta_to_omega():
def test_greiner_quinn_gibbs_sample(
example_r_by_c_data_asym,
): # pylint: disable=redefined-outer-name

r = example_r_by_c_data_asym["group_counts"].shape[1]
c = example_r_by_c_data_asym["vote_counts"].shape[1]
print(r, c)
Expand Down

0 comments on commit 5abcc87

Please sign in to comment.