Skip to content

Commit ef750b2

Browse files
authored
CLN: comments, docstrings, depr NaT.freq (#45071)
1 parent 12cfabb commit ef750b2

18 files changed

+74
-15
lines changed

doc/source/whatsnew/v1.4.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ Other Deprecations
547547
- Deprecated :meth:`Categorical.replace`, use :meth:`Series.replace` instead (:issue:`44929`)
548548
- Deprecated :meth:`Index.__getitem__` with a bool key; use ``index.values[key]`` to get the old behavior (:issue:`44051`)
549549
- Deprecated downcasting column-by-column in :meth:`DataFrame.where` with integer-dtypes (:issue:`44597`)
550+
- Deprecated :meth:`NaT.freq` (:issue:`45071`)
550551
-
551552

552553
.. ---------------------------------------------------------------------------

pandas/_libs/hashtable_class_helper.pxi.in

+1-3
Original file line numberDiff line numberDiff line change
@@ -1228,9 +1228,7 @@ cdef class PyObjectHashTable(HashTable):
12281228
hash(val)
12291229

12301230
if ignore_na and (
1231-
(val is C_NA)
1232-
or (val != val)
1233-
or (val is None)
1231+
checknull(val)
12341232
or (use_na_value and val == na_value)
12351233
):
12361234
# if missing values do not count as unique values (i.e. if

pandas/_libs/tslibs/nattype.pxd

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ cdef set c_nat_strings
1010
cdef class _NaT(datetime):
1111
cdef readonly:
1212
int64_t value
13-
object freq
1413

1514
cdef _NaT c_NaT
1615

pandas/_libs/tslibs/nattype.pyx

+9-1
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,18 @@ class NaTType(_NaT):
357357

358358
base = _NaT.__new__(cls, 1, 1, 1)
359359
base.value = NPY_NAT
360-
base.freq = None
361360

362361
return base
363362

363+
@property
364+
def freq(self):
365+
warnings.warn(
366+
"NaT.freq is deprecated and will be removed in a future version.",
367+
FutureWarning,
368+
stacklevel=1,
369+
)
370+
return None
371+
364372
def __reduce_ex__(self, protocol):
365373
# python 3.6 compat
366374
# https://bugs.python.org/issue28730

pandas/_testing/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,8 @@ def shares_memory(left, right) -> bool:
10781078
return shares_memory(left._ndarray, right)
10791079
if isinstance(left, pd.core.arrays.SparseArray):
10801080
return shares_memory(left.sp_values, right)
1081+
if isinstance(left, pd.core.arrays.IntervalArray):
1082+
return shares_memory(left._left, right) or shares_memory(left._right, right)
10811083

10821084
if isinstance(left, ExtensionArray) and left.dtype == "string[pyarrow]":
10831085
# https://github.com/pandas-dev/pandas/pull/43930#discussion_r736862669

pandas/core/algorithms.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def _ensure_data(values: ArrayLike) -> np.ndarray:
119119
This will coerce:
120120
- ints -> int64
121121
- uint -> uint64
122-
- bool -> uint64 (TODO this should be uint8)
122+
- bool -> uint8
123123
- datetimelike -> i8
124124
- datetime64tz -> i8 (in local tz)
125125
- categorical -> codes
@@ -899,7 +899,6 @@ def value_counts_arraylike(values, dropna: bool):
899899
original = values
900900
values = _ensure_data(values)
901901

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

905904
if needs_i8_conversion(original.dtype):

pandas/core/arrays/base.py

+5
Original file line numberDiff line numberDiff line change
@@ -1500,6 +1500,11 @@ def _fill_mask_inplace(
15001500
def _empty(cls, shape: Shape, dtype: ExtensionDtype):
15011501
"""
15021502
Create an ExtensionArray with the given shape and dtype.
1503+
1504+
See also
1505+
--------
1506+
ExtensionDtype.empty
1507+
ExtensionDtype.empty is the 'official' public version of this API.
15031508
"""
15041509
obj = cls._from_sequence([], dtype=dtype)
15051510

pandas/core/arrays/string_arrow.py

+2
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ def copy(self) -> ArrowStringArray:
355355
"""
356356
Return a shallow copy of the array.
357357
358+
Underlying ChunkedArray is immutable, so a deep copy is unnecessary.
359+
358360
Returns
359361
-------
360362
ArrowStringArray

pandas/core/construction.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,9 @@ def extract_array(
388388
----------
389389
obj : object
390390
For Series / Index, the underlying ExtensionArray is unboxed.
391-
For Numpy-backed ExtensionArrays, the ndarray is extracted.
392391
393392
extract_numpy : bool, default False
394-
Whether to extract the ndarray from a PandasArray
393+
Whether to extract the ndarray from a PandasArray.
395394
396395
extract_range : bool, default False
397396
If we have a RangeIndex, return range._values if True

pandas/core/dtypes/base.py

+4
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ def empty(self, shape: Shape) -> type_t[ExtensionArray]:
215215
216216
Analogous to numpy.empty.
217217
218+
Parameters
219+
----------
220+
shape : int or tuple[int]
221+
218222
Returns
219223
-------
220224
ExtensionArray

pandas/core/frame.py

+6
Original file line numberDiff line numberDiff line change
@@ -5847,6 +5847,9 @@ def isna(self) -> DataFrame:
58475847

58485848
@doc(NDFrame.isna, klass=_shared_doc_kwargs["klass"])
58495849
def isnull(self) -> DataFrame:
5850+
"""
5851+
DataFrame.isnull is an alias for DataFrame.isna.
5852+
"""
58505853
return self.isna()
58515854

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

58565859
@doc(NDFrame.notna, klass=_shared_doc_kwargs["klass"])
58575860
def notnull(self) -> DataFrame:
5861+
"""
5862+
DataFrame.notnull is an alias for DataFrame.notna.
5863+
"""
58585864
return ~self.isna()
58595865

58605866
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])

pandas/core/reshape/pivot.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,7 @@ def __internal_pivot_table(
221221
table = table.sort_index(axis=1)
222222

223223
if fill_value is not None:
224-
_table = table.fillna(fill_value, downcast="infer")
225-
assert _table is not None # needed for mypy
226-
table = _table
224+
table = table.fillna(fill_value, downcast="infer")
227225

228226
if margins:
229227
if dropna:

pandas/core/series.py

+6
Original file line numberDiff line numberDiff line change
@@ -5231,6 +5231,9 @@ def isna(self) -> Series:
52315231
# error: Cannot determine type of 'isna'
52325232
@doc(NDFrame.isna, klass=_shared_doc_kwargs["klass"]) # type: ignore[has-type]
52335233
def isnull(self) -> Series:
5234+
"""
5235+
Series.isnull is an alias for Series.isna.
5236+
"""
52345237
return super().isnull()
52355238

52365239
# error: Cannot determine type of 'notna'
@@ -5241,6 +5244,9 @@ def notna(self) -> Series:
52415244
# error: Cannot determine type of 'notna'
52425245
@doc(NDFrame.notna, klass=_shared_doc_kwargs["klass"]) # type: ignore[has-type]
52435246
def notnull(self) -> Series:
5247+
"""
5248+
Series.notnull is an alias for Series.notna.
5249+
"""
52445250
return super().notnull()
52455251

52465252
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])

pandas/tests/base/test_misc.py

+13
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@
2121
import pandas._testing as tm
2222

2323

24+
def test_isnull_notnull_docstrings():
25+
# GH#41855 make sure its clear these are aliases
26+
doc = pd.DataFrame.notnull.__doc__
27+
assert doc.startswith("\nDataFrame.notnull is an alias for DataFrame.notna.\n")
28+
doc = pd.DataFrame.isnull.__doc__
29+
assert doc.startswith("\nDataFrame.isnull is an alias for DataFrame.isna.\n")
30+
31+
doc = Series.notnull.__doc__
32+
assert doc.startswith("\nSeries.notnull is an alias for Series.notna.\n")
33+
doc = Series.isnull.__doc__
34+
assert doc.startswith("\nSeries.isnull is an alias for Series.isna.\n")
35+
36+
2437
@pytest.mark.parametrize(
2538
"op_name, op",
2639
[

pandas/tests/scalar/test_nat.py

+5
Original file line numberDiff line numberDiff line change
@@ -718,3 +718,8 @@ def test_pickle():
718718
# GH#4606
719719
p = tm.round_trip_pickle(NaT)
720720
assert p is NaT
721+
722+
723+
def test_freq_deprecated():
724+
with tm.assert_produces_warning(FutureWarning, match="deprecated"):
725+
NaT.freq

pandas/tests/tools/test_to_datetime.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1659,7 +1659,8 @@ def test_to_datetime_respects_dayfirst(self, cache):
16591659
with pytest.raises(ValueError, match=msg):
16601660
# if dayfirst is respected, then this would parse as month=13, which
16611661
# would raise
1662-
to_datetime("01-13-2012", dayfirst=True, cache=cache)
1662+
with tm.assert_produces_warning(UserWarning, match="Provide format"):
1663+
to_datetime("01-13-2012", dayfirst=True, cache=cache)
16631664

16641665
def test_to_datetime_on_datetime64_series(self, cache):
16651666
# #2699
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import pandas as pd
2+
import pandas._testing as tm
3+
4+
5+
def test_shares_memory_interval():
6+
obj = pd.interval_range(1, 5)
7+
8+
assert tm.shares_memory(obj, obj)
9+
assert tm.shares_memory(obj, obj._data)
10+
assert tm.shares_memory(obj, obj[::-1])
11+
assert tm.shares_memory(obj, obj[:2])
12+
13+
assert not tm.shares_memory(obj, obj._data.copy())

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ def run(self):
392392
# ----------------------------------------------------------------------
393393
# Specification of Dependencies
394394

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

0 commit comments

Comments
 (0)