pymc-devs / pymc-devs/pymc-examples

Error in `examples/causal_inference/bayesian_nonparametric_causal.ipynb`

Open
#724 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
398
Forks
325
Avg merge
9d 15m
Merged PRs (30d)
1

Description

Seems to be some pandas error.

────────────────────────────────── Error running examples/causal_inference/bayesian_nonparametric_causal.ipynb ───────────────────────────────────

---------------------------------------------------------------------------
Exception encountered at "In [17]":
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[17], line 3
      1 temp = X.copy()
      2 temp["ps"] = ps_logit.values
----> 3 temp["ps_cut"] = pd.qcut(temp["ps"], 5)
      6 def plot_balance(temp, col, t):
      7     fig, axs = plt.subplots(1, 5, figsize=(20, 9))

File ~/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pandas/core/reshape/tile.py:340, in qcut(x, q, labels, retbins, precision,
duplicates)
    336 quantiles = np.linspace(0, 1, q + 1) if is_integer(q) else q
    338 bins = x_idx.to_series().dropna().quantile(quantiles)
--> 340 fac, bins = _bins_to_cuts(
    341     x_idx,
    342     Index(bins),
    343     labels=labels,
    344     precision=precision,
    345     include_lowest=True,
    346     duplicates=duplicates,
    347 )
    349 return _postprocess_for_cut(fac, bins, retbins, original)

File ~/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pandas/core/reshape/tile.py:443, in _bins_to_cuts(x_idx, bins, right, labels,
precision, include_lowest, duplicates, ordered)
    441 if len(unique_bins) < len(bins) and len(bins) != 2:
    442     if duplicates == "raise":
--> 443         raise ValueError(
    444             f"Bin edges must be unique: {repr(bins)}.\n"
    445             f"You can drop duplicate edges by setting the 'duplicates' kwarg"
    446         )
    447     bins = unique_bins
    449 side: Literal["left", "right"] = "left" if right else "right"

ValueError: Bin edges must be unique: Index([0.47, 0.48, 0.48, 0.48, 0.49, 0.5], dtype='float64', name='ps').
You can drop duplicate edges by setting the 'duplicates' kwarg

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open examples/causal_inference/bayesian_nonparametric_causal.ipynb and inspect cell In[17], starting with the pd.qcut call shown in the traceback. Run the notebook to reproduce the pandas ValueError and verify that the example completes without this error.

Written by the indexing model from the issue text.

Assessment

Tech stack
pandas, python
Domain
machine-learning
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.