Skip to content

Commit

Permalink
[WIP} Fix type annotation in pandas/core/api (pandas-dev#26341)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaibhavhrt authored and jreback committed May 12, 2019
1 parent 8747be1 commit 4e4f5bd
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 22 deletions.
3 changes: 0 additions & 3 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ follow_imports=silent
[mypy-pandas.conftest,pandas.tests.*]
ignore_errors=True

[mypy-pandas.core.api]
ignore_errors=True

[mypy-pandas.core.indexes.base]
ignore_errors=True

Expand Down
93 changes: 74 additions & 19 deletions pandas/core/arrays/integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,22 +696,77 @@ def integer_arithmetic_method(self, other):
"""

# create the Dtype
_dtypes = {}
for dtype in ['int8', 'int16', 'int32', 'int64',
'uint8', 'uint16', 'uint32', 'uint64']:

if dtype.startswith('u'):
name = "U{}".format(dtype[1:].capitalize())
else:
name = dtype.capitalize()
classname = "{}Dtype".format(name)
numpy_dtype = getattr(np, dtype)
attributes_dict = {'type': numpy_dtype,
'name': name,
'__doc__': _dtype_docstring.format(dtype=dtype)}
dtype_type = register_extension_dtype(
type(classname, (_IntegerDtype, ), attributes_dict)
)
setattr(module, classname, dtype_type)

_dtypes[dtype] = dtype_type()
Int8Dtype = register_extension_dtype(
type('Int8Dtype', (_IntegerDtype, ), {
'type': np.int8,
'name': 'Int8',
'__doc__': _dtype_docstring.format(dtype='int8')
})
)

Int16Dtype = register_extension_dtype(
type('Int16Dtype', (_IntegerDtype, ), {
'type': np.int16,
'name': 'Int16',
'__doc__': _dtype_docstring.format(dtype='int16')
})
)

Int32Dtype = register_extension_dtype(
type('Int32Dtype', (_IntegerDtype, ), {
'type': np.int32,
'name': 'Int32',
'__doc__': _dtype_docstring.format(dtype='int32')
})
)

Int64Dtype = register_extension_dtype(
type('Int64Dtype', (_IntegerDtype, ), {
'type': np.int64,
'name': 'Int64',
'__doc__': _dtype_docstring.format(dtype='int64')
})
)

UInt8Dtype = register_extension_dtype(
type('UInt8Dtype', (_IntegerDtype, ), {
'type': np.uint8,
'name': 'UInt8',
'__doc__': _dtype_docstring.format(dtype='uint8')
})
)

UInt16Dtype = register_extension_dtype(
type('UInt16Dtype', (_IntegerDtype, ), {
'type': np.uint16,
'name': 'UInt16',
'__doc__': _dtype_docstring.format(dtype='uint16')
})
)

UInt32Dtype = register_extension_dtype(
type('UInt32Dtype', (_IntegerDtype, ), {
'type': np.uint32,
'name': 'UInt32',
'__doc__': _dtype_docstring.format(dtype='uint32')
})
)

UInt64Dtype = register_extension_dtype(
type('UInt64Dtype', (_IntegerDtype, ), {
'type': np.uint64,
'name': 'UInt64',
'__doc__': _dtype_docstring.format(dtype='uint64')
})
)

_dtypes = {
'int8': Int8Dtype(),
'int16': Int16Dtype(),
'int32': Int32Dtype(),
'int64': Int64Dtype(),
'uint8': UInt8Dtype(),
'uint16': UInt16Dtype(),
'uint32': UInt32Dtype(),
'uint64': UInt64Dtype(),
}

0 comments on commit 4e4f5bd

Please sign in to comment.