Skip to content

Commit cb50588

Browse files
committed
Use typing Dict/List for 3.8 support
1 parent deece9d commit cb50588

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

dataqa/column_mapping.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional
1+
from typing import Optional, List
22

33
from dataclasses import dataclass
44

@@ -21,11 +21,11 @@ class PredictionColumn:
2121

2222
@dataclass
2323
class ColumnMapping:
24-
numerical_columns: Optional[list[str]] = None
25-
categorical_columns: Optional[list[str]] = None
26-
text_columns: Optional[list[str]] = None
27-
time_columns: Optional[list[str]] = None
28-
prediction_columns: Optional[list[PredictionColumn]] = None
24+
numerical_columns: Optional[List[str]] = None
25+
categorical_columns: Optional[List[str]] = None
26+
text_columns: Optional[List[str]] = None
27+
time_columns: Optional[List[str]] = None
28+
prediction_columns: Optional[List[PredictionColumn]] = None
2929

3030

3131
class ColumnType:

dataqa/infer_schema.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections import defaultdict
2-
from typing import Any, Optional, Union
2+
from typing import Any, Dict, Optional, Union, List
33

44
import numpy as np
55
import pandas as pd
@@ -25,11 +25,11 @@ def is_column_categorical(values: pd.Series) -> bool:
2525

2626
def infer_schema(
2727
df: pd.DataFrame,
28-
numerical_columns: Optional[list[str]] = None,
29-
categorical_columns: Optional[list[str]] = None,
30-
text_columns: Optional[list[str]] = None,
31-
time_columns: Optional[list[str]] = None,
32-
prediction_columns: Optional[list[PredictionColumn]] = None,
28+
numerical_columns: Optional[List[str]] = None,
29+
categorical_columns: Optional[List[str]] = None,
30+
text_columns: Optional[List[str]] = None,
31+
time_columns: Optional[List[str]] = None,
32+
prediction_columns: Optional[List[PredictionColumn]] = None,
3333
) -> ColumnMapping:
3434
"""
3535
The keyword arguments will take precedence over the inferred schema.
@@ -159,8 +159,8 @@ def check_all_columns_in_df(df: pd.DataFrame, column_mapping: ColumnMapping):
159159

160160

161161
def check_categorical_columns(
162-
df: pd.DataFrame, categorical_columns: list[str]
163-
) -> dict[str, list[Union[str, np.number]]]:
162+
df: pd.DataFrame, categorical_columns: List[str]
163+
) -> Dict[str, List[Union[str, np.number]]]:
164164
"""
165165
Make sure the dtype is numeric or string (not mixed) and that unique categories <= MAX_CATEGORICAL_UNIQUE
166166
"""
@@ -184,33 +184,33 @@ def check_categorical_columns(
184184
return column_to_categories
185185

186186

187-
def check_numerical_columns(df: pd.DataFrame, numerical_columns: list[str]):
187+
def check_numerical_columns(df: pd.DataFrame, numerical_columns: List[str]):
188188
for column in numerical_columns:
189189
if not pd.api.types.is_numeric_dtype(df[column].dtype):
190190
raise Exception(f"Column {column} is not of type numerical.")
191191

192192

193-
def check_text_columns(df: pd.DataFrame, text_columns: list[str]):
193+
def check_text_columns(df: pd.DataFrame, text_columns: List[str]):
194194
for column in text_columns:
195195
if not pd.api.types.infer_dtype(df[column], skipna=True) == "string":
196196
raise Exception(f"Text column {column} is not of type string.")
197197

198198

199-
def check_time_columns(df: pd.DataFrame, time_columns: list[str]):
199+
def check_time_columns(df: pd.DataFrame, time_columns: List[str]):
200200
for column in time_columns:
201201
try:
202202
_ = pd.to_datetime(df[column], errors="raise")
203203
except:
204204
raise Exception(f"Column {column} cannot be cast to a datetime.")
205205

206206

207-
def is_subset(list1: list[Any], list2: list[Any]) -> bool:
207+
def is_subset(list1: List[Any], list2: List[Any]) -> bool:
208208
return len(set(list1).difference(set(list2))) == 0
209209

210210

211211
def check_prediction_columns(
212212
column_mapping: ColumnMapping,
213-
column_to_categories: dict[str, list[Union[str, np.number]]],
213+
column_to_categories: Dict[str, List[Union[str, np.number]]],
214214
) -> dict:
215215
schema_dict = dict(
216216
(column, {"type": ColumnType.CATEGORICAL})
@@ -297,8 +297,8 @@ def check_prediction_columns(
297297
def format_validated_schema(
298298
df: pd.DataFrame,
299299
schema_dict: dict,
300-
prediction_columns: list[PredictionColumn],
301-
column_to_categories: dict[str, list[Union[str, np.number]]],
300+
prediction_columns: List[PredictionColumn],
301+
column_to_categories: Dict[str, List[Union[str, np.number]]],
302302
) -> dict:
303303
new_schema = []
304304
prediction_columns_dict = {

dataqa/publish.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from getpass import getpass
22
import json
33
import requests
4-
from typing import Optional
4+
from typing import Optional, List, Dict
55

66
import pandas as pd
77

@@ -30,7 +30,7 @@ def login(self):
3030

3131
self.auth_token = response.json()["token"]
3232

33-
def create_release(self, project_id: str, column_mapping: list[dict]) -> str:
33+
def create_release(self, project_id: str, column_mapping: List[Dict]) -> str:
3434
response = requests.post(
3535
self.api_url + "/api/v1/release/",
3636
headers={

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "dataqa"
3-
version = "2.0.1"
3+
version = "2.0.3"
44
description = "Python Client library for DataQA"
55
authors = ["Maria Mestre <maria@dataqa.ai>","Stuart Quin <stuart@dataqa.ai>"]
66
readme = "README.md"

0 commit comments

Comments
 (0)