Skip to content

Commit

Permalink
consolidate engine internal naming
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Francois Zinque committed May 12, 2021
1 parent 96ea9b7 commit ec23e0c
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions pandera/engines/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

@dataclass
class _DtypeRegistry:
dispatcher: Callable[[Any], DataType]
lookup: Dict[Any, Type[DataType]]
dispatch: Callable[[Any], DataType]
equivalents: Dict[Any, Type[DataType]]


class Engine(ABCMeta):
Expand All @@ -38,7 +38,7 @@ def __new__(mcs, name, bases, namespace, **kwargs):
def dtype(obj: Any) -> DataType:
raise ValueError(f"Data type '{obj}' not understood")

mcs._registry[cls] = _DtypeRegistry(dispatcher=dtype, lookup={})
mcs._registry[cls] = _DtypeRegistry(dispatch=dtype, equivalents={})
return cls

def _check_source_dtype(cls, obj: Any) -> None:
Expand All @@ -64,17 +64,17 @@ def _method(*args, **kwargs):

for source_dtype in dtypes:
cls._check_source_dtype(source_dtype)
cls._registry[cls].dispatcher.register(source_dtype, _method)
cls._registry[cls].dispatch.register(source_dtype, _method)

def _register_lookup(
def _register_equivalents(
cls,
target_dtype: Union[DataType, Type[DataType]],
*source_dtypes: Any,
) -> None:
value = target_dtype()
for source_dtype in source_dtypes:
cls._check_source_dtype(source_dtype)
cls._registry[cls].lookup[source_dtype] = value
cls._registry[cls].equivalents[source_dtype] = value

def register_dtype(
cls,
Expand All @@ -100,7 +100,7 @@ def _wrapper(dtype: Union[DataType, Type[DataType]]):
)

if equivalents:
cls._register_lookup(dtype, *equivalents)
cls._register_equivalents(dtype, *equivalents)

from_parametrized_dtype = dtype.__dict__.get(
"from_parametrized_dtype"
Expand Down Expand Up @@ -145,12 +145,12 @@ def dtype(cls, obj: Any) -> DataType:

registry = cls._registry[cls]

data_type = registry.lookup.get(obj)
data_type = registry.equivalents.get(obj)
if data_type is not None:
return data_type

try:
return registry.dispatcher(obj)
return registry.dispatch(obj)
except (KeyError, ValueError):
raise TypeError(
f"Data type '{obj}' not understood by {cls.__name__}."
Expand Down

0 comments on commit ec23e0c

Please sign in to comment.