Skip to content

CLN: De-privatize names #33227

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
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions pandas/_libs/tslibs/conversion.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ from pandas._libs.tslibs.tzconversion cimport (
# ----------------------------------------------------------------------
# Constants

NS_DTYPE = np.dtype('M8[ns]')
TD_DTYPE = np.dtype('m8[ns]')
DT64NS_DTYPE = np.dtype('M8[ns]')
TD64NS_DTYPE = np.dtype('m8[ns]')


# ----------------------------------------------------------------------
Expand Down Expand Up @@ -105,11 +105,11 @@ def ensure_datetime64ns(arr: ndarray, copy: bool=True):

ivalues = arr.view(np.int64).ravel()

result = np.empty(shape, dtype=NS_DTYPE)
result = np.empty(shape, dtype=DT64NS_DTYPE)
iresult = result.ravel().view(np.int64)

if len(iresult) == 0:
result = arr.view(NS_DTYPE)
result = arr.view(DT64NS_DTYPE)
if copy:
result = result.copy()
return result
Expand Down Expand Up @@ -145,7 +145,7 @@ def ensure_timedelta64ns(arr: ndarray, copy: bool=True):
result : ndarray with dtype timedelta64[ns]

"""
return arr.astype(TD_DTYPE, copy=copy)
return arr.astype(TD64NS_DTYPE, copy=copy)
# TODO: check for overflows when going from a lower-resolution to nanos


Expand Down
18 changes: 9 additions & 9 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def __init__(
old_codes = (
values._values.codes if isinstance(values, ABCSeries) else values.codes
)
codes = _recode_for_categories(
codes = recode_for_categories(
old_codes, values.dtype.categories, dtype.categories
)

Expand Down Expand Up @@ -572,13 +572,13 @@ def _from_inferred_categories(
if known_categories:
# Recode from observation order to dtype.categories order.
categories = dtype.categories
codes = _recode_for_categories(inferred_codes, cats, categories)
codes = recode_for_categories(inferred_codes, cats, categories)
elif not cats.is_monotonic_increasing:
# Sort categories and recode for unknown categories.
unsorted = cats.copy()
categories = cats.sort_values()

codes = _recode_for_categories(inferred_codes, unsorted, categories)
codes = recode_for_categories(inferred_codes, unsorted, categories)
dtype = CategoricalDtype(categories, ordered=False)
else:
dtype = CategoricalDtype(cats, ordered=False)
Expand Down Expand Up @@ -727,7 +727,7 @@ def _set_dtype(self, dtype: CategoricalDtype) -> "Categorical":
We don't do any validation here. It's assumed that the dtype is
a (valid) instance of `CategoricalDtype`.
"""
codes = _recode_for_categories(self.codes, self.categories, dtype.categories)
codes = recode_for_categories(self.codes, self.categories, dtype.categories)
return type(self)(codes, dtype=dtype, fastpath=True)

def set_ordered(self, value, inplace=False):
Expand Down Expand Up @@ -849,7 +849,7 @@ def set_categories(self, new_categories, ordered=None, rename=False, inplace=Fal
# remove all _codes which are larger and set to -1/NaN
cat._codes[cat._codes >= len(new_dtype.categories)] = -1
else:
codes = _recode_for_categories(
codes = recode_for_categories(
cat.codes, cat.categories, new_dtype.categories
)
cat._codes = codes
Expand Down Expand Up @@ -2034,7 +2034,7 @@ def __setitem__(self, key, value):
"without identical categories"
)
if not self.categories.equals(value.categories):
new_codes = _recode_for_categories(
new_codes = recode_for_categories(
value.codes, value.categories, self.categories
)
value = Categorical.from_codes(new_codes, dtype=self.dtype)
Expand Down Expand Up @@ -2298,7 +2298,7 @@ def equals(self, other):
# fastpath to avoid re-coding
other_codes = other._codes
else:
other_codes = _recode_for_categories(
other_codes = recode_for_categories(
other.codes, other.categories, self.categories
)
return np.array_equal(self._codes, other_codes)
Expand Down Expand Up @@ -2667,7 +2667,7 @@ def _get_codes_for_values(values, categories):
return coerce_indexer_dtype(t.lookup(vals), cats)


def _recode_for_categories(codes: np.ndarray, old_categories, new_categories):
def recode_for_categories(codes: np.ndarray, old_categories, new_categories):
"""
Convert a set of codes for to a new set of categories

Expand All @@ -2685,7 +2685,7 @@ def _recode_for_categories(codes: np.ndarray, old_categories, new_categories):
>>> old_cat = pd.Index(['b', 'a', 'c'])
>>> new_cat = pd.Index(['a', 'b'])
>>> codes = np.array([0, 1, 1, 2])
>>> _recode_for_categories(codes, old_cat, new_cat)
>>> recode_for_categories(codes, old_cat, new_cat)
array([ 1, 0, 0, -1], dtype=int8)
"""
if len(old_categories) == 0:
Expand Down
30 changes: 15 additions & 15 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from pandas.core.dtypes.common import (
_INT64_DTYPE,
_NS_DTYPE,
DT64NS_DTYPE,
is_bool_dtype,
is_categorical_dtype,
is_datetime64_any_dtype,
Expand Down Expand Up @@ -66,7 +66,7 @@ def tz_to_dtype(tz):
np.dtype or Datetime64TZDType
"""
if tz is None:
return _NS_DTYPE
return DT64NS_DTYPE
else:
return DatetimeTZDtype(tz=tz)

Expand Down Expand Up @@ -209,7 +209,7 @@ class DatetimeArray(dtl.DatetimeLikeArrayMixin, dtl.TimelikeOps, dtl.DatelikeOps
_dtype: Union[np.dtype, DatetimeTZDtype]
_freq = None

def __init__(self, values, dtype=_NS_DTYPE, freq=None, copy=False):
def __init__(self, values, dtype=DT64NS_DTYPE, freq=None, copy=False):
if isinstance(values, (ABCSeries, ABCIndexClass)):
values = values._values

Expand Down Expand Up @@ -246,9 +246,9 @@ def __init__(self, values, dtype=_NS_DTYPE, freq=None, copy=False):
# for compat with datetime/timedelta/period shared methods,
# we can sometimes get here with int64 values. These represent
# nanosecond UTC (or tz-naive) unix timestamps
values = values.view(_NS_DTYPE)
values = values.view(DT64NS_DTYPE)

if values.dtype != _NS_DTYPE:
if values.dtype != DT64NS_DTYPE:
raise ValueError(
"The dtype of 'values' is incorrect. Must be 'datetime64[ns]'. "
f"Got {values.dtype} instead."
Expand Down Expand Up @@ -282,11 +282,11 @@ def __init__(self, values, dtype=_NS_DTYPE, freq=None, copy=False):
type(self)._validate_frequency(self, freq)

@classmethod
def _simple_new(cls, values, freq=None, dtype=_NS_DTYPE):
def _simple_new(cls, values, freq=None, dtype=DT64NS_DTYPE):
assert isinstance(values, np.ndarray)
if values.dtype != _NS_DTYPE:
if values.dtype != DT64NS_DTYPE:
assert values.dtype == "i8"
values = values.view(_NS_DTYPE)
values = values.view(DT64NS_DTYPE)

result = object.__new__(cls)
result._data = values
Expand Down Expand Up @@ -970,7 +970,7 @@ def tz_localize(self, tz, ambiguous="raise", nonexistent="raise"):
new_dates = conversion.tz_localize_to_utc(
self.asi8, tz, ambiguous=ambiguous, nonexistent=nonexistent
)
new_dates = new_dates.view(_NS_DTYPE)
new_dates = new_dates.view(DT64NS_DTYPE)
dtype = tz_to_dtype(tz)
return self._simple_new(new_dates, dtype=dtype, freq=self.freq)

Expand Down Expand Up @@ -1751,7 +1751,7 @@ def sequence_to_dt64ns(
elif is_datetime64_dtype(data):
# tz-naive DatetimeArray or ndarray[datetime64]
data = getattr(data, "_data", data)
if data.dtype != _NS_DTYPE:
if data.dtype != DT64NS_DTYPE:
data = conversion.ensure_datetime64ns(data)

if tz is not None:
Expand All @@ -1760,9 +1760,9 @@ def sequence_to_dt64ns(
data = conversion.tz_localize_to_utc(
data.view("i8"), tz, ambiguous=ambiguous
)
data = data.view(_NS_DTYPE)
data = data.view(DT64NS_DTYPE)

assert data.dtype == _NS_DTYPE, data.dtype
assert data.dtype == DT64NS_DTYPE, data.dtype
result = data

else:
Expand All @@ -1773,7 +1773,7 @@ def sequence_to_dt64ns(

if data.dtype != _INT64_DTYPE:
data = data.astype(np.int64, copy=False)
result = data.view(_NS_DTYPE)
result = data.view(DT64NS_DTYPE)

if copy:
# TODO: should this be deepcopy?
Expand Down Expand Up @@ -1897,7 +1897,7 @@ def maybe_convert_dtype(data, copy):
if is_float_dtype(data.dtype):
# Note: we must cast to datetime64[ns] here in order to treat these
# as wall-times instead of UTC timestamps.
data = data.astype(_NS_DTYPE)
data = data.astype(DT64NS_DTYPE)
copy = False
# TODO: deprecate this behavior to instead treat symmetrically
# with integer dtypes. See discussion in GH#23675
Expand Down Expand Up @@ -1994,7 +1994,7 @@ def _validate_dt64_dtype(dtype):
)
raise ValueError(msg)

if (isinstance(dtype, np.dtype) and dtype != _NS_DTYPE) or not isinstance(
if (isinstance(dtype, np.dtype) and dtype != DT64NS_DTYPE) or not isinstance(
dtype, (np.dtype, DatetimeTZDtype)
):
raise ValueError(
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from pandas.util._decorators import cache_readonly

from pandas.core.dtypes.common import (
_TD_DTYPE,
TD64NS_DTYPE,
ensure_object,
is_datetime64_dtype,
is_float_dtype,
Expand Down Expand Up @@ -718,10 +718,10 @@ def _check_timedeltalike_freq_compat(self, other):
elif isinstance(other, np.ndarray):
# numpy timedelta64 array; all entries must be compatible
assert other.dtype.kind == "m"
if other.dtype != _TD_DTYPE:
if other.dtype != TD64NS_DTYPE:
# i.e. non-nano unit
# TODO: disallow unit-less timedelta64
other = other.astype(_TD_DTYPE)
other = other.astype(TD64NS_DTYPE)
nanos = other.view("i8")
else:
# TimedeltaArray/Index
Expand Down
30 changes: 15 additions & 15 deletions pandas/core/arrays/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from pandas.compat.numpy import function as nv

from pandas.core.dtypes.common import (
_NS_DTYPE,
_TD_DTYPE,
DT64NS_DTYPE,
TD64NS_DTYPE,
is_dtype_equal,
is_float_dtype,
is_integer_dtype,
Expand Down Expand Up @@ -136,12 +136,12 @@ def dtype(self):
-------
numpy.dtype
"""
return _TD_DTYPE
return TD64NS_DTYPE

# ----------------------------------------------------------------
# Constructors

def __init__(self, values, dtype=_TD_DTYPE, freq=None, copy=False):
def __init__(self, values, dtype=TD64NS_DTYPE, freq=None, copy=False):
values = extract_array(values)

inferred_freq = getattr(values, "_freq", None)
Expand All @@ -167,7 +167,7 @@ def __init__(self, values, dtype=_TD_DTYPE, freq=None, copy=False):
# for compat with datetime/timedelta/period shared methods,
# we can sometimes get here with int64 values. These represent
# nanosecond UTC (or tz-naive) unix timestamps
values = values.view(_TD_DTYPE)
values = values.view(TD64NS_DTYPE)

_validate_td64_dtype(values.dtype)
dtype = _validate_td64_dtype(dtype)
Expand All @@ -192,21 +192,21 @@ def __init__(self, values, dtype=_TD_DTYPE, freq=None, copy=False):
type(self)._validate_frequency(self, freq)

@classmethod
def _simple_new(cls, values, freq=None, dtype=_TD_DTYPE):
assert dtype == _TD_DTYPE, dtype
def _simple_new(cls, values, freq=None, dtype=TD64NS_DTYPE):
assert dtype == TD64NS_DTYPE, dtype
assert isinstance(values, np.ndarray), type(values)
if values.dtype != _TD_DTYPE:
if values.dtype != TD64NS_DTYPE:
assert values.dtype == "i8"
values = values.view(_TD_DTYPE)
values = values.view(TD64NS_DTYPE)

result = object.__new__(cls)
result._data = values
result._freq = to_offset(freq)
result._dtype = _TD_DTYPE
result._dtype = TD64NS_DTYPE
return result

@classmethod
def _from_sequence(cls, data, dtype=_TD_DTYPE, copy=False, freq=None, unit=None):
def _from_sequence(cls, data, dtype=TD64NS_DTYPE, copy=False, freq=None, unit=None):
if dtype:
_validate_td64_dtype(dtype)
freq, freq_infer = dtl.maybe_infer_freq(freq)
Expand Down Expand Up @@ -428,7 +428,7 @@ def _add_datetimelike_scalar(self, other):
i8 = self.asi8
result = checked_add_with_arr(i8, other.value, arr_mask=self._isnan)
result = self._maybe_mask_results(result)
dtype = DatetimeTZDtype(tz=other.tz) if other.tz else _NS_DTYPE
dtype = DatetimeTZDtype(tz=other.tz) if other.tz else DT64NS_DTYPE
return DatetimeArray(result, dtype=dtype, freq=self.freq)

def _addsub_object_array(self, other, op):
Expand Down Expand Up @@ -950,10 +950,10 @@ def sequence_to_td64ns(data, copy=False, unit="ns", errors="raise"):
copy = False

elif is_timedelta64_dtype(data.dtype):
if data.dtype != _TD_DTYPE:
if data.dtype != TD64NS_DTYPE:
# non-nano unit
# TODO: watch out for overflows
data = data.astype(_TD_DTYPE)
data = data.astype(TD64NS_DTYPE)
copy = False

else:
Expand Down Expand Up @@ -1051,7 +1051,7 @@ def _validate_td64_dtype(dtype):
)
raise ValueError(msg)

if not is_dtype_equal(dtype, _TD_DTYPE):
if not is_dtype_equal(dtype, TD64NS_DTYPE):
raise ValueError(f"dtype {dtype} cannot be converted to timedelta64[ns]")

return dtype
Expand Down
Loading