@@ -24,8 +24,8 @@ def arg(cls) -> str:
24
24
return "range"
25
25
26
26
@classmethod
27
- def applicable_types (cls ) -> List [ type ] :
28
- return [ pd .Series ]
27
+ def applies_to (cls , datatype : Type [ Type ] ) -> bool :
28
+ return issubclass ( datatype , pd .Series ) # TODO -- handle dataframes?
29
29
30
30
def description (self ) -> str :
31
31
return f"Validates that the datapoint falls within the range ({ self .range [0 ]} , { self .range [1 ]} )"
@@ -69,8 +69,8 @@ def arg(cls) -> str:
69
69
return "values_in"
70
70
71
71
@classmethod
72
- def applicable_types (cls ) -> List [ type ] :
73
- return [ pd .Series ]
72
+ def applies_to (cls , datatype : Type [ Type ] ) -> bool :
73
+ return issubclass ( datatype , pd .Series ) # TODO -- handle dataframes?
74
74
75
75
def description (self ) -> str :
76
76
return f"Validates that all data points are from a fixed set of values: ({ self .values } ), ignoring NA values."
@@ -113,8 +113,8 @@ def __init__(self, range: Tuple[numbers.Real, numbers.Real], importance: str):
113
113
self .range = range
114
114
115
115
@classmethod
116
- def applicable_types (cls ) -> List [ type ] :
117
- return [ numbers .Real ]
116
+ def applies_to (cls , datatype : Type [ Type ] ) -> bool :
117
+ return issubclass ( datatype , numbers .Real )
118
118
119
119
def description (self ) -> str :
120
120
return f"Validates that the datapoint falls within the range ({ self .range [0 ]} , { self .range [1 ]} )"
@@ -151,8 +151,10 @@ def arg(cls) -> str:
151
151
return "values_in"
152
152
153
153
@classmethod
154
- def applicable_types (cls ) -> List [type ]:
155
- return [numbers .Real , str ]
154
+ def applies_to (cls , datatype : Type [Type ]) -> bool :
155
+ return issubclass (datatype , numbers .Real ) or issubclass (
156
+ datatype , str
157
+ ) # TODO support list, dict and typing.* variants
156
158
157
159
def description (self ) -> str :
158
160
return f"Validates that python values are from a fixed set of values: ({ self .values } )."
@@ -187,8 +189,8 @@ def _to_percent(fraction: float):
187
189
return "{0:.2%}" .format (fraction )
188
190
189
191
@classmethod
190
- def applicable_types (cls ) -> List [ type ] :
191
- return [ pd .Series ]
192
+ def applies_to (cls , datatype : Type [ Type ] ) -> bool :
193
+ return issubclass ( datatype , pd .Series )
192
194
193
195
def description (self ) -> str :
194
196
return f"Validates that no more than { MaxFractionNansValidatorPandasSeries ._to_percent (self .max_fraction_nans )} of the data is Nan."
@@ -249,8 +251,8 @@ def __init__(self, data_type: Type[Type], importance: str):
249
251
self .datatype = data_type
250
252
251
253
@classmethod
252
- def applicable_types (cls ) -> List [ type ] :
253
- return [ pd .Series ]
254
+ def applies_to (cls , datatype : Type [ Type ] ) -> bool :
255
+ return issubclass ( datatype , pd .Series )
254
256
255
257
def description (self ) -> str :
256
258
return f"Validates that the datatype of the pandas series is a subclass of: { self .datatype } "
@@ -280,8 +282,8 @@ def __init__(self, data_type: Type[Type], importance: str):
280
282
self .datatype = data_type
281
283
282
284
@classmethod
283
- def applicable_types (cls ) -> List [ type ] :
284
- return [ numbers .Real , str , bool , int , float , list , dict ]
285
+ def applies_to (cls , datatype : Type [ Type ] ) -> bool :
286
+ return issubclass ( datatype , numbers .Real ) or datatype in ( str , bool )
285
287
286
288
def description (self ) -> str :
287
289
return f"Validates that the datatype of the pandas series is a subclass of: { self .datatype } "
@@ -310,8 +312,8 @@ def __init__(self, max_standard_dev: float, importance: str):
310
312
self .max_standard_dev = max_standard_dev
311
313
312
314
@classmethod
313
- def applicable_types (cls ) -> List [ type ] :
314
- return [ pd .Series ]
315
+ def applies_to (cls , datatype : Type [ Type ] ) -> bool :
316
+ return issubclass ( datatype , pd .Series )
315
317
316
318
def description (self ) -> str :
317
319
return f"Validates that the standard deviation of a pandas series is no greater than : { self .max_standard_dev } "
@@ -338,8 +340,8 @@ def __init__(self, mean_in_range: Tuple[float, float], importance: str):
338
340
self .mean_in_range = mean_in_range
339
341
340
342
@classmethod
341
- def applicable_types (cls ) -> List [ type ] :
342
- return [ pd .Series ]
343
+ def applies_to (cls , datatype : Type [ Type ] ) -> bool :
344
+ return issubclass ( datatype , pd .Series )
343
345
344
346
def description (self ) -> str :
345
347
return f"Validates that a pandas series has mean in range [{ self .mean_in_range [0 ]} , { self .mean_in_range [1 ]} ]"
@@ -366,8 +368,8 @@ def __init__(self, allow_none: bool, importance: str):
366
368
self .allow_none = allow_none
367
369
368
370
@classmethod
369
- def applicable_types (cls ) -> List [ type ] :
370
- return [ Any ]
371
+ def applies_to (cls , datatype : Type [ Type ] ) -> bool :
372
+ return True
371
373
372
374
def description (self ) -> str :
373
375
if self .allow_none :
0 commit comments