Should we change Dataset to adaptively create the correct subclass depending on the input path?
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 25/100
Línea de trabajo
Read the Dataset, SQLiteDataset, and ParquetDataset definitions to see how they currently accept paths and arguments. Compare that design with the proposed subclass registry using __new__ and __init_subclass__, then decide whether the tradeoffs around shared constructor arguments and extension mapping are acceptable. Done means the project has a decided approach for constructing the correct dataset subclass from an input path.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
At the meeting today I mentioned that we could use hooks from __new__ and __init_subclass__ to automatically infer the desired dataset-subclass.
Currently we have two Datasets which are being used SQLiteDataset and ParquetDataset, and they both take the same inputs arguments.
I think we could overwrite __new__ and __init_subclass__ in Dataset in such a way that __init_subclass__ would make a "subclass registry", which connects file-extensions to implemented datasets, and then __new__ would look up the subclass registry and find the correct subclass to instantiate.
A "simple" illustration of how this would look like
from typing import Iterable, Union
class A:
_subclass_registry = {}
def __init__(self, arg1, arg2, kwarg1=None, kwarg2=None, *, path: str):
self.path = path
self.arg1 = arg1
self.arg2 = arg2
self.kwarg1 = kwarg1
self.kwarg2 = kwarg2
def __init_subclass__(cls, file_extensions: Union[str, Iterable[str]], **kwargs):
if isinstance(file_extensions, str):
file_extensions = [file_extensions]
for ext in file_extensions:
if ext in cls._subclass_registry:
raise ValueError(f"Duplicate file extension: {ext}")
A._subclass_registry[ext] = cls
super().__init_subclass__(**kwargs)
def __new__(cls, *args, **kwargs):
path = kwargs["path"]
file_extension = path.split(".")[-1]
subclass = cls._subclass_registry.get(file_extension, None)
if subclass is None:
raise ValueError(f"Unknown file extension: {file_extension}")
return object.__new__(subclass)
class B(A, file_extensions="ext1"):
def __init__(self, arg1, arg2, kwarg1=None, kwarg2=None, *, path: str):
super().__init__(arg1, arg2, kwarg1=kwarg1, kwarg2=kwarg2, path=path)
print(f"Created B instance with path: {self.path}")
class C(A, file_extensions=["ext2", "ext3"]):
def __init__(self, arg1, arg2, kwarg1=None, kwarg2=None, *, path: str):
super().__init__(arg1, arg2, kwarg1=kwarg1, kwarg2=kwarg2, path=path)
print(f"Created C instance with path: {self.path}")
if __name__ == "__main__":
a = A(1, 2, path="file.ext1") # Creates object from class B
b = A(3, 4, path="file.ext2") # Creates object from class C
c = A(5, 6, path="file.ext3") # Creates object from class C
print(f"{type(a)=}")
print(f"{type(b)=}")
print(f"{type(c)=}")
Pros:
- I think it would be easier for end-users to interact with the library, since they only need to create a Dataset, and don't need to worry about finding the correct subclass for their data back-end.
Cons:
- We restrict ourselves to have all datasets take the same arguments/keyword arguments
- We restrict ourselves to only have one dataset per file extension. (This can somewhat be circumvented, but it is not as elegant)
- It might be slightly more difficult to debug a dataset object, because it is not completely straightforward which subclass it is.
- Lenguaje dominante
- Python
- Estrellas
- 117
- Forks
- 115
- Merge medio
- 2 d 21 h
- PR fusionados (30 d)
- 1
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Sin plantilla de pull request
- Sin guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de graphnet-team/graphnet
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
graphnet-team/graphnet#933 ·
-
Spring cleanAbierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
graphnet-team/graphnet#927 · 1 comentario ·
-
Time for a new version release v1.8.1Quizá libre de nuevo @Aske-Rosted la tomó hace 75 días y no hay ningún pull request abierto. Abiertodecision
graphnet-team/graphnet#924 · 1 asignado ·
-
Make kaggle checkpoints part of the CIQuizá libre de nuevo @sevmag la tomó hace 75 días y no hay ningún pull request abierto. Abiertobug
graphnet-team/graphnet#921 · 2 comentarios · 1 asignado ·
-
decision deferred
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
graphnet-team/graphnet#919 ·
Todos los issues de graphnet-team/graphnet
Issues similares
-
MarkdownDocSerializer.post_process escapes '\<' to '\<', rendering literal '<' in CommonMarkAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
docling-project/docling-core#1067 ·
Los mantenedores suelen responder en 3 días
-
correction metadata
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
acl-org/acl-anthology#11101 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[BUG] crewai tool create/install/login exit 0 when they failPosiblemente ocupada @Kiko0301 la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
vllm-project/compressed-tensors#1033 ·
Los mantenedores suelen responder en 3 días
-
chore kaizen ui-rewrite
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
IBM/mcp-context-forge#7681 ·
Los mantenedores suelen responder en 2 días