Skip to content

CLN: comments, docstrings, depr NaT.freq #45071

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 7 commits into from
Dec 27, 2021
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ Other Deprecations
- Deprecated :meth:`Categorical.replace`, use :meth:`Series.replace` instead (:issue:`44929`)
- Deprecated :meth:`Index.__getitem__` with a bool key; use ``index.values[key]`` to get the old behavior (:issue:`44051`)
- Deprecated downcasting column-by-column in :meth:`DataFrame.where` with integer-dtypes (:issue:`44597`)
- Deprecated :meth:`NaT.freq` (:issue:`45071`)
-

.. ---------------------------------------------------------------------------
Expand Down
4 changes: 1 addition & 3 deletions pandas/_libs/hashtable_class_helper.pxi.in
Original file line number Diff line number Diff line change
Expand Up @@ -1228,9 +1228,7 @@ cdef class PyObjectHashTable(HashTable):
hash(val)

if ignore_na and (
(val is C_NA)
or (val != val)
or (val is None)
checknull(val)
or (use_na_value and val == na_value)
):
# if missing values do not count as unique values (i.e. if
Expand Down
1 change: 0 additions & 1 deletion pandas/_libs/tslibs/nattype.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ cdef set c_nat_strings
cdef class _NaT(datetime):
cdef readonly:
int64_t value
object freq

cdef _NaT c_NaT

Expand Down
10 changes: 9 additions & 1 deletion pandas/_libs/tslibs/nattype.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,18 @@ class NaTType(_NaT):

base = _NaT.__new__(cls, 1, 1, 1)
base.value = NPY_NAT
base.freq = None

return base

@property
def freq(self):
warnings.warn(
"NaT.freq is deprecated and will be removed in a future version.",
FutureWarning,
stacklevel=1,
)
return None

def __reduce_ex__(self, protocol):
# python 3.6 compat
# https://bugs.python.org/issue28730
Expand Down
2 changes: 2 additions & 0 deletions pandas/_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,8 @@ def shares_memory(left, right) -> bool:
return shares_memory(left._ndarray, right)
if isinstance(left, pd.core.arrays.SparseArray):
return shares_memory(left.sp_values, right)
if isinstance(left, pd.core.arrays.IntervalArray):
return shares_memory(left._left, right) or shares_memory(left._right, right)

if isinstance(left, ExtensionArray) and left.dtype == "string[pyarrow]":
# https://github.com/pandas-dev/pandas/pull/43930#discussion_r736862669
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def _ensure_data(values: ArrayLike) -> np.ndarray:
This will coerce:
- ints -> int64
- uint -> uint64
- bool -> uint64 (TODO this should be uint8)
- bool -> uint8
- datetimelike -> i8
- datetime64tz -> i8 (in local tz)
- categorical -> codes
Expand Down Expand Up @@ -899,7 +899,6 @@ def value_counts_arraylike(values, dropna: bool):
original = values
values = _ensure_data(values)

# TODO: handle uint8
keys, counts = htable.value_count(values, dropna)

if needs_i8_conversion(original.dtype):
Expand Down
5 changes: 5 additions & 0 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,11 @@ def _fill_mask_inplace(
def _empty(cls, shape: Shape, dtype: ExtensionDtype):
"""
Create an ExtensionArray with the given shape and dtype.

See also
--------
ExtensionDtype.empty
ExtensionDtype.empty is the 'official' public version of this API.
"""
obj = cls._from_sequence([], dtype=dtype)

Expand Down
2 changes: 2 additions & 0 deletions pandas/core/arrays/string_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ def copy(self) -> ArrowStringArray:
"""
Return a shallow copy of the array.

Underlying ChunkedArray is immutable, so a deep copy is unnecessary.

Returns
-------
ArrowStringArray
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,9 @@ def extract_array(
----------
obj : object
For Series / Index, the underlying ExtensionArray is unboxed.
For Numpy-backed ExtensionArrays, the ndarray is extracted.

extract_numpy : bool, default False
Whether to extract the ndarray from a PandasArray
Whether to extract the ndarray from a PandasArray.

extract_range : bool, default False
If we have a RangeIndex, return range._values if True
Expand Down
4 changes: 4 additions & 0 deletions pandas/core/dtypes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ def empty(self, shape: Shape) -> type_t[ExtensionArray]:

Analogous to numpy.empty.

Parameters
----------
shape : int or tuple[int]

Returns
-------
ExtensionArray
Expand Down
6 changes: 6 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -5847,6 +5847,9 @@ def isna(self) -> DataFrame:

@doc(NDFrame.isna, klass=_shared_doc_kwargs["klass"])
def isnull(self) -> DataFrame:
"""
DataFrame.isnull is an alias for DataFrame.isna.
"""
return self.isna()

@doc(NDFrame.notna, klass=_shared_doc_kwargs["klass"])
Expand All @@ -5855,6 +5858,9 @@ def notna(self) -> DataFrame:

@doc(NDFrame.notna, klass=_shared_doc_kwargs["klass"])
def notnull(self) -> DataFrame:
"""
DataFrame.notnull is an alias for DataFrame.notna.
"""
return ~self.isna()

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
Expand Down
4 changes: 1 addition & 3 deletions pandas/core/reshape/pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,7 @@ def __internal_pivot_table(
table = table.sort_index(axis=1)

if fill_value is not None:
_table = table.fillna(fill_value, downcast="infer")
assert _table is not None # needed for mypy
table = _table
table = table.fillna(fill_value, downcast="infer")

if margins:
if dropna:
Expand Down
6 changes: 6 additions & 0 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -5231,6 +5231,9 @@ def isna(self) -> Series:
# error: Cannot determine type of 'isna'
@doc(NDFrame.isna, klass=_shared_doc_kwargs["klass"]) # type: ignore[has-type]
def isnull(self) -> Series:
"""
Series.isnull is an alias for Series.isna.
"""
return super().isnull()

# error: Cannot determine type of 'notna'
Expand All @@ -5241,6 +5244,9 @@ def notna(self) -> Series:
# error: Cannot determine type of 'notna'
@doc(NDFrame.notna, klass=_shared_doc_kwargs["klass"]) # type: ignore[has-type]
def notnull(self) -> Series:
"""
Series.notnull is an alias for Series.notna.
"""
return super().notnull()

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/base/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@
import pandas._testing as tm


def test_isnull_notnull_docstrings():
# GH#41855 make sure its clear these are aliases
doc = pd.DataFrame.notnull.__doc__
assert doc.startswith("\nDataFrame.notnull is an alias for DataFrame.notna.\n")
doc = pd.DataFrame.isnull.__doc__
assert doc.startswith("\nDataFrame.isnull is an alias for DataFrame.isna.\n")

doc = Series.notnull.__doc__
assert doc.startswith("\nSeries.notnull is an alias for Series.notna.\n")
doc = Series.isnull.__doc__
assert doc.startswith("\nSeries.isnull is an alias for Series.isna.\n")


@pytest.mark.parametrize(
"op_name, op",
[
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/scalar/test_nat.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,3 +718,8 @@ def test_pickle():
# GH#4606
p = tm.round_trip_pickle(NaT)
assert p is NaT


def test_freq_deprecated():
with tm.assert_produces_warning(FutureWarning, match="deprecated"):
NaT.freq
3 changes: 2 additions & 1 deletion pandas/tests/tools/test_to_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -1649,7 +1649,8 @@ def test_to_datetime_respects_dayfirst(self, cache):
with pytest.raises(ValueError, match=msg):
# if dayfirst is respected, then this would parse as month=13, which
# would raise
to_datetime("01-13-2012", dayfirst=True, cache=cache)
with tm.assert_produces_warning(UserWarning, match="Provide format"):
to_datetime("01-13-2012", dayfirst=True, cache=cache)

def test_to_datetime_on_datetime64_series(self, cache):
# #2699
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/util/test_shares_memory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pandas as pd
import pandas._testing as tm


def test_shares_memory_interval():
obj = pd.interval_range(1, 5)

assert tm.shares_memory(obj, obj)
assert tm.shares_memory(obj, obj._data)
assert tm.shares_memory(obj, obj[::-1])
assert tm.shares_memory(obj, obj[:2])

assert not tm.shares_memory(obj, obj._data.copy())
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ def run(self):
# ----------------------------------------------------------------------
# Specification of Dependencies

# TODO: Need to check to see if e.g. `linetrace` has changed and possibly
# re-compile.
# TODO(cython#4518): Need to check to see if e.g. `linetrace` has changed and
# possibly re-compile.
def maybe_cythonize(extensions, *args, **kwargs):
"""
Render tempita templates before calling cythonize. This is skipped for
Expand Down