Skip to content

Commit

Permalink
fix: DataCollector versioning deprecation (#173)
Browse files Browse the repository at this point in the history
* fix datacollector deprecation

* fix number of warnings

* fix pre-commit

* remove unused import

* remove comment
  • Loading branch information
younik authored Dec 7, 2023
1 parent b6035a7 commit e24113b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions minari/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ def __getattr__(name):
if name == "DataCollectorV0":
from minari.data_collector import DataCollectorV0
return DataCollectorV0
else:
raise ImportError(f"cannot import name '{name}' from '{__name__}' ({__file__})")
2 changes: 2 additions & 0 deletions minari/data_collector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ def __getattr__(name):
if name == "DataCollectorV0":
from minari.data_collector.data_collector import DataCollectorV0
return DataCollectorV0
else:
raise ImportError(f"cannot import name '{name}' from '{__name__}' ({__file__})")
15 changes: 10 additions & 5 deletions minari/data_collector/data_collector.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import copy
import inspect
import os
import secrets
import shutil
Expand Down Expand Up @@ -29,11 +30,15 @@
EpisodeBuffer = Dict[str, Any] # TODO: narrow this down


class DataCollectorV0:
warnings.warn("DataCollectorV0 is deprecated and will be removed. Use DataCollector instead.", DeprecationWarning, stacklevel=5)

def __new__(cls, *args, **kwargs):
return DataCollector(*args, **kwargs)
def __getattr__(name):
if name == "DataCollectorV0":
stacklevel = len(inspect.stack(0))
warnings.warn("DataCollectorV0 is deprecated and will be removed. Use DataCollector instead.", DeprecationWarning, stacklevel=stacklevel)
return DataCollector
elif name == "__path__":
return False # see https://stackoverflow.com/a/60803436
else:
raise ImportError(f"cannot import name '{name}' from '{__name__}' ({__file__})")


class DataCollector(gym.Wrapper):
Expand Down

0 comments on commit e24113b

Please sign in to comment.