Skip to content

Commit 222d509

Browse files
Migrate to modern Python Logger API (#8449)
### Description This PR resolves the deprecation warnings of the `logger` library: ```python DeprecationWarning: The 'warn' method is deprecated, use 'warning' instead ``` ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. Signed-off-by: Emmanuel Ferdman <[email protected]> Co-authored-by: Eric Kerfoot <[email protected]>
1 parent bf6bc1f commit 222d509

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

monai/apps/auto3dseg/auto_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ def set_device_info(
570570
self.device_setting["CUDA_VISIBLE_DEVICES"] = ",".join([str(x) for x in cuda_visible_devices])
571571
self.device_setting["n_devices"] = len(cuda_visible_devices)
572572
else:
573-
logger.warn(f"Wrong format of cuda_visible_devices {cuda_visible_devices}, devices not set")
573+
logger.warning(f"Wrong format of cuda_visible_devices {cuda_visible_devices}, devices not set")
574574

575575
if num_nodes is None:
576576
num_nodes = int(os.environ.get("NUM_NODES", 1))

monai/bundle/workflows.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def add_property(self, name: str, required: str, desc: str | None = None) -> Non
226226
if self.properties is None:
227227
self.properties = {}
228228
if name in self.properties:
229-
logger.warn(f"property '{name}' already exists in the properties list, overriding it.")
229+
logger.warning(f"property '{name}' already exists in the properties list, overriding it.")
230230
self.properties[name] = {BundleProperty.DESC: desc, BundleProperty.REQUIRED: required}
231231

232232
def check_properties(self) -> list[str] | None:
@@ -421,7 +421,7 @@ def __init__(
421421
for _config_file in _config_files:
422422
_config_file = Path(_config_file)
423423
if _config_file.parent != config_root_path:
424-
logger.warn(
424+
logger.warning(
425425
f"Not all config files are in {config_root_path}. If logging_file and meta_file are"
426426
f"not specified, {config_root_path} will be used as the default config root directory."
427427
)
@@ -434,11 +434,11 @@ def __init__(
434434
self.config_root_path = config_root_path
435435
logging_file = str(self.config_root_path / "logging.conf") if logging_file is None else logging_file
436436
if logging_file is False:
437-
logger.warn(f"Logging file is set to {logging_file}, skipping logging.")
437+
logger.warning(f"Logging file is set to {logging_file}, skipping logging.")
438438
else:
439439
if not os.path.isfile(logging_file):
440440
if logging_file == str(self.config_root_path / "logging.conf"):
441-
logger.warn(f"Default logging file in {logging_file} does not exist, skipping logging.")
441+
logger.warning(f"Default logging file in {logging_file} does not exist, skipping logging.")
442442
else:
443443
raise FileNotFoundError(f"Cannot find the logging config file: {logging_file}.")
444444
else:
@@ -503,17 +503,17 @@ def check_properties(self) -> list[str] | None:
503503
"""
504504
ret = super().check_properties()
505505
if self.properties is None:
506-
logger.warn("No available properties had been set, skipping check.")
506+
logger.warning("No available properties had been set, skipping check.")
507507
return None
508508
if ret:
509-
logger.warn(f"Loaded bundle does not contain the following required properties: {ret}")
509+
logger.warning(f"Loaded bundle does not contain the following required properties: {ret}")
510510
# also check whether the optional properties use correct ID name if existing
511511
wrong_props = []
512512
for n, p in self.properties.items():
513513
if not p.get(BundleProperty.REQUIRED, False) and not self._check_optional_id(name=n, property=p):
514514
wrong_props.append(n)
515515
if wrong_props:
516-
logger.warn(f"Loaded bundle defines the following optional properties with wrong ID: {wrong_props}")
516+
logger.warning(f"Loaded bundle defines the following optional properties with wrong ID: {wrong_props}")
517517
if ret is not None:
518518
ret.extend(wrong_props)
519519
return ret

0 commit comments

Comments
 (0)