Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update some pipeline images (macos-12, ubuntu20), fix pycodestyle E275 #672

Merged
merged 4 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion azure-pipelines-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

parameters:
package: '-e .'
images: ['ubuntu-18.04', 'macOS-10.15', 'windows-2019']
images: ['ubuntu-20.04', 'macOS-12', 'windows-2019']
versions: ['3.6', '3.7', '3.8', '3.9']
job:
job: Job
Expand Down
14 changes: 7 additions & 7 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- job: 'EvalChanges'
displayName: 'Analyze changed files to determine which job to run'
pool:
vmImage: 'macOS-10.15'
vmImage: 'macos-12'
steps:
# We want to enforce the following rules for PRs:
# * if all modifications are to README.md
Expand Down Expand Up @@ -54,7 +54,7 @@ jobs:
- template: azure-pipelines-steps.yml
parameters:
versions: ['3.8']
images: ['ubuntu-18.04']
images: ['ubuntu-20.04']
package: '-e .[all]'
job:
job: 'Docs'
Expand Down Expand Up @@ -88,7 +88,7 @@ jobs:
- template: azure-pipelines-steps.yml
parameters:
versions: ['3.8']
images: ['ubuntu-18.04']
images: ['ubuntu-20.04']
package: '-e .[tf,plt]'
job:
job: 'Notebooks_cust'
Expand Down Expand Up @@ -116,7 +116,7 @@ jobs:
- template: azure-pipelines-steps.yml
parameters:
versions: ['3.8']
images: ['ubuntu-18.04']
images: ['ubuntu-20.04']
package: '-e .[tf,plt]'
job:
job: 'Notebooks_noncust'
Expand Down Expand Up @@ -148,7 +148,7 @@ jobs:
# variables:
# python.version: '3.6'
# pool:
# vmImage: 'ubuntu-18.04'
# vmImage: 'ubuntu-20.04'
# steps:
# - template: azure-pipelines-steps.yml
# parameters:
Expand Down Expand Up @@ -180,7 +180,7 @@ jobs:
- template: azure-pipelines-steps.yml
parameters:
versions: ['3.8']
images: ['macOS-10.15']
images: ['macos-12']
job:
job: 'Linting'
dependsOn: 'EvalChanges'
Expand Down Expand Up @@ -247,7 +247,7 @@ jobs:
- template: azure-pipelines-steps.yml
parameters:
# exclude macOS since these tests frequently break there
images: ['ubuntu-18.04', 'windows-2019']
images: ['ubuntu-20.04', 'windows-2019']
package: '-e .[tf,plt]'
job:
job: Tests_serial
Expand Down
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
'sklearn': ('https://scikit-learn.org/stable/', None),
'matplotlib': ('https://matplotlib.org/', None),
'shap': ('https://shap.readthedocs.io/en/stable/', None),
'dowhy': ('https://py-why.github.io/dowhy/', None)}
'dowhy': ('https://py-why.github.io/dowhy/v0.8/', None)}


# -- Options for todo extension ----------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions econml/automated_ml/_automated_ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def setAutomatedMLWorkspace(create_workspace=False,
ws.write_config()
print("Workspace configuration has succeeded.")
except ProjectSystemException:
if(create_workspace):
if(create_resource_group):
if (create_workspace):
if (create_resource_group):
print("Workspace not accessible. Creating a new workspace and \
resource group.")
ws = Workspace.create(name=workspace_name,
Expand Down Expand Up @@ -351,9 +351,9 @@ def __init__(self, sample_weights_required=False, linear_model_required=False, s
whitelist_models = list(LINEAR_MODELS_SET.intersection(SAMPLE_WEIGHTS_MODELS_SET))

else:
if(linear_model_required):
if (linear_model_required):
whitelist_models = list(LINEAR_MODELS_SET)
if(sample_weights_required):
if (sample_weights_required):
whitelist_models = list(SAMPLE_WEIGHTS_MODELS_SET)

kwargs['whitelist_models'] = whitelist_models
Expand Down
2 changes: 1 addition & 1 deletion econml/iv/nnet/_deepiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def response_loss_model(h, p, d_z, d_x, d_y, samples=1, use_upper_bound=False, g
A Keras model that takes as inputs z, x, and y and generates a single output containing the loss.

"""
assert not(use_upper_bound and gradient_samples)
assert not (use_upper_bound and gradient_samples)

# sample: (() -> Layer, int) -> Layer
def sample(f, n):
Expand Down
14 changes: 7 additions & 7 deletions econml/tests/test_dml.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def make_random(n, is_discrete, d):
# since T isn't passed to const_marginal_effect, defaults to one row if X is None
const_marginal_effect_shape = ((n if d_x else 1,) +
((d_y,) if d_y > 0 else ()) +
((d_t_final,) if d_t_final > 0 else()))
((d_t_final,) if d_t_final > 0 else ()))
const_marginal_effect_summaryframe_shape = (
(n if d_x else 1) * (d_y if d_y > 0 else 1) *
(d_t_final if d_t_final > 0 else 1), 6)
Expand Down Expand Up @@ -159,7 +159,7 @@ def make_random(n, is_discrete, d):
True,
['auto', 'blb'])]:

if not(multi) and d_y > 1:
if not (multi) and d_y > 1:
continue

if X is None and isinstance(est, CausalForestDML):
Expand Down Expand Up @@ -326,7 +326,7 @@ def make_random(n, is_discrete, d):

if isinstance(est, CausalForestDML):
np.testing.assert_array_equal(est.feature_importances_.shape,
((d_y,) if d_y > 0 else()) + fd_x)
((d_y,) if d_y > 0 else ()) + fd_x)

# make sure we can call effect with implied scalar treatments,
# no matter the dimensions of T, and also that we warn when there
Expand All @@ -337,7 +337,7 @@ def make_random(n, is_discrete, d):
# ExitStack can be used as a "do nothing" ContextManager
cm = ExitStack()
with cm:
effect_shape2 = (n if d_x else 1,) + ((d_y,) if d_y > 0 else())
effect_shape2 = (n if d_x else 1,) + ((d_y,) if d_y > 0 else ())
eff = est.effect(X) if not is_discrete else est.effect(
X, T0='a', T1='b')
self.assertEqual(shape(eff), effect_shape2)
Expand Down Expand Up @@ -383,7 +383,7 @@ def make_random(is_discrete, d):
# since T isn't passed to const_marginal_effect, defaults to one row if X is None
const_marginal_effect_shape = ((n if d_x else 1,) +
((d_y,) if d_y > 0 else ()) +
((d_t_final,) if d_t_final > 0 else()))
((d_t_final,) if d_t_final > 0 else ()))
const_marginal_effect_summaryframe_shape = (
(n if d_x else 1) * (d_y if d_y > 0 else 1) * (d_t_final if d_t_final > 0 else 1), 6)

Expand All @@ -405,7 +405,7 @@ def make_random(is_discrete, d):
True,
base_infs), ]:

if not(multi) and d_y > 1:
if not (multi) and d_y > 1:
continue

for inf in infs:
Expand Down Expand Up @@ -512,7 +512,7 @@ def make_random(is_discrete, d):
else:
cm = ExitStack() # ExitStack can be used as a "do nothing" ContextManager
with cm:
effect_shape2 = (n if d_x else 1,) + ((d_y,) if d_y > 0 else())
effect_shape2 = (n if d_x else 1,) + ((d_y,) if d_y > 0 else ())
eff = est.effect(X) if not is_discrete else est.effect(X, T0='a', T1='b')
self.assertEqual(shape(eff), effect_shape2)

Expand Down
4 changes: 2 additions & 2 deletions econml/tests/test_drlearner.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def make_random(is_discrete, d):
# since T isn't passed to const_marginal_effect, defaults to one row if X is None
const_marginal_effect_shape = ((n if d_x else 1,) +
((d_y,) if d_y > 0 else ()) +
((d_t_final,) if d_t_final > 0 else()))
((d_t_final,) if d_t_final > 0 else ()))
const_marginal_effect_summaryframe_shape = (
(n if d_x else 1) * (d_y if d_y > 0 else 1) * (d_t_final if d_t_final > 0 else 1), 6)

Expand Down Expand Up @@ -261,7 +261,7 @@ def make_random(is_discrete, d):
cm = ExitStack() # ExitStack can be used as a "do nothing" ContextManager
with cm:
effect_shape2 = (
n if d_x else 1,) + ((d_y,) if d_y > 0 else())
n if d_x else 1,) + ((d_y,) if d_y > 0 else ())
eff = est.effect(X, T0='a', T1='b')
self.assertEqual(
shape(eff), effect_shape2)
Expand Down
4 changes: 2 additions & 2 deletions econml/tests/test_dynamic_dml.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def make_random(n, is_discrete, d):
# since T isn't passed to const_marginal_effect, defaults to one row if X is None
const_marginal_effect_shape = ((n if d_x else 1,) +
((d_y,) if d_y > 0 else ()) +
((d_t_final,) if d_t_final > 0 else()))
((d_t_final,) if d_t_final > 0 else ()))
const_marginal_effect_summaryframe_shape = (
(n if d_x else 1) * (d_y if d_y > 0 else 1) *
(d_t_final if d_t_final > 0 else 1), 6)
Expand Down Expand Up @@ -247,7 +247,7 @@ def make_random(n, is_discrete, d):
# ExitStack can be used as a "do nothing" ContextManager
cm = ExitStack()
with cm:
effect_shape2 = (n if d_x else 1,) + ((d_y,) if d_y > 0 else())
effect_shape2 = (n if d_x else 1,) + ((d_y,) if d_y > 0 else ())
eff = est.effect(X) if not is_discrete else est.effect(
X, T0='a', T1='b')
self.assertEqual(shape(eff), effect_shape2)
Expand Down
6 changes: 3 additions & 3 deletions econml/tests/test_two_stage_least_squares.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ def test_hermite_results(self):
# first polynomials are 1, x, x*x-1, x*x*x-3*x
ones = np.ones(shape(inputs))
polys = np.hstack([ones, inputs, inputs * inputs - ones, inputs * inputs * inputs - 3 * inputs])
assert(np.allclose(hf, polys * np.exp(-inputs * inputs / 2)))
assert (np.allclose(hf, polys * np.exp(-inputs * inputs / 2)))

for j in [True, False]:
hf = HermiteFeatures(1, shift=1, joint=j).fit_transform(inputs)
# first derivatives are -x, -x^2+1 (since there's just one column, joint-ness doesn't matter)
polys = np.hstack([-inputs, -inputs * inputs + ones])
assert(np.allclose(hf, reshape(polys * np.exp(-inputs * inputs / 2), (5, 1, 2))))
assert (np.allclose(hf, reshape(polys * np.exp(-inputs * inputs / 2), (5, 1, 2))))

@pytest.mark.slow
def test_hermite_approx(self):
Expand Down Expand Up @@ -87,7 +87,7 @@ def make_random(d):
effect_shape = (n,) + ((d_y,) if d_y > 0 else ())
marginal_effect_shape = ((n if d_x else 1,) +
((d_y,) if d_y > 0 else ()) +
((d_t,) if d_t > 0 else()))
((d_t,) if d_t > 0 else ()))

self.assertEqual(shape(marg_eff), marginal_effect_shape)
self.assertEqual(shape(eff), effect_shape)
Expand Down
6 changes: 3 additions & 3 deletions econml/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,10 @@ def reshape_Y_T(Y, T):
Reshaped treatment policy.

"""
assert(len(Y) == len(T))
assert(Y.ndim <= 2)
assert (len(Y) == len(T))
assert (Y.ndim <= 2)
if Y.ndim == 2:
assert(Y.shape[1] == 1)
assert (Y.shape[1] == 1)
Y = Y.flatten()
if T.ndim == 1:
T = T.reshape(-1, 1)
Expand Down