Skip to content

Commit bf97e50

Browse files
Merge remote-tracking branch 'upstream/main' into enh_top-level_object_name
2 parents dbaf5f5 + f9d2e50 commit bf97e50

File tree

11 files changed

+34
-11
lines changed

11 files changed

+34
-11
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ Categorical
613613
Datetimelike
614614
^^^^^^^^^^^^
615615
- Bug in :attr:`is_year_start` where a DateTimeIndex constructed via a date_range with frequency 'MS' wouldn't have the correct year or quarter start attributes (:issue:`57377`)
616+
- Bug in :class:`DataFrame` raising ``ValueError`` when ``dtype`` is ``timedelta64`` and ``data`` is a list containing ``None`` (:issue:`60064`)
616617
- Bug in :class:`Timestamp` constructor failing to raise when ``tz=None`` is explicitly specified in conjunction with timezone-aware ``tzinfo`` or data (:issue:`48688`)
617618
- Bug in :func:`date_range` where the last valid timestamp would sometimes not be produced (:issue:`56134`)
618619
- Bug in :func:`date_range` where using a negative frequency value would not include all points between the start and end values (:issue:`56147`)
@@ -710,6 +711,7 @@ Period
710711
Plotting
711712
^^^^^^^^
712713
- Bug in :meth:`.DataFrameGroupBy.boxplot` failed when there were multiple groupings (:issue:`14701`)
714+
- Bug in :meth:`DataFrame.plot.bar` with ``stacked=True`` where labels on stacked bars with zero-height segments were incorrectly positioned at the base instead of the label position of the previous segment (:issue:`59429`)
713715
- Bug in :meth:`DataFrame.plot.line` raising ``ValueError`` when set both color and a ``dict`` style (:issue:`59461`)
714716
- Bug in :meth:`DataFrame.plot` that causes a shift to the right when the frequency multiplier is greater than one. (:issue:`57587`)
715717
- Bug in :meth:`Series.plot` with ``kind="pie"`` with :class:`ArrowDtype` (:issue:`59192`)

pandas/_libs/tslibs/period.pyx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ from pandas._libs.tslibs.offsets import (
114114
INVALID_FREQ_ERR_MSG,
115115
BDay,
116116
)
117-
118117
from pandas.util._decorators import set_module
119118

120119
cdef:

pandas/_libs/tslibs/timedeltas.pyx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import collections
22
import warnings
33

4-
from pandas.util._exceptions import find_stack_level
54
from pandas.util._decorators import set_module
5+
from pandas.util._exceptions import find_stack_level
66

77
cimport cython
88
from cpython.object cimport (
@@ -1855,7 +1855,6 @@ cdef class _Timedelta(timedelta):
18551855

18561856
# Python front end to C extension type _Timedelta
18571857
# This serves as the box for timedelta64
1858-
18591858
@set_module("pandas")
18601859
class Timedelta(_Timedelta):
18611860
"""
@@ -1918,7 +1917,7 @@ class Timedelta(_Timedelta):
19181917
--------
19191918
Here we initialize Timedelta object with both value and unit
19201919
1921-
>>> td = pd.Timedelta(1, "d")
1920+
>>> td = pd.Timedelta(1, "D")
19221921
>>> td
19231922
Timedelta('1 days 00:00:00')
19241923

pandas/_libs/tslibs/timestamps.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ import datetime as dt
5050
from pandas._libs.tslibs cimport ccalendar
5151
from pandas._libs.tslibs.base cimport ABCTimestamp
5252

53-
from pandas.util._exceptions import find_stack_level
5453
from pandas.util._decorators import set_module
54+
from pandas.util._exceptions import find_stack_level
5555

5656
from pandas._libs.tslibs.conversion cimport (
5757
_TSObject,
@@ -2927,7 +2927,7 @@ timedelta}, default 'raise'
29272927
--------
29282928
>>> ts = pd.Timestamp(1584226800, unit='s', tz='Europe/Stockholm')
29292929
>>> ts.tz
2930-
<DstTzInfo 'Europe/Stockholm' CET+1:00:00 STD>
2930+
zoneinfo.ZoneInfo(key='Europe/Stockholm')
29312931
"""
29322932
return self.tzinfo
29332933

pandas/core/construction.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,12 @@ def _try_cast(
807807
)
808808

809809
elif dtype.kind in "mM":
810+
if is_ndarray:
811+
arr = cast(np.ndarray, arr)
812+
if arr.ndim == 2 and arr.shape[1] == 1:
813+
# GH#60081: DataFrame Constructor converts 1D data to array of
814+
# shape (N, 1), but maybe_cast_to_datetime assumes 1D input
815+
return maybe_cast_to_datetime(arr[:, 0], dtype).reshape(arr.shape)
810816
return maybe_cast_to_datetime(arr, dtype)
811817

812818
# GH#15832: Check if we are requesting a numeric dtype and

pandas/core/dtypes/cast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ def maybe_infer_to_datetimelike(
12051205

12061206
def maybe_cast_to_datetime(
12071207
value: np.ndarray | list, dtype: np.dtype
1208-
) -> ExtensionArray | np.ndarray:
1208+
) -> DatetimeArray | TimedeltaArray | np.ndarray:
12091209
"""
12101210
try to cast the array/value to a datetimelike dtype, converting float
12111211
nan to iNaT

pandas/plotting/_matplotlib/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1960,7 +1960,7 @@ def _make_plot(self, fig: Figure) -> None:
19601960
)
19611961
ax.set_title(label)
19621962
elif self.stacked:
1963-
mask = y > 0
1963+
mask = y >= 0
19641964
start = np.where(mask, pos_prior, neg_prior) + self._start_base
19651965
w = self.bar_width / 2
19661966
rect = self._plot(

pandas/tests/api/test_api.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,6 @@ def test_set_module():
413413
assert pd.PeriodIndex.__module__ == "pandas"
414414
assert pd.RangeIndex.__module__ == "pandas"
415415
assert pd.TimedeltaIndex.__module__ == "pandas"
416+
assert pd.Period.__module__ == "pandas"
416417
assert pd.Timestamp.__module__ == "pandas"
417418
assert pd.Timedelta.__module__ == "pandas"
418-
assert pd.Period.__module__ == "pandas"
419-

pandas/tests/frame/test_constructors.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2772,6 +2772,14 @@ def test_construction_datetime_resolution_inference(self, cons):
27722772
res_dtype2 = tm.get_dtype(obj2)
27732773
assert res_dtype2 == "M8[us, US/Pacific]", res_dtype2
27742774

2775+
def test_construction_nan_value_timedelta64_dtype(self):
2776+
# GH#60064
2777+
result = DataFrame([None, 1], dtype="timedelta64[ns]")
2778+
expected = DataFrame(
2779+
["NaT", "0 days 00:00:00.000000001"], dtype="timedelta64[ns]"
2780+
)
2781+
tm.assert_frame_equal(result, expected)
2782+
27752783

27762784
class TestDataFrameConstructorIndexInference:
27772785
def test_frame_from_dict_of_series_overlapping_monthly_period_indexes(self):

pandas/tests/plotting/frame/test_frame.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,16 @@ def test_bar_nan_stacked(self):
774774
expected = [0.0, 0.0, 0.0, 10.0, 0.0, 20.0, 15.0, 10.0, 40.0]
775775
assert result == expected
776776

777+
def test_bar_stacked_label_position_with_zero_height(self):
778+
# GH 59429
779+
df = DataFrame({"A": [3, 0, 1], "B": [0, 2, 4], "C": [5, 0, 2]})
780+
ax = df.plot.bar(stacked=True)
781+
ax.bar_label(ax.containers[-1])
782+
expected = [8.0, 2.0, 7.0]
783+
result = [text.xy[1] for text in ax.texts]
784+
tm.assert_almost_equal(result, expected)
785+
plt.close("all")
786+
777787
@pytest.mark.parametrize("idx", [Index, pd.CategoricalIndex])
778788
def test_bar_categorical(self, idx):
779789
# GH 13019

0 commit comments

Comments
 (0)