Repository: pandas-dev/pandas

Issue:
Fix Type Annotations in pandas/compat/numpy/function.py
Part of #25882

Current errors are as follows:

> mypy pandas/compat/numpy/function.py

    pandas\compat\numpy\function.py:104: error: Need type annotation for 'ARGSORT_DEFAULTS'
    pandas\compat\numpy\function.py:105: error: Cannot determine type of 'ARGSORT_DEFAULTS'
    pandas\compat\numpy\function.py:106: error: Cannot determine type of 'ARGSORT_DEFAULTS'
    pandas\compat\numpy\function.py:107: error: Cannot determine type of 'ARGSORT_DEFAULTS'
    pandas\compat\numpy\function.py:108: error: Cannot determine type of 'ARGSORT_DEFAULTS'
    pandas\compat\numpy\function.py:113: error: Need type annotation for 'ARGSORT_DEFAULTS_KIND'
    pandas\compat\numpy\function.py:114: error: Cannot determine type of 'ARGSORT_DEFAULTS_KIND'
    pandas\compat\numpy\function.py:115: error: Cannot determine type of 'ARGSORT_DEFAULTS_KIND'
    pandas\compat\numpy\function.py:116: error: Cannot determine type of 'ARGSORT_DEFAULTS_KIND'
    pandas\compat\numpy\function.py:158: error: Need type annotation for 'COMPRESS_DEFAULTS'
    pandas\compat\numpy\function.py:159: error: Cannot determine type of 'COMPRESS_DEFAULTS'
    pandas\compat\numpy\function.py:160: error: Cannot determine type of 'COMPRESS_DEFAULTS'
    pandas\compat\numpy\function.py:161: error: Cannot determine type of 'COMPRESS_DEFAULTS'
    pandas\compat\numpy\function.py:164: error: Need type annotation for 'CUM_FUNC_DEFAULTS'
    pandas\compat\numpy\function.py:165: error: Cannot determine type of 'CUM_FUNC_DEFAULTS'
    pandas\compat\numpy\function.py:166: error: Cannot determine type of 'CUM_FUNC_DEFAULTS'
    pandas\compat\numpy\function.py:167: error: Cannot determine type of 'CUM_FUNC_DEFAULTS'
    pandas\compat\numpy\function.py:169: error: Cannot determine type of 'CUM_FUNC_DEFAULTS'
    pandas\compat\numpy\function.py:188: error: Need type annotation for 'ALLANY_DEFAULTS'
    pandas\compat\numpy\function.py:189: error: Cannot determine type of 'ALLANY_DEFAULTS'
    pandas\compat\numpy\function.py:190: error: Cannot determine type of 'ALLANY_DEFAULTS'
    pandas\compat\numpy\function.py:191: error: Cannot determine type of 'ALLANY_DEFAULTS'
    pandas\compat\numpy\function.py:192: error: Cannot determine type of 'ALLANY_DEFAULTS'
    pandas\compat\numpy\function.py:194: error: Cannot determine type of 'ALLANY_DEFAULTS'
    pandas\compat\numpy\function.py:218: error: Need type annotation for 'SORT_DEFAULTS'
    pandas\compat\numpy\function.py:219: error: Cannot determine type of 'SORT_DEFAULTS'
    pandas\compat\numpy\function.py:220: error: Cannot determine type of 'SORT_DEFAULTS'
    pandas\compat\numpy\function.py:221: error: Cannot determine type of 'SORT_DEFAULTS'
    pandas\compat\numpy\function.py:222: error: Cannot determine type of 'SORT_DEFAULTS'
    pandas\compat\numpy\function.py:225: error: Need type annotation for 'STAT_FUNC_DEFAULTS'
    pandas\compat\numpy\function.py:226: error: Cannot determine type of 'STAT_FUNC_DEFAULTS'
    pandas\compat\numpy\function.py:227: error: Cannot determine type of 'STAT_FUNC_DEFAULTS'
    pandas\compat\numpy\function.py:229: error: Cannot determine type of 'STAT_FUNC_DEFAULTS'
    pandas\compat\numpy\function.py:233: error: Cannot determine type of 'STAT_FUNC_DEFAULTS'
    pandas\compat\numpy\function.py:237: error: Cannot determine type of 'STAT_FUNC_DEFAULTS'
    pandas\compat\numpy\function.py:239: error: Cannot determine type of 'STAT_FUNC_DEFAULTS'
    pandas\compat\numpy\function.py:245: error: Cannot determine type of 'STAT_FUNC_DEFAULTS'
    pandas\compat\numpy\function.py:250: error: Need type annotation for 'STAT_DDOF_FUNC_DEFAULTS'
    pandas\compat\numpy\function.py:251: error: Cannot determine type of 'STAT_DDOF_FUNC_DEFAULTS'
    pandas\compat\numpy\function.py:252: error: Cannot determine type of 'STAT_DDOF_FUNC_DEFAULTS'
    pandas\compat\numpy\function.py:253: error: Cannot determine type of 'STAT_DDOF_FUNC_DEFAULTS'
    pandas\compat\numpy\function.py:254: error: Cannot determine type of 'STAT_DDOF_FUNC_DEFAULTS'
    pandas\compat\numpy\function.py:257: error: Need type annotation for 'TAKE_DEFAULTS'
    pandas\compat\numpy\function.py:258: error: Cannot determine type of 'TAKE_DEFAULTS'
    pandas\compat\numpy\function.py:259: error: Cannot determine type of 'TAKE_DEFAULTS'
    pandas\compat\numpy\function.py:260: error: Cannot determine type of 'TAKE_DEFAULTS'



Discussion:
PR Coming Soon.

Resolving patch:
diff --git a/pandas/compat/numpy/function.py b/pandas/compat/numpy/function.py
--- a/pandas/compat/numpy/function.py
+++ b/pandas/compat/numpy/function.py
@@ -18,6 +18,7 @@
 easier to adjust to future upstream changes in the analogous numpy signatures.
 """
 from collections import OrderedDict
+from typing import Any, Dict, Optional, Union
 
 from numpy import ndarray
 
@@ -101,7 +102,8 @@ def validate_argmax_with_skipna(skipna, args, kwargs):
     return skipna
 
 
-ARGSORT_DEFAULTS = OrderedDict()
+ARGSORT_DEFAULTS = OrderedDict() \
+    # type: OrderedDict[str, Optional[Union[int, str]]]
 ARGSORT_DEFAULTS['axis'] = -1
 ARGSORT_DEFAULTS['kind'] = 'quicksort'
 ARGSORT_DEFAULTS['order'] = None
@@ -110,7 +112,8 @@ def validate_argmax_with_skipna(skipna, args, kwargs):
 
 # two different signatures of argsort, this second validation
 # for when the `kind` param is supported
-ARGSORT_DEFAULTS_KIND = OrderedDict()
+ARGSORT_DEFAULTS_KIND = OrderedDict() \
+    # type: OrderedDict[str, Optional[int]]
 ARGSORT_DEFAULTS_KIND['axis'] = -1
 ARGSORT_DEFAULTS_KIND['order'] = None
 validate_argsort_kind = CompatValidator(ARGSORT_DEFAULTS_KIND, fname='argsort',
@@ -134,7 +137,7 @@ def validate_argsort_with_ascending(ascending, args, kwargs):
     return ascending
 
 
-CLIP_DEFAULTS = dict(out=None)
+CLIP_DEFAULTS = dict(out=None)  # type Dict[str, Any]
 validate_clip = CompatValidator(CLIP_DEFAULTS, fname='clip',
                                 method='both', max_fname_arg_count=3)
 
@@ -155,13 +158,13 @@ def validate_clip_with_axis(axis, args, kwargs):
     return axis
 
 
-COMPRESS_DEFAULTS = OrderedDict()
+COMPRESS_DEFAULTS = OrderedDict()  # type: OrderedDict[str, Any]
 COMPRESS_DEFAULTS['axis'] = None
 COMPRESS_DEFAULTS['out'] = None
 validate_compress = CompatValidator(COMPRESS_DEFAULTS, fname='compress',
                                     method='both', max_fname_arg_count=1)
 
-CUM_FUNC_DEFAULTS = OrderedDict()
+CUM_FUNC_DEFAULTS = OrderedDict()  # type: OrderedDict[str, Any]
 CUM_FUNC_DEFAULTS['dtype'] = None
 CUM_FUNC_DEFAULTS['out'] = None
 validate_cum_func = CompatValidator(CUM_FUNC_DEFAULTS, method='both',
@@ -185,7 +188,7 @@ def validate_cum_func_with_skipna(skipna, args, kwargs, name):
     return skipna
 
 
-ALLANY_DEFAULTS = OrderedDict()
+ALLANY_DEFAULTS = OrderedDict()  # type: OrderedDict[str, Optional[bool]]
 ALLANY_DEFAULTS['dtype'] = None
 ALLANY_DEFAULTS['out'] = None
 ALLANY_DEFAULTS['keepdims'] = False
@@ -203,26 +206,27 @@ def validate_cum_func_with_skipna(skipna, args, kwargs, name):
 validate_max = CompatValidator(MINMAX_DEFAULTS, fname='max',
                                method='both', max_fname_arg_count=1)
 
-RESHAPE_DEFAULTS = dict(order='C')
+RESHAPE_DEFAULTS = dict(order='C')  # type: Dict[str, str]
 validate_reshape = CompatValidator(RESHAPE_DEFAULTS, fname='reshape',
                                    method='both', max_fname_arg_count=1)
 
-REPEAT_DEFAULTS = dict(axis=None)
+REPEAT_DEFAULTS = dict(axis=None)  # type: Dict[str, Any]
 validate_repeat = CompatValidator(REPEAT_DEFAULTS, fname='repeat',
                                   method='both', max_fname_arg_count=1)
 
-ROUND_DEFAULTS = dict(out=None)
+ROUND_DEFAULTS = dict(out=None)  # type: Dict[str, Any]
 validate_round = CompatValidator(ROUND_DEFAULTS, fname='round',
                                  method='both', max_fname_arg_count=1)
 
-SORT_DEFAULTS = OrderedDict()
+SORT_DEFAULTS = OrderedDict()  \
+    # type: OrderedDict[str, Optional[Union[int, str]]]
 SORT_DEFAULTS['axis'] = -1
 SORT_DEFAULTS['kind'] = 'quicksort'
 SORT_DEFAULTS['order'] = None
 validate_sort = CompatValidator(SORT_DEFAULTS, fname='sort',
                                 method='kwargs')
 
-STAT_FUNC_DEFAULTS = OrderedDict()
+STAT_FUNC_DEFAULTS = OrderedDict()  # type: OrderedDict[str, Optional[Any]]
 STAT_FUNC_DEFAULTS['dtype'] = None
 STAT_FUNC_DEFAULTS['out'] = None
 
@@ -247,14 +251,15 @@ def validate_cum_func_with_skipna(skipna, args, kwargs, name):
 validate_median = CompatValidator(MEDIAN_DEFAULTS, fname='median',
                                   method='both', max_fname_arg_count=1)
 
-STAT_DDOF_FUNC_DEFAULTS = OrderedDict()
+STAT_DDOF_FUNC_DEFAULTS = OrderedDict() \
+    # type: OrderedDict[str, Optional[bool]]
 STAT_DDOF_FUNC_DEFAULTS['dtype'] = None
 STAT_DDOF_FUNC_DEFAULTS['out'] = None
 STAT_DDOF_FUNC_DEFAULTS['keepdims'] = False
 validate_stat_ddof_func = CompatValidator(STAT_DDOF_FUNC_DEFAULTS,
                                           method='kwargs')
 
-TAKE_DEFAULTS = OrderedDict()
+TAKE_DEFAULTS = OrderedDict()  # type: OrderedDict[str, Optional[str]]
 TAKE_DEFAULTS['out'] = None
 TAKE_DEFAULTS['mode'] = 'raise'
 validate_take = CompatValidator(TAKE_DEFAULTS, fname='take',


Test patch: