Unverified Commit d677d6c6 authored by sayantan sadhu's avatar sayantan sadhu Committed by GitHub
Browse files

[python] improving the syntax of the fstring in the file :...


[python] improving the syntax of the fstring in the file : tests/python_package_test/test_dask.py (#4358)

* updated the old syntax with fstrings

* Updated the strings with + catenation to fstrings

* Updated the strings with + catenation to fstrings

* Update tests/python_package_test/test_dask.py
Co-authored-by: default avatarJames Lamb <jaylamb20@gmail.com>
parent 9143003d
......@@ -95,7 +95,7 @@ def _create_ranking_data(n_samples=100, output='array', chunk_size=50, **kwargs)
X_df = pd.DataFrame(X, columns=[f'feature_{i}' for i in range(X.shape[1])])
if output == 'dataframe-with-categorical':
for i in range(5):
col_name = "cat_col" + str(i)
col_name = f"cat_col{i}"
cat_values = rnd.choice(['a', 'b'], X.shape[0])
cat_series = pd.Series(
cat_values,
......@@ -159,7 +159,7 @@ def _create_data(objective, n_samples=1_000, output='array', chunk_size=500, **k
**kwargs
)
else:
raise ValueError("Unknown objective '%s'" % objective)
raise ValueError(f"Unknown objective '{objective}'")
rnd = np.random.RandomState(42)
weights = rnd.random(X.shape[0]) * 0.01
......@@ -168,11 +168,11 @@ def _create_data(objective, n_samples=1_000, output='array', chunk_size=500, **k
dy = da.from_array(y, chunk_size)
dw = da.from_array(weights, chunk_size)
elif output.startswith('dataframe'):
X_df = pd.DataFrame(X, columns=['feature_%d' % i for i in range(X.shape[1])])
X_df = pd.DataFrame(X, columns=[f'feature_{i}' for i in range(X.shape[1])])
if output == 'dataframe-with-categorical':
num_cat_cols = 2
for i in range(num_cat_cols):
col_name = "cat_col" + str(i)
col_name = f"cat_col{i}"
cat_values = rnd.choice(['a', 'b'], X.shape[0])
cat_series = pd.Series(
cat_values,
......@@ -199,7 +199,7 @@ def _create_data(objective, n_samples=1_000, output='array', chunk_size=500, **k
dy = da.from_array(y, chunks=chunk_size)
dw = da.from_array(weights, chunk_size)
else:
raise ValueError("Unknown output type '%s'" % output)
raise ValueError("Unknown output type '{output}'")
return X, y, weights, None, dX, dy, dw, None
......@@ -1105,7 +1105,7 @@ def test_network_params_not_required_but_respected_if_given(task, listen_port, c
n_estimators=5,
num_leaves=5,
machines=",".join([
"127.0.0.1:" + str(port)
f"127.0.0.1:{port}"
for port in open_ports
]),
)
......@@ -1151,14 +1151,14 @@ def test_machines_should_be_used_if_provided(task, cluster):
n_estimators=5,
num_leaves=5,
machines=",".join([
"127.0.0.1:" + str(port)
f"127.0.0.1:{port}"
for port in open_ports
]),
)
# test that "machines" is actually respected by creating a socket that uses
# one of the ports mentioned in "machines"
error_msg = "Binding port %s failed" % open_ports[0]
error_msg = f"Binding port {open_ports[0]} failed"
with pytest.raises(lgb.basic.LightGBMError, match=error_msg):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(('127.0.0.1', open_ports[0]))
......@@ -1171,7 +1171,7 @@ def test_machines_should_be_used_if_provided(task, cluster):
one_open_port = lgb.dask._find_random_open_port()
dask_model.set_params(
machines=",".join([
"127.0.0.1:" + str(one_open_port)
f"127.0.0.1:{one_open_port}"
for _ in range(n_workers)
])
)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment