Skip to content

Commit 7792b77

Browse files
lucmosjustusschockpre-commit-ci[bot]
authored
Resolve: 'DummyExperiment' object does not support item assignment (#10917)
Co-authored-by: Justus Schock <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 6fe3211 commit 7792b77

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
240240
- Fixed a bug that caused incorrect batch indices to be passed to the `BasePredictionWriter` hooks when using a dataloader with `num_workers > 0` ([#10870](https://github.com/PyTorchLightning/pytorch-lightning/pull/10870))
241241

242242

243-
-
243+
- Fixed an issue with item assignment on the logger on rank > 0 for those who support it ([#10917](https://github.com/PyTorchLightning/pytorch-lightning/pull/10917))
244244

245245

246246

pytorch_lightning/loggers/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,9 @@ def __getitem__(self, idx) -> "DummyExperiment":
474474
# enables self.logger.experiment[0].add_image(...)
475475
return self
476476

477+
def __setitem__(self, *args, **kwargs) -> None:
478+
pass
479+
477480

478481
class DummyLogger(LightningLoggerBase):
479482
"""Dummy logger for internal use.

tests/loggers/test_base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,13 @@ def test_dummylogger_noop_method_calls():
241241
logger.log_metrics("1", 2, three="three")
242242

243243

244+
def test_dummyexperiment_support_item_assignment():
245+
"""Test that the DummyExperiment supports item assignment."""
246+
experiment = DummyExperiment()
247+
experiment["variable"] = "value"
248+
assert experiment["variable"] != "value" # this is only a stateless mock experiment
249+
250+
244251
def test_np_sanitization():
245252
class CustomParamsLogger(CustomLogger):
246253
def __init__(self):

0 commit comments

Comments
 (0)