From 9c42c023f61cbec9050e453f9759b1d42f0219bf Mon Sep 17 00:00:00 2001 From: Pedro Amaral Date: Wed, 28 Aug 2024 07:22:44 -0300 Subject: [PATCH] Deprecating check_spat_diag Check is done in check_weights. --- spreg/ols.py | 7 +++++-- spreg/ols_regimes.py | 7 +++++-- spreg/twosls.py | 4 ++-- spreg/twosls_regimes.py | 3 +-- spreg/twosls_sp_regimes.py | 1 - spreg/user_output.py | 6 +++--- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/spreg/ols.py b/spreg/ols.py index f532039..a88a3ea 100644 --- a/spreg/ols.py +++ b/spreg/ols.py @@ -470,12 +470,15 @@ def __init__( "White test not available when standard errors are estimated by HAC or White correction.", ) white_test = False - USER.check_spat_diag(spat_diag, w) + x_constant, name_x, warn = USER.check_constant(x, name_x) set_warn(self, warn) self.name_x = USER.set_name_x(name_x, x_constant) - w = USER.check_weights(w, y, slx_lags=slx_lags) + if spat_diag or moran: + w = USER.check_weights(w, y, slx_lags=slx_lags, w_required=True) + else: + w = USER.check_weights(w, y, slx_lags=slx_lags) if slx_lags >0: # lag_x = get_lags(w, x_constant[:, 1:], slx_lags) # x_constant = np.hstack((x_constant, lag_x)) diff --git a/spreg/ols_regimes.py b/spreg/ols_regimes.py index cc9eac9..dd6df85 100755 --- a/spreg/ols_regimes.py +++ b/spreg/ols_regimes.py @@ -436,10 +436,13 @@ def __init__( "White test not available when standard errors are estimated by HAC or White correction.", ) white_test = False - USER.check_spat_diag(spat_diag, w) + x_constant, name_x, warn = USER.check_constant(x, name_x, just_rem=True) name_x = USER.set_name_x(name_x, x_constant, constant=True) - w = USER.check_weights(w, y, slx_lags=slx_lags) + if spat_diag or moran: + w = USER.check_weights(w, y, slx_lags=slx_lags, w_required=True) + else: + w = USER.check_weights(w, y, slx_lags=slx_lags) if slx_lags > 0: lag_x = get_lags(w, x_constant, slx_lags) x_constant = np.hstack((x_constant, lag_x)) diff --git a/spreg/twosls.py b/spreg/twosls.py index c44937a..5bae2e1 100644 --- a/spreg/twosls.py +++ b/spreg/twosls.py @@ -474,10 +474,10 @@ def __init__( "Spatial diagnostics are not available for HAC estimation. The spatial diagnostics have been disabled for this model.", ) spat_diag = False - USER.check_spat_diag(spat_diag, w) + x_constant, name_x, warn = USER.check_constant(x, name_x) self.name_x = USER.set_name_x(name_x, x_constant) - w = USER.check_weights(w, y, slx_lags=slx_lags) + w = USER.check_weights(w, y, slx_lags=slx_lags, w_required=spat_diag) if slx_lags>0: # lag_x = get_lags(w, x_constant[:, 1:], slx_lags) # x_constant = np.hstack((x_constant, lag_x)) diff --git a/spreg/twosls_regimes.py b/spreg/twosls_regimes.py index abf89f8..5163fbc 100644 --- a/spreg/twosls_regimes.py +++ b/spreg/twosls_regimes.py @@ -384,11 +384,10 @@ def __init__( "Spatial diagnostics are not available for HAC estimation. The spatial diagnostics have been disabled for this model.", ) spat_diag = False - USER.check_spat_diag(spat_diag, w) x_constant, name_x, warn = USER.check_constant(x, name_x, just_rem=True) set_warn(self, warn) name_x = USER.set_name_x(name_x, x_constant, constant=True) - w = USER.check_weights(w, y, slx_lags=slx_lags) + w = USER.check_weights(w, y, slx_lags=slx_lags, w_required=spat_diag) if slx_lags > 0: lag_x = get_lags(w, x_constant, slx_lags) x_constant = np.hstack((x_constant, lag_x)) diff --git a/spreg/twosls_sp_regimes.py b/spreg/twosls_sp_regimes.py index 7749108..a427a70 100644 --- a/spreg/twosls_sp_regimes.py +++ b/spreg/twosls_sp_regimes.py @@ -503,7 +503,6 @@ def __init__( "Spatial diagnostics are not available for HAC estimation. The spatial diagnostics have been disabled for this model.", ) spat_diag = False - USER.check_spat_diag(spat_diag, w) x_constant, name_x, warn = USER.check_constant(x, name_x, just_rem=True) set_warn(self, warn) name_x = USER.set_name_x(name_x, x_constant, constant=True) diff --git a/spreg/user_output.py b/spreg/user_output.py index 34bd3e2..993058e 100755 --- a/spreg/user_output.py +++ b/spreg/user_output.py @@ -544,7 +544,7 @@ def check_weights(w, y, w_required=False, time=False, slx_lags=0): # should not raise an exception """ - if w_required == True or w != None or slx_lags > 0: + if w_required == True or (w is not None) or slx_lags > 0: if isinstance(w, graph.Graph): w = w.to_W() @@ -644,7 +644,7 @@ def check_robust(robust, wk): "invalid value passed to robust, see docs for valid options" ) - +''' Deprecated in 1.6.1 def check_spat_diag(spat_diag, w): """Check if there is a w parameter passed by the user if the user also requests spatial diagnostics. @@ -684,7 +684,7 @@ def check_spat_diag(spat_diag, w): if spat_diag: if not isinstance(w, weights.W): raise Exception("w must be a libpysal.W object to run spatial diagnostics") - +''' def check_reg_list(regimes, name_regimes, n): """Check if the regimes parameter passed by the user is a valid list of