Skip to content

remove usages of _get_na_value #19692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2098,7 +2098,7 @@ def asof(self, label):
try:
loc = self.get_loc(label, method='pad')
except KeyError:
return _get_na_value(self.dtype)
return self._na_value
else:
if isinstance(loc, slice):
loc = loc.indices(len(self))[-1]
Expand Down Expand Up @@ -4317,6 +4317,8 @@ def _ensure_index(index_like, copy=False):


def _get_na_value(dtype):
# TODO: remove; this may require a deprecation cycle because this is
# listed in indexes.api.__all_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's odd that that's the case! After all, the underscore means it should be private...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not public and can be removed. the whole pandas.core.index bizness needs to be removed as well.

if is_datetime64_any_dtype(dtype) or is_timedelta64_dtype(dtype):
return libts.NaT
return np.nan
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

from pandas.core.indexes.base import (
Index, _ensure_index,
_get_na_value, InvalidIndexError,
InvalidIndexError,
_index_shared_docs)
from pandas.core.indexes.frozen import (
FrozenNDArray, FrozenList, _ensure_frozen)
Expand Down Expand Up @@ -804,7 +804,7 @@ def values(self):
elif box:
taken = algos.take_1d(lev._box_values(lev._ndarray_values),
lab,
fill_value=_get_na_value(lev.dtype.type))
fill_value=lev._na_value)
else:
taken = algos.take_1d(np.asarray(lev._values), lab)
values.append(taken)
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/reshape/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import pandas.core.algorithms as algos
from pandas._libs import algos as _algos, reshape as _reshape

from pandas.core.index import Index, MultiIndex, _get_na_value
from pandas.core.index import Index, MultiIndex


class _Unstacker(object):
Expand Down Expand Up @@ -260,7 +260,7 @@ def get_new_columns(self):
return self.removed_level

lev = self.removed_level
return lev.insert(0, _get_na_value(lev.dtype.type))
return lev.insert(0, lev._na_value)

stride = len(self.removed_level) + self.lift
width = len(self.value_columns)
Expand Down Expand Up @@ -299,7 +299,7 @@ def get_new_index(self):
if len(self.new_index_levels) == 1:
lev, lab = self.new_index_levels[0], result_labels[0]
if (lab == -1).any():
lev = lev.insert(len(lev), _get_na_value(lev.dtype.type))
lev = lev.insert(len(lev), lev._na_value)
return lev.take(lab)

return MultiIndex(levels=self.new_index_levels, labels=result_labels,
Expand Down
4 changes: 1 addition & 3 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1261,8 +1261,6 @@ def count(self, level=None):
-------
nobs : int or Series (if level specified)
"""
from pandas.core.index import _get_na_value

if level is None:
return notna(com._values_from_object(self)).sum()

Expand All @@ -1275,7 +1273,7 @@ def count(self, level=None):
mask = lab == -1
if mask.any():
lab[mask] = cnt = len(lev)
lev = lev.insert(cnt, _get_na_value(lev.dtype.type))
lev = lev.insert(cnt, lev._na_value)

obs = lab[notna(self.values)]
out = np.bincount(obs, minlength=len(lev) or None)
Expand Down