Skip to content

Commit 06cafd9

Browse files
committed
Refinements
1 parent 32288dc commit 06cafd9

File tree

11 files changed

+48
-48
lines changed

11 files changed

+48
-48
lines changed

pandas/_libs/missing.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ class NAType(C_NAType):
394394
True
395395
"""
396396
__module__ = "pandas.api.typing"
397+
397398
_instance = None
398399

399400
def __new__(cls, *args, **kwargs):

pandas/_libs/tslibs/nattype.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ class NaTType(_NaT):
371371
0 2023-01-01
372372
1 NaT
373373
"""
374+
374375
__module__ = "pandas.api.typing"
375376

376377
def __new__(cls):

pandas/_libs/tslibs/np_datetime.pyx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ class OutOfBoundsDatetime(ValueError):
193193
at position 0
194194
"""
195195
__module__ = "pandas.errors"
196+
pass
196197

197198

198199
class OutOfBoundsTimedelta(ValueError):
@@ -212,8 +213,9 @@ class OutOfBoundsTimedelta(ValueError):
212213
OutOfBoundsTimedelta: Cannot cast 139999 days 00:00:00
213214
to unit='ns' without overflow.
214215
"""
215-
# Timedelta analogue to OutOfBoundsDatetime
216216
__module__ = "pandas.errors"
217+
# Timedelta analogue to OutOfBoundsDatetime
218+
pass
217219

218220

219221
cdef get_implementation_bounds(

pandas/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,14 @@ def pytest_sessionstart(session):
113113
import doctest
114114
import inspect
115115

116-
orig = doctest.DocTestFinder._from_module
116+
orig = doctest.DocTestFinder._from_module # type: ignore[attr-defined]
117117

118118
def _from_module(self, module, object):
119119
if inspect.isfunction(object) and "." in object.__qualname__:
120120
return True
121121
return orig(self, module, object)
122122

123-
doctest.DocTestFinder._from_module = _from_module
123+
doctest.DocTestFinder._from_module = _from_module # type: ignore[attr-defined]
124124

125125

126126
def ignore_doctest_warning(item: pytest.Item, path: str, message: str) -> None:

pandas/core/arrays/datetimes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -894,13 +894,13 @@ def tz_convert(self, tz) -> Self:
894894
DatetimeIndex(['2014-08-01 09:00:00+02:00',
895895
'2014-08-01 10:00:00+02:00',
896896
'2014-08-01 11:00:00+02:00'],
897-
dtype='datetime64[ns, Europe/Berlin]', freq='h')
897+
dtype='datetime64[us, Europe/Berlin]', freq='h')
898898
899899
>>> dti.tz_convert("US/Central")
900900
DatetimeIndex(['2014-08-01 02:00:00-05:00',
901901
'2014-08-01 03:00:00-05:00',
902902
'2014-08-01 04:00:00-05:00'],
903-
dtype='datetime64[ns, US/Central]', freq='h')
903+
dtype='datetime64[us, US/Central]', freq='h')
904904
905905
With the ``tz=None``, we can remove the timezone (after converting
906906
to UTC if necessary):

pandas/core/arrays/masked.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
from pandas.core.dtypes.base import ExtensionDtype
3434
from pandas.core.dtypes.cast import (
3535
maybe_downcast_to_dtype,
36-
maybe_unbox_numpy_scalar,
3736
)
3837
from pandas.core.dtypes.common import (
3938
is_bool,
@@ -1742,25 +1741,25 @@ def any(
17421741
skips NAs):
17431742
17441743
>>> pd.array([True, False, True]).any()
1745-
True
1744+
np.True_
17461745
>>> pd.array([True, False, pd.NA]).any()
1747-
True
1746+
np.True_
17481747
>>> pd.array([False, False, pd.NA]).any()
1749-
False
1748+
np.False_
17501749
>>> pd.array([], dtype="boolean").any()
1751-
False
1750+
np.False_
17521751
>>> pd.array([pd.NA], dtype="boolean").any()
1753-
False
1752+
np.False_
17541753
>>> pd.array([pd.NA], dtype="Float64").any()
1755-
False
1754+
np.False_
17561755
17571756
With ``skipna=False``, the result can be NA if this is logically
17581757
required (whether ``pd.NA`` is True or False influences the result):
17591758
17601759
>>> pd.array([True, False, pd.NA]).any(skipna=False)
1761-
True
1760+
np.True_
17621761
>>> pd.array([1, 0, pd.NA]).any(skipna=False)
1763-
True
1762+
np.True_
17641763
>>> pd.array([False, False, pd.NA]).any(skipna=False)
17651764
<NA>
17661765
>>> pd.array([0, 0, pd.NA]).any(skipna=False)
@@ -1770,7 +1769,7 @@ def any(
17701769

17711770
values = self._data.copy()
17721771
np.putmask(values, self._mask, self.dtype._falsey_value)
1773-
result = maybe_unbox_numpy_scalar(values.any())
1772+
result = values.any()
17741773
if skipna:
17751774
return result
17761775
else:
@@ -1828,17 +1827,17 @@ def all(
18281827
skips NAs):
18291828
18301829
>>> pd.array([True, True, pd.NA]).all()
1831-
True
1830+
np.True_
18321831
>>> pd.array([1, 1, pd.NA]).all()
1833-
True
1832+
np.True_
18341833
>>> pd.array([True, False, pd.NA]).all()
1835-
False
1834+
np.False_
18361835
>>> pd.array([], dtype="boolean").all()
1837-
True
1836+
np.True_
18381837
>>> pd.array([pd.NA], dtype="boolean").all()
1839-
True
1838+
np.True_
18401839
>>> pd.array([pd.NA], dtype="Float64").all()
1841-
True
1840+
np.True_
18421841
18431842
With ``skipna=False``, the result can be NA if this is logically
18441843
required (whether ``pd.NA`` is True or False influences the result):
@@ -1848,21 +1847,21 @@ def all(
18481847
>>> pd.array([1, 1, pd.NA]).all(skipna=False)
18491848
<NA>
18501849
>>> pd.array([True, False, pd.NA]).all(skipna=False)
1851-
False
1850+
np.False_
18521851
>>> pd.array([1, 0, pd.NA]).all(skipna=False)
1853-
False
1852+
np.False_
18541853
"""
18551854
nv.validate_all((), kwargs)
18561855

18571856
values = self._data.copy()
18581857
np.putmask(values, self._mask, self.dtype._truthy_value)
1859-
result = maybe_unbox_numpy_scalar(values.all(axis=axis))
1858+
result = values.all(axis=axis)
18601859

18611860
if skipna:
1862-
return result
1861+
return result # type: ignore[return-value]
18631862
else:
18641863
if not result or len(self) == 0 or not self._mask.any():
1865-
return result
1864+
return result # type: ignore[return-value]
18661865
else:
18671866
return self.dtype.na_value
18681867

pandas/core/arrays/timedeltas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ def total_seconds(self) -> npt.NDArray[np.float64]:
813813
>>> idx = pd.to_timedelta(np.arange(5), unit="D")
814814
>>> idx
815815
TimedeltaIndex(['0 days', '1 days', '2 days', '3 days', '4 days'],
816-
dtype='timedelta64[us]', freq=None)
816+
dtype='timedelta64[ns]', freq=None)
817817
818818
>>> idx.total_seconds()
819819
Index([0.0, 86400.0, 172800.0, 259200.0, 345600.0], dtype='float64')
@@ -855,7 +855,7 @@ def to_pytimedelta(self) -> npt.NDArray[np.object_]:
855855
>>> tidx = pd.TimedeltaIndex(data=["1 days 02:30:45", "3 days 04:15:10"])
856856
>>> tidx
857857
TimedeltaIndex(['1 days 02:30:45', '3 days 04:15:10'],
858-
dtype='timedelta64[ns]', freq=None)
858+
dtype='timedelta64[us]', freq=None)
859859
>>> tidx.to_pytimedelta()
860860
array([datetime.timedelta(days=1, seconds=9045),
861861
datetime.timedelta(days=3, seconds=15310)], dtype=object)

pandas/core/indexes/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5936,22 +5936,22 @@ def shift(self, periods: int = 1, freq=None) -> Self:
59365936
>>> month_starts
59375937
DatetimeIndex(['2011-01-01', '2011-02-01', '2011-03-01', '2011-04-01',
59385938
'2011-05-01'],
5939-
dtype='datetime64[ns]', freq='MS')
5939+
dtype='datetime64[us]', freq='MS')
59405940
59415941
Shift the index by 10 days.
59425942
59435943
>>> month_starts.shift(10, freq="D")
59445944
DatetimeIndex(['2011-01-11', '2011-02-11', '2011-03-11', '2011-04-11',
59455945
'2011-05-11'],
5946-
dtype='datetime64[ns]', freq=None)
5946+
dtype='datetime64[us]', freq=None)
59475947
59485948
The default value of `freq` is the `freq` attribute of the index,
59495949
which is 'MS' (month start) in this example.
59505950
59515951
>>> month_starts.shift(10)
59525952
DatetimeIndex(['2011-11-01', '2011-12-01', '2012-01-01', '2012-02-01',
59535953
'2012-03-01'],
5954-
dtype='datetime64[ns]', freq='MS')
5954+
dtype='datetime64[us]', freq='MS')
59555955
"""
59565956
raise NotImplementedError(
59575957
f"This method is only implemented for DatetimeIndex, PeriodIndex and "

pandas/core/indexes/datetimes.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -365,13 +365,13 @@ def tz_convert(self, tz) -> Self:
365365
DatetimeIndex(['2014-08-01 09:00:00+02:00',
366366
'2014-08-01 10:00:00+02:00',
367367
'2014-08-01 11:00:00+02:00'],
368-
dtype='datetime64[ns, Europe/Berlin]', freq='h')
368+
dtype='datetime64[us, Europe/Berlin]', freq='h')
369369
370370
>>> dti.tz_convert("US/Central")
371371
DatetimeIndex(['2014-08-01 02:00:00-05:00',
372372
'2014-08-01 03:00:00-05:00',
373373
'2014-08-01 04:00:00-05:00'],
374-
dtype='datetime64[ns, US/Central]', freq='h')
374+
dtype='datetime64[us, US/Central]', freq='h')
375375
376376
With the ``tz=None``, we can remove the timezone (after converting
377377
to UTC if necessary):
@@ -384,13 +384,13 @@ def tz_convert(self, tz) -> Self:
384384
DatetimeIndex(['2014-08-01 09:00:00+02:00',
385385
'2014-08-01 10:00:00+02:00',
386386
'2014-08-01 11:00:00+02:00'],
387-
dtype='datetime64[ns, Europe/Berlin]', freq='h')
387+
dtype='datetime64[us, Europe/Berlin]', freq='h')
388388
389389
>>> dti.tz_convert(None)
390390
DatetimeIndex(['2014-08-01 07:00:00',
391391
'2014-08-01 08:00:00',
392392
'2014-08-01 09:00:00'],
393-
dtype='datetime64[ns]', freq='h')
393+
dtype='datetime64[us]', freq='h')
394394
""" # noqa: E501
395395
arr = self._data.tz_convert(tz)
396396
return type(self)._simple_new(arr, name=self.name, refs=self._references)
@@ -468,7 +468,7 @@ def tz_localize(
468468
>>> tz_naive
469469
DatetimeIndex(['2018-03-01 09:00:00', '2018-03-02 09:00:00',
470470
'2018-03-03 09:00:00'],
471-
dtype='datetime64[ns]', freq='D')
471+
dtype='datetime64[us]', freq='D')
472472
473473
Localize DatetimeIndex in US/Eastern time zone:
474474
@@ -477,15 +477,15 @@ def tz_localize(
477477
DatetimeIndex(['2018-03-01 09:00:00-05:00',
478478
'2018-03-02 09:00:00-05:00',
479479
'2018-03-03 09:00:00-05:00'],
480-
dtype='datetime64[ns, US/Eastern]', freq=None)
480+
dtype='datetime64[us, US/Eastern]', freq=None)
481481
482482
With the ``tz=None``, we can remove the time zone information
483483
while keeping the local time (not converted to UTC):
484484
485485
>>> tz_aware.tz_localize(None)
486486
DatetimeIndex(['2018-03-01 09:00:00', '2018-03-02 09:00:00',
487487
'2018-03-03 09:00:00'],
488-
dtype='datetime64[ns]', freq=None)
488+
dtype='datetime64[us]', freq=None)
489489
490490
Be careful with DST changes. When there is sequential data, pandas can
491491
infer the DST time:
@@ -505,7 +505,7 @@ def tz_localize(
505505
4 2018-10-28 02:30:00+01:00
506506
5 2018-10-28 03:00:00+01:00
507507
6 2018-10-28 03:30:00+01:00
508-
dtype: datetime64[s, CET]
508+
dtype: datetime64[us, CET]
509509
510510
In some cases, inferring the DST is impossible. In such cases, you can
511511
pass an ndarray to the ambiguous parameter to set the DST explicitly
@@ -517,7 +517,7 @@ def tz_localize(
517517
0 2018-10-28 01:20:00+02:00
518518
1 2018-10-28 02:36:00+02:00
519519
2 2018-10-28 03:46:00+01:00
520-
dtype: datetime64[s, CET]
520+
dtype: datetime64[us, CET]
521521
522522
If the DST transition causes nonexistent times, you can shift these
523523
dates forward or backwards with a timedelta object or `'shift_forward'`

pandas/core/window/expanding.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -900,9 +900,9 @@ def sem(self, ddof: int = 1, numeric_only: bool = False):
900900
901901
>>> s.expanding().sem()
902902
0 NaN
903-
1 0.707107
904-
2 0.707107
905-
3 0.745356
903+
1 0.500000
904+
2 0.577350
905+
3 0.645497
906906
dtype: float64
907907
"""
908908
return super().sem(ddof=ddof, numeric_only=numeric_only)

0 commit comments

Comments
 (0)