# Buggy code
def na_value_for_dtype(dtype, compat: bool = True):
    """
    Return a dtype compat na value

    Parameters
    ----------
    dtype : string / dtype
    compat : bool, default True

    Returns
    -------
    np.dtype or a pandas dtype

    Examples
    --------
    >>> na_value_for_dtype(np.dtype('int64'))
    0
    >>> na_value_for_dtype(np.dtype('int64'), compat=False)
    nan
    >>> na_value_for_dtype(np.dtype('float64'))
    nan
    >>> na_value_for_dtype(np.dtype('bool'))
    False
    >>> na_value_for_dtype(np.dtype('datetime64[ns]'))
    NaT
    """
    dtype = pandas_dtype(dtype)

    if is_extension_array_dtype(dtype):
        return dtype.na_value
    if needs_i8_conversion(dtype):
        return NaT
    elif is_float_dtype(dtype):
        return np.nan
    elif is_integer_dtype(dtype):
        if compat:
            return 0
        return np.nan
    elif is_bool_dtype(dtype):
        return False
    return np.nan


# Traceback (TypeError)
In [202]: sparse_series.dtype
Out[203]: Sparse[bool, False]

In [208]: sparse_series.value_counts()
Out[208]:
False    51386
True        13
Name: C_3D Printing, dtype: int64

In [209]: sparse_series.sum()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-209-8f6162710840> in <module>
----> 1 sparse_series.sum()

~/anaconda3/envs/idp/lib/python3.6/site-packages/pandas/core/generic.py in stat_func(self, axis, skipna, level, numeric_only, min_count, **kwargs)
10929                                       skipna=skipna, min_count=min_count)
10930         return self._reduce(f, name, axis=axis, skipna=skipna,
10931                             numeric_only=numeric_only, min_count=min_count)
10932
10933     return set_function_name(stat_func, name, cls)

~/anaconda3/envs/idp/lib/python3.6/site-packages/pandas/core/series.py in _reduce(self, op, name, axis, skipna, numeric_only, filter_type, **kwds)
3613         # dispatch to ExtensionArray interface
3614         if isinstance(delegate, ExtensionArray):
-> 3615             return delegate._reduce(name, skipna=skipna, **kwds)
3616         elif is_datetime64_dtype(delegate):
3617             # use DatetimeIndex implementation to handle skipna correctly

~/anaconda3/envs/idp/lib/python3.6/site-packages/pandas/core/arrays/sparse.py in _reduce(self, name, skipna, **kwargs)
1439         kwargs.pop('numeric_only', None)
1440         kwargs.pop('op', None)
-> 1441         return getattr(arr, name)(**kwargs)
1442
1443     def all(self, axis=None, *args, **kwargs):

~/anaconda3/envs/idp/lib/python3.6/site-packages/pandas/core/arrays/sparse.py in sum(self, axis, *args, **kwargs)
1491         sum : float
1492         """
-> 1493         nv.validate_sum(args, kwargs)
1494         valid_vals = self._valid_sp_values
1495         sp_sum = valid_vals.sum()

~/anaconda3/envs/idp/lib/python3.6/site-packages/pandas/compat/numpy/function.py in __call__(self, args, kwargs, fname, max_fname_arg_count, method)
54                 validate_args_and_kwargs(fname, args, kwargs,
55                                          max_fname_arg_count,
---> 56                                          self.defaults)
57             else:
58                 raise ValueError("invalid validation method "

~/anaconda3/envs/idp/lib/python3.6/site-packages/pandas/util/_validators.py in validate_args_and_kwargs(fname, args, kwargs, max_fname_arg_count, compat_args)
216
217     kwargs.update(args_dict)
--> 218     validate_kwargs(fname, kwargs, compat_args)
219
220

~/anaconda3/envs/idp/lib/python3.6/site-packages/pandas/util/_validators.py in validate_kwargs(fname, kwargs, compat_args)
154     """
155     kwds = kwargs.copy()
--> 156     _check_for_invalid_keys(fname, kwargs, compat_args)
157     _check_for_default_values(fname, kwds, compat_args)
158

~/anaconda3/envs/idp/lib/python3.6/site-packages/pandas/util/_validators.py in _check_for_invalid_keys(fname, kwargs, compat_args)
125         raise TypeError(("{fname}() got an unexpected "
126                          "keyword argument '{arg}'".
--> 127                          format(fname=fname, arg=bad_arg)))
128
129

TypeError: sum() got an unexpected keyword argument 'min_count'

In [210]:

# Fixed code
def na_value_for_dtype(dtype, compat: bool = True):
    """
    Return a dtype compat na value

    Parameters
    ----------
    dtype : string / dtype
    compat : bool, default True

    Returns
    -------
    np.dtype or a pandas dtype

    Examples
    --------
    >>> na_value_for_dtype(np.dtype('int64'))
    0
    >>> na_value_for_dtype(np.dtype('int64'), compat=False)
    nan
    >>> na_value_for_dtype(np.dtype('float64'))
    nan
    >>> na_value_for_dtype(np.dtype('bool'))
    False
    >>> na_value_for_dtype(np.dtype('datetime64[ns]'))
    NaT
    """
    dtype = pandas_dtype(dtype)

    if is_extension_array_dtype(dtype):
        return dtype.na_value
    if needs_i8_conversion(dtype):
        return NaT
    elif is_float_dtype(dtype):
        return np.nan
    elif is_integer_dtype(dtype):
        if compat:
            return 0
        return np.nan
    elif is_bool_dtype(dtype):
        if compat:
            return False
        return np.nan
    return np.nan