ronikobrosly / causal-curve

A python package with tools to perform causal inference using observational data when the treatment of interest is continuous.
MIT License
271 stars 18 forks source link

ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part. #45

Open dirknbr opened 5 months ago

dirknbr commented 5 months ago

when I run

gps_point = gps.point_estimate(np.array([1]))

I get this error

ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.

the model was trained with continours treatment in pandas format

ronikobrosly commented 5 months ago

Hi @dirknbr , can you include data and code to replicate this? The data can be mock/random data if that helps

dirknbr commented 5 months ago

sure

n = 200
df = pd.DataFrame()
df['X'] = np.random.normal(10, 1, n)
df['Tr'] = 10 + df.X + np.random.normal(0, 1, n)
df['Y'] = 10 + df.X + df.Tr + np.random.normal(0, 1, n)
gps = GPS_Regressor(treatment_grid_num = 20, random_seed = 512)
gps.fit(T = df['Tr'], X = df['X'], y = df['Y'])
gps_point = gps.point_estimate(np.array([1]))
ronikobrosly commented 5 months ago

Ok thanks @dirknbr , I'll take a look soon and get back to you 👍

ronikobrosly commented 5 months ago

Well @dirknbr , in short, numpy introduced a breaking change in some recent version. I can confirm that 3 unit tests in this package are now broken with the most recent version of numpy. Thanks for catching this!

Two options. The quicker one: I recommend you create a new virtual environment for your project work and force install a version of numpy < 1.20. This will have a cascading effect on the other dependencies and they'll end up being older versions too. The slightly more challenging one: could I get your help in patching causal-curve to work with the latest version of numpy?

dirknbr commented 5 months ago

ok will have a look whether I can fix it

dirknbr commented 5 months ago

fixed it locally and will now try to upload it, pytest passes

abhijeetdhakane commented 4 months ago

Will this fix be available in the latest Numpy version (stable)? I am also encountering the same problem.