Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6746653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:20:53+00:00 2026-05-26T12:20:53+00:00

I recently had the following problem: I’m developing a numerical library in Python (called

  • 0

I recently had the following problem: I’m developing a numerical library in Python (called spuq) that needs scipy at its core. Now one of the functions in scipy, its called btdtri, had a bug for a certain tuple of input parameters. This bug, however, is now fixed in scipy version 0.9 according to the developers of scipy. So in my code I have something like this:

import scipy

def foo(a, b, c):
  if scipy.__version__>=(0, 9):
      return btdtri(a, b, c)
  else:
      return my_fixed_btdtri(a, b, c)

This works, however, I don’t really like to litter my code with bug fixes for third party packages. I would rather have that contained in one module, that implements the workaround, and have all the other of my modules uses the patched module automatically.

Now my question is: what would be the best practice to handle cases like this in general? E.g. write my own spuq.contrib.scipy and say there

from scipy import *
if __version__ < (0, 9):
  btdtri = my_fixed_btdtri

and instead of importing scipy import spuq.contrib.scipy everywhere? I think that’s complicated and easy to forget (and probably unpythonic and ugly). Maybe there is a way to “hook” automatically into the package loading and modify the scipy module directly so that every other package sees only the patched up package? I think this problem is quite common, so probably there should be some ‘best-practices’ around.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:20:54+00:00Added an answer on May 26, 2026 at 12:20 pm

    You could “monkey patch” the scipy module. Somewhere in your initialization code, do

    import scipy.special
    if scipy.version.version < "0.9.0":
        scipy.special.btdtri = my_btdtri
    

    Since modules are imported only once, there will be only one module scipy.special, and all other modules will only see the monkey-patched version.

    Monkey patching is often seen as useful for testing, but not for production code. In this case, though, I think it is fine since you don’t really change the behaviour of the package — you are fixing a confirmed bug.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had a frustrating problem recently that boiled down to a very simple coding
I recently had an exchange with another C++ developer about the following use of
Recently I attended a lecture concerning some design patterns: The following code had been
I recently had a problem during the deployment of a windows service. Four computers
I recently had a problem in my app where some of the subviews I
I recently had this problem about scrolling and focus changing. I solved it by
I had an issue recently (see my last question) that led me to take
I recently had the following memory bug , which is easy to spot here,
I've recently encountered the following problem with my application: it didn't show any console
I have an application in production that that recently had a MySQL timeout, so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.