Skip to content

Commit b34e1c2

Browse files
committed
Merge branch 'main' into bug-factorize
2 parents bf56892 + 59bb3f4 commit b34e1c2

File tree

28 files changed

+292
-87
lines changed

28 files changed

+292
-87
lines changed

ci/code_checks.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
161161
-i "pandas.Series.str.zfill RT03" \
162162
-i "pandas.Series.struct.dtypes SA01" \
163163
-i "pandas.Series.to_markdown SA01" \
164-
-i "pandas.Series.update PR07,SA01" \
165164
-i "pandas.Timedelta.asm8 SA01" \
166165
-i "pandas.Timedelta.ceil SA01" \
167166
-i "pandas.Timedelta.components SA01" \
@@ -191,9 +190,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
191190
-i "pandas.Timestamp.nanosecond GL08" \
192191
-i "pandas.Timestamp.resolution PR02" \
193192
-i "pandas.Timestamp.second GL08" \
194-
-i "pandas.Timestamp.strptime PR01,SA01" \
195-
-i "pandas.Timestamp.timetz SA01" \
196-
-i "pandas.Timestamp.to_datetime64 SA01" \
197193
-i "pandas.Timestamp.tzinfo GL08" \
198194
-i "pandas.Timestamp.value GL08" \
199195
-i "pandas.Timestamp.year GL08" \

doc/source/whatsnew/v3.0.0.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Other enhancements
3131
- :class:`pandas.api.typing.FrozenList` is available for typing the outputs of :attr:`MultiIndex.names`, :attr:`MultiIndex.codes` and :attr:`MultiIndex.levels` (:issue:`58237`)
3232
- :class:`pandas.api.typing.SASReader` is available for typing the output of :func:`read_sas` (:issue:`55689`)
3333
- :func:`DataFrame.to_excel` now raises an ``UserWarning`` when the character count in a cell exceeds Excel's limitation of 32767 characters (:issue:`56954`)
34+
- :func:`pandas.merge` now validates the ``how`` parameter input (merge type) (:issue:`59435`)
3435
- :func:`read_stata` now returns ``datetime64`` resolutions better matching those natively stored in the stata format (:issue:`55642`)
3536
- :meth:`DataFrame.agg` called with ``axis=1`` and a ``func`` which relabels the result index now raises a ``NotImplementedError`` (:issue:`58807`).
3637
- :meth:`Index.get_loc` now accepts also subclasses of ``tuple`` as keys (:issue:`57922`)
@@ -632,6 +633,7 @@ Period
632633
Plotting
633634
^^^^^^^^
634635
- Bug in :meth:`.DataFrameGroupBy.boxplot` failed when there were multiple groupings (:issue:`14701`)
636+
- Bug in :meth:`DataFrame.plot.line` raising ``ValueError`` when set both color and a ``dict`` style (:issue:`59461`)
635637
- Bug in :meth:`DataFrame.plot` that causes a shift to the right when the frequency multiplier is greater than one. (:issue:`57587`)
636638
- Bug in :meth:`Series.plot` with ``kind="pie"`` with :class:`ArrowDtype` (:issue:`59192`)
637639

@@ -650,6 +652,7 @@ Groupby/resample/rolling
650652
- Bug in :meth:`DataFrameGroupBy.cumsum` where it did not return the correct dtype when the label contained ``None``. (:issue:`58811`)
651653
- Bug in :meth:`DataFrameGroupby.transform` and :meth:`SeriesGroupby.transform` with a reducer and ``observed=False`` that coerces dtype to float when there are unobserved categories. (:issue:`55326`)
652654
- Bug in :meth:`Rolling.apply` where the applied function could be called on fewer than ``min_period`` periods if ``method="table"``. (:issue:`58868`)
655+
- Bug in :meth:`Series.resample` could raise when the the date range ended shortly before a non-existent time. (:issue:`58380`)
653656

654657
Reshaping
655658
^^^^^^^^^

pandas/_libs/lib.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2699,16 +2699,16 @@ def maybe_convert_objects(ndarray[object] objects,
26992699
seen.object_ = True
27002700

27012701
elif seen.str_:
2702-
if using_string_dtype() and is_string_array(objects, skipna=True):
2702+
if convert_to_nullable_dtype and is_string_array(objects, skipna=True):
27032703
from pandas.core.arrays.string_ import StringDtype
27042704

2705-
dtype = StringDtype(na_value=np.nan)
2705+
dtype = StringDtype()
27062706
return dtype.construct_array_type()._from_sequence(objects, dtype=dtype)
27072707

2708-
elif convert_to_nullable_dtype and is_string_array(objects, skipna=True):
2708+
elif using_string_dtype() and is_string_array(objects, skipna=True):
27092709
from pandas.core.arrays.string_ import StringDtype
27102710

2711-
dtype = StringDtype()
2711+
dtype = StringDtype(na_value=np.nan)
27122712
return dtype.construct_array_type()._from_sequence(objects, dtype=dtype)
27132713

27142714
seen.object_ = True

pandas/_libs/tslibs/nattype.pyx

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,17 @@ cdef class _NaT(datetime):
229229

230230
def to_datetime64(self) -> np.datetime64:
231231
"""
232-
Return a numpy.datetime64 object with same precision.
232+
Return a NumPy datetime64 object with same precision.
233+
234+
This method returns a numpy.datetime64 object with the same
235+
date and time information and precision as the pd.Timestamp object.
236+
237+
See Also
238+
--------
239+
numpy.datetime64 : Class to represent dates and times with high precision.
240+
Timestamp.to_numpy : Alias for this method.
241+
Timestamp.asm8 : Alias for this method.
242+
pd.to_datetime : Convert argument to datetime.
233243

234244
Examples
235245
--------
@@ -764,6 +774,19 @@ class NaTType(_NaT):
764774
"""
765775
Return time object with same time and tzinfo.
766776
777+
This method returns a datetime.time object with
778+
the time and tzinfo corresponding to the pd.Timestamp
779+
object, ignoring any information about the day/date.
780+
781+
See Also
782+
--------
783+
datetime.datetime.timetz : Return datetime.time object with the
784+
same time attributes as the datetime object.
785+
datetime.time : Class to represent the time of day, independent
786+
of any particular day.
787+
datetime.datetime.tzinfo : Attribute of datetime.datetime objects
788+
representing the timezone of the datetime object.
789+
767790
Examples
768791
--------
769792
>>> ts = pd.Timestamp('2023-01-01 10:00:00', tz='Europe/Brussels')
@@ -860,9 +883,27 @@ class NaTType(_NaT):
860883
strptime = _make_error_func(
861884
"strptime",
862885
"""
863-
Timestamp.strptime(string, format)
886+
Convert string argument to datetime.
864887
865-
Function is not implemented. Use pd.to_datetime().
888+
This method is not implemented; calling it will raise NotImplementedError.
889+
Use pd.to_datetime() instead.
890+
891+
Parameters
892+
----------
893+
date_string : str
894+
String to convert to a datetime.
895+
format : str, default None
896+
The format string to parse time, e.g. "%d/%m/%Y".
897+
898+
See Also
899+
--------
900+
pd.to_datetime : Convert argument to datetime.
901+
datetime.datetime.strptime : Return a datetime corresponding to a string
902+
representing a date and time, parsed according to a separate
903+
format string.
904+
datetime.datetime.strftime : Return a string representing the date and
905+
time, controlled by an explicit format string.
906+
Timestamp.isoformat : Return the time formatted according to ISO 8601.
866907
867908
Examples
868909
--------

pandas/_libs/tslibs/timestamps.pyx

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,17 @@ cdef class _Timestamp(ABCTimestamp):
13421342
13431343
cpdef to_datetime64(self):
13441344
"""
1345-
Return a numpy.datetime64 object with same precision.
1345+
Return a NumPy datetime64 object with same precision.
1346+
1347+
This method returns a numpy.datetime64 object with the same
1348+
date and time information and precision as the pd.Timestamp object.
1349+
1350+
See Also
1351+
--------
1352+
numpy.datetime64 : Class to represent dates and times with high precision.
1353+
Timestamp.to_numpy : Alias for this method.
1354+
Timestamp.asm8 : Alias for this method.
1355+
pd.to_datetime : Convert argument to datetime.
13461356

13471357
Examples
13481358
--------
@@ -2093,6 +2103,19 @@ class Timestamp(_Timestamp):
20932103
"""
20942104
Return time object with same time and tzinfo.
20952105

2106+
This method returns a datetime.time object with
2107+
the time and tzinfo corresponding to the pd.Timestamp
2108+
object, ignoring any information about the day/date.
2109+
2110+
See Also
2111+
--------
2112+
datetime.datetime.timetz : Return datetime.time object with the
2113+
same time attributes as the datetime object.
2114+
datetime.time : Class to represent the time of day, independent
2115+
of any particular day.
2116+
datetime.datetime.tzinfo : Attribute of datetime.datetime objects
2117+
representing the timezone of the datetime object.
2118+
20962119
Examples
20972120
--------
20982121
>>> ts = pd.Timestamp('2023-01-01 10:00:00', tz='Europe/Brussels')
@@ -2141,9 +2164,27 @@ class Timestamp(_Timestamp):
21412164
@classmethod
21422165
def strptime(cls, date_string, format):
21432166
"""
2144-
Timestamp.strptime(string, format)
2167+
Convert string argument to datetime.
21452168

2146-
Function is not implemented. Use pd.to_datetime().
2169+
This method is not implemented; calling it will raise NotImplementedError.
2170+
Use pd.to_datetime() instead.
2171+
2172+
Parameters
2173+
----------
2174+
date_string : str
2175+
String to convert to a datetime.
2176+
format : str, default None
2177+
The format string to parse time, e.g. "%d/%m/%Y".
2178+
2179+
See Also
2180+
--------
2181+
pd.to_datetime : Convert argument to datetime.
2182+
datetime.datetime.strptime : Return a datetime corresponding to a string
2183+
representing a date and time, parsed according to a separate
2184+
format string.
2185+
datetime.datetime.strftime : Return a string representing the date and
2186+
time, controlled by an explicit format string.
2187+
Timestamp.isoformat : Return the time formatted according to ISO 8601.
21472188

21482189
Examples
21492190
--------
@@ -3073,7 +3114,8 @@ default 'raise'
30733114
"""
30743115
Convert TimeStamp to a Julian Date.
30753116

3076-
0 Julian date is noon January 1, 4713 BC.
3117+
This method returns the number of days as a float since
3118+
0 Julian date, which is noon January 1, 4713 BC.
30773119

30783120
See Also
30793121
--------

pandas/core/generic.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,10 @@ def _get_cleaned_column_resolvers(self) -> dict[Hashable, Series]:
600600
if isinstance(self, ABCSeries):
601601
return {clean_column_name(self.name): self}
602602

603+
dtypes = self.dtypes
603604
return {
604605
clean_column_name(k): Series(
605-
v, copy=False, index=self.index, name=k, dtype=self.dtypes[k]
606+
v, copy=False, index=self.index, name=k, dtype=dtypes[k]
606607
).__finalize__(self)
607608
for k, v in zip(self.columns, self._iter_column_arrays())
608609
if not isinstance(k, int)
@@ -7486,9 +7487,13 @@ def replace(
74867487
if inplace:
74877488
return None
74887489
return self.copy(deep=False)
7489-
74907490
if is_dict_like(to_replace):
74917491
if is_dict_like(value): # {'A' : NA} -> {'A' : 0}
7492+
if isinstance(self, ABCSeries):
7493+
raise ValueError(
7494+
"to_replace and value cannot be dict-like for "
7495+
"Series.replace"
7496+
)
74927497
# Note: Checking below for `in foo.keys()` instead of
74937498
# `in foo` is needed for when we have a Series and not dict
74947499
mapping = {

pandas/core/resample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2466,7 +2466,7 @@ def _get_timestamp_range_edges(
24662466
)
24672467
if isinstance(freq, Day):
24682468
first = first.tz_localize(index_tz)
2469-
last = last.tz_localize(index_tz)
2469+
last = last.tz_localize(index_tz, nonexistent="shift_forward")
24702470
else:
24712471
first = first.normalize()
24722472
last = last.normalize()

pandas/core/reshape/merge.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,14 @@ def __init__(
982982
)
983983
raise MergeError(msg)
984984

985+
# GH 59435: raise when "how" is not a valid Merge type
986+
merge_type = {"left", "right", "inner", "outer", "cross", "asof"}
987+
if how not in merge_type:
988+
raise ValueError(
989+
f"'{how}' is not a valid Merge type: "
990+
f"left, right, inner, outer, cross, asof"
991+
)
992+
985993
self.left_on, self.right_on = self._validate_left_right_on(left_on, right_on)
986994

987995
(

pandas/core/series.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3211,6 +3211,13 @@ def update(self, other: Series | Sequence | Mapping) -> None:
32113211
Parameters
32123212
----------
32133213
other : Series, or object coercible into Series
3214+
Other Series that provides values to update the current Series.
3215+
3216+
See Also
3217+
--------
3218+
Series.combine : Perform element-wise operation on two Series
3219+
using a given function.
3220+
Series.transform: Modify a Series using a function.
32143221
32153222
Examples
32163223
--------

pandas/io/_util.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ def _arrow_dtype_mapping() -> dict:
2727
pa.string(): pd.StringDtype(),
2828
pa.float32(): pd.Float32Dtype(),
2929
pa.float64(): pd.Float64Dtype(),
30+
pa.string(): pd.StringDtype(),
31+
pa.large_string(): pd.StringDtype(),
3032
}
3133

3234

0 commit comments

Comments
 (0)