Skip to content

Commit 683b611

Browse files
author
Khor Chean Wei
authored
Merge branch 'main' into enh-consistency-interval-range
2 parents 543dfc5 + 5414a2d commit 683b611

File tree

19 files changed

+249
-56
lines changed

19 files changed

+249
-56
lines changed

doc/source/getting_started/install.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ Computation
276276
========================= ================== =============================================================
277277
Dependency Minimum Version Notes
278278
========================= ================== =============================================================
279-
SciPy 1.14.1 Miscellaneous statistical functions
279+
SciPy 1.4.1 Miscellaneous statistical functions
280280
numba 0.50.1 Alternative execution engine for rolling operations
281281
(see :ref:`Enhancing Performance <enhancingperf.numba>`)
282282
xarray 0.15.1 pandas-like API for N-dimensional data

doc/source/whatsnew/v1.5.0.rst

+7
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ did not have the same index as the input.
110110
df.groupby('a', dropna=True).transform(lambda x: x)
111111
df.groupby('a', dropna=True).transform('sum')
112112
113+
.. _whatsnew_150.notable_bug_fixes.visualization:
114+
115+
Styler
116+
^^^^^^
117+
118+
- Fix showing "None" as ylabel in :meth:`Series.plot` when not setting ylabel (:issue:`46129`)
119+
113120
.. _whatsnew_150.notable_bug_fixes.notable_bug_fix2:
114121

115122
notable_bug_fix2

pandas/_libs/tslibs/dtypes.pxd

+3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
from numpy cimport int64_t
2+
13
from pandas._libs.tslibs.np_datetime cimport NPY_DATETIMEUNIT
24

35

46
cdef str npy_unit_to_abbrev(NPY_DATETIMEUNIT unit)
57
cdef NPY_DATETIMEUNIT freq_group_code_to_npy_unit(int freq) nogil
8+
cdef int64_t periods_per_day(NPY_DATETIMEUNIT reso=*)
69

710
cdef dict attrname_to_abbrevs
811

pandas/_libs/tslibs/dtypes.pyx

+30
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,36 @@ cdef NPY_DATETIMEUNIT freq_group_code_to_npy_unit(int freq) nogil:
307307
return NPY_DATETIMEUNIT.NPY_FR_D
308308

309309

310+
cdef int64_t periods_per_day(NPY_DATETIMEUNIT reso=NPY_DATETIMEUNIT.NPY_FR_ns):
311+
"""
312+
How many of the given time units fit into a single day?
313+
"""
314+
cdef:
315+
int64_t day_units
316+
317+
if reso == NPY_DATETIMEUNIT.NPY_FR_ps:
318+
# pico is the smallest unit for which we don't overflow, so
319+
# we exclude fempto and atto
320+
day_units = 24 * 3600 * 1_000_000_000_000
321+
elif reso == NPY_DATETIMEUNIT.NPY_FR_ns:
322+
day_units = 24 * 3600 * 1_000_000_000
323+
elif reso == NPY_DATETIMEUNIT.NPY_FR_us:
324+
day_units = 24 * 3600 * 1_000_000
325+
elif reso == NPY_DATETIMEUNIT.NPY_FR_ms:
326+
day_units = 24 * 3600 * 1_000
327+
elif reso == NPY_DATETIMEUNIT.NPY_FR_s:
328+
day_units = 24 * 3600
329+
elif reso == NPY_DATETIMEUNIT.NPY_FR_m:
330+
day_units = 24 * 60
331+
elif reso == NPY_DATETIMEUNIT.NPY_FR_h:
332+
day_units = 24
333+
elif reso == NPY_DATETIMEUNIT.NPY_FR_D:
334+
day_units = 1
335+
else:
336+
raise NotImplementedError(reso)
337+
return day_units
338+
339+
310340
cdef dict _reso_str_map = {
311341
Resolution.RESO_NS.value: "nanosecond",
312342
Resolution.RESO_US.value: "microsecond",

pandas/_libs/tslibs/vectorized.pyx

+10-16
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ cnp.import_array()
2121
from .conversion cimport normalize_i8_stamp
2222

2323
from .dtypes import Resolution
24+
2425
from .ccalendar cimport DAY_NANOS
26+
from .dtypes cimport c_Resolution
2527
from .nattype cimport (
2628
NPY_NAT,
2729
c_NaT as NaT,
@@ -168,27 +170,19 @@ def ints_to_pydatetime(
168170

169171
# -------------------------------------------------------------------------
170172

171-
cdef:
172-
int RESO_US = Resolution.RESO_US.value
173-
int RESO_MS = Resolution.RESO_MS.value
174-
int RESO_SEC = Resolution.RESO_SEC.value
175-
int RESO_MIN = Resolution.RESO_MIN.value
176-
int RESO_HR = Resolution.RESO_HR.value
177-
int RESO_DAY = Resolution.RESO_DAY.value
178-
179173

180-
cdef inline int _reso_stamp(npy_datetimestruct *dts):
174+
cdef inline c_Resolution _reso_stamp(npy_datetimestruct *dts):
181175
if dts.us != 0:
182176
if dts.us % 1000 == 0:
183-
return RESO_MS
184-
return RESO_US
177+
return c_Resolution.RESO_MS
178+
return c_Resolution.RESO_US
185179
elif dts.sec != 0:
186-
return RESO_SEC
180+
return c_Resolution.RESO_SEC
187181
elif dts.min != 0:
188-
return RESO_MIN
182+
return c_Resolution.RESO_MIN
189183
elif dts.hour != 0:
190-
return RESO_HR
191-
return RESO_DAY
184+
return c_Resolution.RESO_HR
185+
return c_Resolution.RESO_DAY
192186

193187

194188
@cython.wraparound(False)
@@ -205,7 +199,7 @@ def get_resolution(const int64_t[:] stamps, tzinfo tz=None) -> Resolution:
205199
str typ
206200

207201
npy_datetimestruct dts
208-
int reso = RESO_DAY, curr_reso
202+
c_Resolution reso = c_Resolution.RESO_DAY, curr_reso
209203

210204
if is_utc(tz) or tz is None:
211205
use_utc = True

pandas/_typing.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ def closed(self) -> bool:
297297
else:
298298
TakeIndexer = Any
299299

300+
# Shared by functions such as drop and astype
301+
IgnoreRaise = Literal["ignore", "raise"]
302+
300303
# Windowing rank methods
301304
WindowingRankType = Literal["average", "min", "max"]
302305

@@ -311,7 +314,7 @@ def closed(self) -> bool:
311314

312315
# datetime and NaTType
313316
DatetimeNaTType = Union[datetime, "NaTType"]
314-
DateTimeErrorChoices = Literal["ignore", "raise", "coerce"]
317+
DateTimeErrorChoices = Union[IgnoreRaise, Literal["coerce"]]
315318

316319
# sort_index
317320
SortKind = Literal["quicksort", "mergesort", "heapsort", "stable"]

pandas/core/common.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ def asarray_tuplesafe(values, dtype: NpDtype | None = None) -> np.ndarray:
250250
return result
251251

252252

253-
def index_labels_to_array(labels, dtype: NpDtype | None = None) -> np.ndarray:
253+
def index_labels_to_array(
254+
labels: np.ndarray | Iterable, dtype: NpDtype | None = None
255+
) -> np.ndarray:
254256
"""
255257
Transform label or iterable of labels to array, for use in Index.
256258

pandas/core/dtypes/astype.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from pandas._typing import (
2020
ArrayLike,
2121
DtypeObj,
22+
IgnoreRaise,
2223
)
2324
from pandas.errors import IntCastingNaNError
2425
from pandas.util._exceptions import find_stack_level
@@ -235,7 +236,7 @@ def astype_array(values: ArrayLike, dtype: DtypeObj, copy: bool = False) -> Arra
235236

236237

237238
def astype_array_safe(
238-
values: ArrayLike, dtype, copy: bool = False, errors: str = "raise"
239+
values: ArrayLike, dtype, copy: bool = False, errors: IgnoreRaise = "raise"
239240
) -> ArrayLike:
240241
"""
241242
Cast array (ndarray or ExtensionArray) to the new dtype.

pandas/core/frame.py

+53-8
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
FloatFormatType,
5959
FormattersType,
6060
Frequency,
61+
IgnoreRaise,
6162
IndexKeyFunc,
6263
IndexLabel,
6364
Level,
@@ -4831,17 +4832,61 @@ def reindex(self, *args, **kwargs) -> DataFrame:
48314832
kwargs.pop("labels", None)
48324833
return super().reindex(**kwargs)
48334834

4834-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "labels"])
4835+
@overload
4836+
def drop(
4837+
self,
4838+
labels: Hashable | list[Hashable] = ...,
4839+
*,
4840+
axis: Axis = ...,
4841+
index: Hashable | list[Hashable] = ...,
4842+
columns: Hashable | list[Hashable] = ...,
4843+
level: Level | None = ...,
4844+
inplace: Literal[True],
4845+
errors: IgnoreRaise = ...,
4846+
) -> None:
4847+
...
4848+
4849+
@overload
48354850
def drop(
48364851
self,
4837-
labels=None,
4852+
labels: Hashable | list[Hashable] = ...,
4853+
*,
4854+
axis: Axis = ...,
4855+
index: Hashable | list[Hashable] = ...,
4856+
columns: Hashable | list[Hashable] = ...,
4857+
level: Level | None = ...,
4858+
inplace: Literal[False] = ...,
4859+
errors: IgnoreRaise = ...,
4860+
) -> DataFrame:
4861+
...
4862+
4863+
@overload
4864+
def drop(
4865+
self,
4866+
labels: Hashable | list[Hashable] = ...,
4867+
*,
4868+
axis: Axis = ...,
4869+
index: Hashable | list[Hashable] = ...,
4870+
columns: Hashable | list[Hashable] = ...,
4871+
level: Level | None = ...,
4872+
inplace: bool = ...,
4873+
errors: IgnoreRaise = ...,
4874+
) -> DataFrame | None:
4875+
...
4876+
4877+
# error: Signature of "drop" incompatible with supertype "NDFrame"
4878+
# github.com/python/mypy/issues/12387
4879+
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "labels"])
4880+
def drop( # type: ignore[override]
4881+
self,
4882+
labels: Hashable | list[Hashable] = None,
48384883
axis: Axis = 0,
4839-
index=None,
4840-
columns=None,
4884+
index: Hashable | list[Hashable] = None,
4885+
columns: Hashable | list[Hashable] = None,
48414886
level: Level | None = None,
48424887
inplace: bool = False,
4843-
errors: str = "raise",
4844-
):
4888+
errors: IgnoreRaise = "raise",
4889+
) -> DataFrame | None:
48454890
"""
48464891
Drop specified labels from rows or columns.
48474892
@@ -11187,7 +11232,7 @@ def where(
1118711232
inplace=False,
1118811233
axis=None,
1118911234
level=None,
11190-
errors="raise",
11235+
errors: IgnoreRaise = "raise",
1119111236
try_cast=lib.no_default,
1119211237
):
1119311238
return super().where(cond, other, inplace, axis, level, errors, try_cast)
@@ -11202,7 +11247,7 @@ def mask(
1120211247
inplace=False,
1120311248
axis=None,
1120411249
level=None,
11205-
errors="raise",
11250+
errors: IgnoreRaise = "raise",
1120611251
try_cast=lib.no_default,
1120711252
):
1120811253
return super().mask(cond, other, inplace, axis, level, errors, try_cast)

pandas/core/generic.py

+57-12
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
DtypeArg,
4545
DtypeObj,
4646
FilePath,
47+
IgnoreRaise,
4748
IndexKeyFunc,
4849
IndexLabel,
4950
IntervalClosedType,
@@ -71,6 +72,7 @@
7172
)
7273
from pandas.util._decorators import (
7374
deprecate_kwarg,
75+
deprecate_nonkeyword_arguments,
7476
doc,
7577
rewrite_axis_style_signature,
7678
)
@@ -4270,16 +4272,59 @@ def reindex_like(
42704272

42714273
return self.reindex(**d)
42724274

4275+
@overload
42734276
def drop(
42744277
self,
4275-
labels=None,
4276-
axis=0,
4277-
index=None,
4278-
columns=None,
4279-
level=None,
4278+
labels: Hashable | list[Hashable] = ...,
4279+
*,
4280+
axis: Axis = ...,
4281+
index: Hashable | list[Hashable] = ...,
4282+
columns: Hashable | list[Hashable] = ...,
4283+
level: Level | None = ...,
4284+
inplace: Literal[True],
4285+
errors: IgnoreRaise = ...,
4286+
) -> None:
4287+
...
4288+
4289+
@overload
4290+
def drop(
4291+
self: NDFrameT,
4292+
labels: Hashable | list[Hashable] = ...,
4293+
*,
4294+
axis: Axis = ...,
4295+
index: Hashable | list[Hashable] = ...,
4296+
columns: Hashable | list[Hashable] = ...,
4297+
level: Level | None = ...,
4298+
inplace: Literal[False] = ...,
4299+
errors: IgnoreRaise = ...,
4300+
) -> NDFrameT:
4301+
...
4302+
4303+
@overload
4304+
def drop(
4305+
self: NDFrameT,
4306+
labels: Hashable | list[Hashable] = ...,
4307+
*,
4308+
axis: Axis = ...,
4309+
index: Hashable | list[Hashable] = ...,
4310+
columns: Hashable | list[Hashable] = ...,
4311+
level: Level | None = ...,
4312+
inplace: bool_t = ...,
4313+
errors: IgnoreRaise = ...,
4314+
) -> NDFrameT | None:
4315+
...
4316+
4317+
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "labels"])
4318+
def drop(
4319+
self: NDFrameT,
4320+
labels: Hashable | list[Hashable] = None,
4321+
axis: Axis = 0,
4322+
index: Hashable | list[Hashable] = None,
4323+
columns: Hashable | list[Hashable] = None,
4324+
level: Level | None = None,
42804325
inplace: bool_t = False,
4281-
errors: str = "raise",
4282-
):
4326+
errors: IgnoreRaise = "raise",
4327+
) -> NDFrameT | None:
42834328

42844329
inplace = validate_bool_kwarg(inplace, "inplace")
42854330

@@ -4312,7 +4357,7 @@ def _drop_axis(
43124357
labels,
43134358
axis,
43144359
level=None,
4315-
errors: str = "raise",
4360+
errors: IgnoreRaise = "raise",
43164361
only_slice: bool_t = False,
43174362
) -> NDFrameT:
43184363
"""
@@ -5826,7 +5871,7 @@ def dtypes(self):
58265871
return self._constructor_sliced(data, index=self._info_axis, dtype=np.object_)
58275872

58285873
def astype(
5829-
self: NDFrameT, dtype, copy: bool_t = True, errors: str = "raise"
5874+
self: NDFrameT, dtype, copy: bool_t = True, errors: IgnoreRaise = "raise"
58305875
) -> NDFrameT:
58315876
"""
58325877
Cast a pandas object to a specified dtype ``dtype``.
@@ -9139,7 +9184,7 @@ def _where(
91399184
inplace=False,
91409185
axis=None,
91419186
level=None,
9142-
errors="raise",
9187+
errors: IgnoreRaise = "raise",
91439188
):
91449189
"""
91459190
Equivalent to public method `where`, except that `other` is not
@@ -9278,7 +9323,7 @@ def where(
92789323
inplace=False,
92799324
axis=None,
92809325
level=None,
9281-
errors="raise",
9326+
errors: IgnoreRaise = "raise",
92829327
try_cast=lib.no_default,
92839328
):
92849329
"""
@@ -9431,7 +9476,7 @@ def mask(
94319476
inplace=False,
94329477
axis=None,
94339478
level=None,
9434-
errors="raise",
9479+
errors: IgnoreRaise = "raise",
94359480
try_cast=lib.no_default,
94369481
):
94379482

0 commit comments

Comments
 (0)