CedricFR / dataenforce

Python package to enforce column names & data types of pandas DataFrames
Apache License 2.0
212 stars 9 forks source link

Type annotations for index & multi-index [feature request] #2

Open WestXu opened 4 years ago

WestXu commented 4 years ago

--which would be rather useful.

Cool project. Thanks.

CedricFR commented 4 years ago

Thank you for the suggestion @WestXu

I'll have a look at what can be done and how it can fit into the current syntax. Don't hesitate to elaborate on this feature request if you have a specific idea on how it should work (esp. regarding multi-index).

WestXu commented 4 years ago

I'm not professional at exactly how type annotation works in python, buy maybe this syntax is possible:

from dataenforce import Dataset, DataIndex

# index
Dataset[DataIndex["id": int], "name": object, "latitude": float, "longitude": float]

# multiindex
Dataset[DataIndex["date": "timestamp", "id": int], "name": object, "latitude": float, "longitude": float]
WestXu commented 4 years ago

Also consider this:

from dataenforce import Dataset, DataIndex, DataColumns

Dataset[
    "index": DataIndex["date": "timestamp", "id": int], 
    "columns": DataColumns["name": object, "latitude": float, "longitude": float]
]
qiuwei commented 3 years ago

Support for pandas Series is appreciated!

Marco-Christiani commented 2 years ago

Also consider this:

from dataenforce import Dataset, DataIndex, DataColumns

Dataset[
    "index": DataIndex["date": "timestamp", "id": int], 
    "columns": DataColumns["name": object, "latitude": float, "longitude": float]
]

This is a great solution