dataenforce icon indicating copy to clipboard operation
dataenforce copied to clipboard

[Feature Request] Dataset from a dataclass

Open maxbrodin opened this issue 3 years ago • 0 comments

Would be nice to have a feature to define a Dataset using a dataclass as a source.

So, instead of

DUser = Dataset["id": int, "name": str]

def process1(data: DUser):
  pass

we can use a dataclass as a source for field names and types, like

@dataclass
class User:
  id: int
  name: str

def process1(data: Dataset[User]):
  pass

This can help to automatically update a list of fields based on the data class, and also might be useful in refactoring. Can be used like

users = pd.DataFrame(
  [
    User(id=1, name="Sam"),
    User(id=2, name="Rhett")
  ]
)

process1(users)

maxbrodin avatar Oct 26 '22 00:10 maxbrodin