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

Improved the syntax of the fstrings (#4294)

parent d6fc12b3
...@@ -29,7 +29,8 @@ def find_lib_path(): ...@@ -29,7 +29,8 @@ def find_lib_path():
lib_path = [p for p in dll_path if os.path.exists(p) and os.path.isfile(p)] lib_path = [p for p in dll_path if os.path.exists(p) and os.path.isfile(p)]
if not lib_path: if not lib_path:
dll_path = [os.path.realpath(p) for p in dll_path] dll_path = [os.path.realpath(p) for p in dll_path]
raise Exception('Cannot find lightgbm library file in following paths:\n' + '\n'.join(dll_path)) dll_path_joined = '\n'.join(dll_path)
raise Exception(f'Cannot find lightgbm library file in following paths:\n{dll_path_joined}')
return lib_path return lib_path
...@@ -74,7 +75,7 @@ def load_from_file(filename, reference): ...@@ -74,7 +75,7 @@ def load_from_file(filename, reference):
LIB.LGBM_DatasetGetNumData(handle, ctypes.byref(num_data)) LIB.LGBM_DatasetGetNumData(handle, ctypes.byref(num_data))
num_feature = ctypes.c_long() num_feature = ctypes.c_long()
LIB.LGBM_DatasetGetNumFeature(handle, ctypes.byref(num_feature)) LIB.LGBM_DatasetGetNumFeature(handle, ctypes.byref(num_feature))
print('#data: %d #feature: %d' % (num_data.value, num_feature.value)) print(f'#data: {num_data.value} #feature: {num_feature.value}')
return handle return handle
...@@ -115,7 +116,7 @@ def load_from_csr(filename, reference): ...@@ -115,7 +116,7 @@ def load_from_csr(filename, reference):
num_feature = ctypes.c_long() num_feature = ctypes.c_long()
LIB.LGBM_DatasetGetNumFeature(handle, ctypes.byref(num_feature)) LIB.LGBM_DatasetGetNumFeature(handle, ctypes.byref(num_feature))
LIB.LGBM_DatasetSetField(handle, c_str('label'), c_array(ctypes.c_float, label), len(label), 0) LIB.LGBM_DatasetSetField(handle, c_str('label'), c_array(ctypes.c_float, label), len(label), 0)
print('#data: %d #feature: %d' % (num_data.value, num_feature.value)) print(f'#data: {num_data.value} #feature: {num_feature.value}')
return handle return handle
...@@ -152,7 +153,7 @@ def load_from_csc(filename, reference): ...@@ -152,7 +153,7 @@ def load_from_csc(filename, reference):
num_feature = ctypes.c_long() num_feature = ctypes.c_long()
LIB.LGBM_DatasetGetNumFeature(handle, ctypes.byref(num_feature)) LIB.LGBM_DatasetGetNumFeature(handle, ctypes.byref(num_feature))
LIB.LGBM_DatasetSetField(handle, c_str('label'), c_array(ctypes.c_float, label), len(label), 0) LIB.LGBM_DatasetSetField(handle, c_str('label'), c_array(ctypes.c_float, label), len(label), 0)
print('#data: %d #feature: %d' % (num_data.value, num_feature.value)) print(f'#data: {num_data.value} #feature: {num_feature.value}')
return handle return handle
...@@ -186,7 +187,7 @@ def load_from_mat(filename, reference): ...@@ -186,7 +187,7 @@ def load_from_mat(filename, reference):
num_feature = ctypes.c_long() num_feature = ctypes.c_long()
LIB.LGBM_DatasetGetNumFeature(handle, ctypes.byref(num_feature)) LIB.LGBM_DatasetGetNumFeature(handle, ctypes.byref(num_feature))
LIB.LGBM_DatasetSetField(handle, c_str('label'), c_array(ctypes.c_float, label), len(label), 0) LIB.LGBM_DatasetSetField(handle, c_str('label'), c_array(ctypes.c_float, label), len(label), 0)
print('#data: %d #feature: %d' % (num_data.value, num_feature.value)) print(f'#data: {num_data.value} #feature: {num_feature.value}')
return handle return handle
...@@ -234,7 +235,7 @@ def test_booster(): ...@@ -234,7 +235,7 @@ def test_booster():
ctypes.byref(out_len), ctypes.byref(out_len),
result.ctypes.data_as(ctypes.POINTER(ctypes.c_double))) result.ctypes.data_as(ctypes.POINTER(ctypes.c_double)))
if i % 10 == 0: if i % 10 == 0:
print('%d iteration test AUC %f' % (i, result[0])) print(f'{i} iteration test AUC {result[0]:.6f}')
LIB.LGBM_BoosterSaveModel(booster, 0, -1, 0, c_str('model.txt')) LIB.LGBM_BoosterSaveModel(booster, 0, -1, 0, c_str('model.txt'))
LIB.LGBM_BoosterFree(booster) LIB.LGBM_BoosterFree(booster)
free_dataset(train) free_dataset(train)
......
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