Skip to content

Commit

Permalink
typing of helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
SaturnFromTitan committed Dec 5, 2019
1 parent 4ba36b4 commit 8db3cc4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ When :class:`Categorical` contains ``np.nan``,
Default dtype of empty :class:`pandas.Series`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Initialising an empty :class:`pandas.Series` without specifying a dtype will raise a `DeprecationWarning` now
(:issue:`17261`). The default dtype will change from ``float64`` to ``object`` in future releases so that it is
Expand Down
29 changes: 16 additions & 13 deletions pandas/core/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
These should not depend on core.internals.
"""
from typing import Optional, Sequence, Union, cast
from typing import TYPE_CHECKING, Any, Optional, Sequence, Union, cast

import numpy as np
import numpy.ma as ma
Expand Down Expand Up @@ -44,8 +44,13 @@
)
from pandas.core.dtypes.missing import isna

from pandas._typing import ArrayLike, Dtype
import pandas.core.common as com

if TYPE_CHECKING:
from pandas.core.series import Series
from pandas.core.index import Index


def array(
data: Sequence[object],
Expand Down Expand Up @@ -567,8 +572,7 @@ def _try_cast(
return subarr


# see gh-17261
def is_empty_data(data):
def is_empty_data(data: Any) -> bool:
"""
Utility to check if a Series is instantiated with empty data,
which does not contain dtype information.
Expand All @@ -589,19 +593,18 @@ def is_empty_data(data):


def create_series_with_explicit_dtype(
data=None,
index=None,
dtype=None,
name=None,
copy=False,
fastpath=False,
dtype_if_empty=object,
):
data: Any = None,
index: Optional[Union[ArrayLike, Index]] = None,
dtype: Optional[Dtype] = None,
name: Optional[str] = None,
copy: bool = False,
fastpath: bool = False,
dtype_if_empty: Dtype = object,
) -> Series:
"""
Helper to pass an explicit dtype when instantiating an empty Series.
This silences a DeprecationWarning described in the GitHub issue
mentioned above.
This silences a DeprecationWarning described in GitHub-17261.
Parameters
----------
Expand Down

0 comments on commit 8db3cc4

Please sign in to comment.