Skip to content

Commit 178ef99

Browse files
authored
Merge branch 'main' into durbonas/docstring_validation_fixes
2 parents 5c82d50 + 05fa958 commit 178ef99

File tree

16 files changed

+110
-37
lines changed

16 files changed

+110
-37
lines changed

ci/code_checks.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,14 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
179179
-i "pandas.errors.ValueLabelTypeMismatch SA01" \
180180
-i "pandas.infer_freq SA01" \
181181
-i "pandas.io.json.build_table_schema PR07,RT03,SA01" \
182-
-i "pandas.io.stata.StataReader.data_label SA01" \
183182
-i "pandas.io.stata.StataReader.value_labels RT03,SA01" \
184183
-i "pandas.io.stata.StataReader.variable_labels RT03,SA01" \
185184
-i "pandas.io.stata.StataWriter.write_file SA01" \
186185
-i "pandas.json_normalize RT03,SA01" \
187-
-i "pandas.period_range RT03,SA01" \
188186
-i "pandas.plotting.andrews_curves RT03,SA01" \
189187
-i "pandas.plotting.lag_plot RT03,SA01" \
190188
-i "pandas.plotting.scatter_matrix PR07,SA01" \
191189
-i "pandas.set_eng_float_format RT03,SA01" \
192-
-i "pandas.testing.assert_extension_array_equal SA01" \
193190
-i "pandas.tseries.offsets.BDay PR02,SA01" \
194191
-i "pandas.tseries.offsets.BQuarterBegin.is_on_offset GL08" \
195192
-i "pandas.tseries.offsets.BQuarterBegin.n GL08" \

doc/source/whatsnew/v3.0.0.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ Bug fixes
544544

545545
Categorical
546546
^^^^^^^^^^^
547-
-
547+
- Bug in :func:`Series.apply` where ``nan`` was ignored for :class:`CategoricalDtype` (:issue:`59938`)
548548
-
549549

550550
Datetimelike
@@ -682,6 +682,7 @@ Sparse
682682
^^^^^^
683683
- Bug in :class:`SparseDtype` for equal comparison with na fill value. (:issue:`54770`)
684684
- Bug in :meth:`DataFrame.sparse.from_spmatrix` which hard coded an invalid ``fill_value`` for certain subtypes. (:issue:`59063`)
685+
- Bug in :meth:`DataFrame.sparse.to_dense` which ignored subclassing and always returned an instance of :class:`DataFrame` (:issue:`59913`)
685686

686687
ExtensionArray
687688
^^^^^^^^^^^^^^
@@ -700,6 +701,7 @@ Other
700701
- Bug in :func:`eval` on :class:`ExtensionArray` on including division ``/`` failed with a ``TypeError``. (:issue:`58748`)
701702
- Bug in :func:`eval` where the names of the :class:`Series` were not preserved when using ``engine="numexpr"``. (:issue:`10239`)
702703
- Bug in :func:`eval` with ``engine="numexpr"`` returning unexpected result for float division. (:issue:`59736`)
704+
- Bug in :func:`to_numeric` raising ``TypeError`` when ``arg`` is a :class:`Timedelta` or :class:`Timestamp` scalar. (:issue:`59944`)
703705
- Bug in :func:`unique` on :class:`Index` not always returning :class:`Index` (:issue:`57043`)
704706
- Bug in :meth:`DataFrame.apply` where passing ``engine="numba"`` ignored ``args`` passed to the applied function (:issue:`58712`)
705707
- Bug in :meth:`DataFrame.eval` and :meth:`DataFrame.query` which caused an exception when using NumPy attributes via ``@`` notation, e.g., ``df.eval("@np.floor(a)")``. (:issue:`58041`)

pandas/_testing/asserters.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,10 @@ def assert_extension_array_equal(
701701
"""
702702
Check that left and right ExtensionArrays are equal.
703703
704+
This method compares two ``ExtensionArray`` instances for equality,
705+
including checks for missing values, the dtype of the arrays, and
706+
the exactness of the comparison (or tolerance when comparing floats).
707+
704708
Parameters
705709
----------
706710
left, right : ExtensionArray
@@ -726,6 +730,12 @@ def assert_extension_array_equal(
726730
727731
.. versionadded:: 2.0.0
728732
733+
See Also
734+
--------
735+
testing.assert_series_equal : Check that left and right ``Series`` are equal.
736+
testing.assert_frame_equal : Check that left and right ``DataFrame`` are equal.
737+
testing.assert_index_equal : Check that left and right ``Index`` are equal.
738+
729739
Notes
730740
-----
731741
Missing values are checked separately from valid values.

pandas/core/apply.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@
3838
is_numeric_dtype,
3939
is_sequence,
4040
)
41-
from pandas.core.dtypes.dtypes import (
42-
CategoricalDtype,
43-
ExtensionDtype,
44-
)
41+
from pandas.core.dtypes.dtypes import ExtensionDtype
4542
from pandas.core.dtypes.generic import (
4643
ABCDataFrame,
4744
ABCNDFrame,
@@ -1465,14 +1462,7 @@ def curried(x):
14651462

14661463
else:
14671464
curried = func
1468-
1469-
# row-wise access
1470-
# apply doesn't have a `na_action` keyword and for backward compat reasons
1471-
# we need to give `na_action="ignore"` for categorical data.
1472-
# TODO: remove the `na_action="ignore"` when that default has been changed in
1473-
# Categorical (GH51645).
1474-
action = "ignore" if isinstance(obj.dtype, CategoricalDtype) else None
1475-
mapped = obj._map_values(mapper=curried, na_action=action)
1465+
mapped = obj._map_values(mapper=curried)
14761466

14771467
if len(mapped) and isinstance(mapped[0], ABCSeries):
14781468
# GH#43986 Need to do list(mapped) in order to get treated as nested

pandas/core/arrays/sparse/accessor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,10 @@ def to_dense(self) -> DataFrame:
369369
1 1
370370
2 0
371371
"""
372-
from pandas import DataFrame
373-
374372
data = {k: v.array.to_dense() for k, v in self._parent.items()}
375-
return DataFrame(data, index=self._parent.index, columns=self._parent.columns)
373+
return self._parent._constructor(
374+
data, index=self._parent.index, columns=self._parent.columns
375+
)
376376

377377
def to_coo(self) -> spmatrix:
378378
"""

pandas/core/indexes/period.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,14 @@ def period_range(
563563
Returns
564564
-------
565565
PeriodIndex
566+
A PeriodIndex of fixed frequency periods.
567+
568+
See Also
569+
--------
570+
date_range : Returns a fixed frequency DatetimeIndex.
571+
Period : Represents a period of time.
572+
PeriodIndex : Immutable ndarray holding ordinal values indicating regular periods
573+
in time.
566574
567575
Notes
568576
-----

pandas/core/tools/numeric.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
lib,
1212
missing as libmissing,
1313
)
14+
from pandas._libs.tslibs import (
15+
Timedelta,
16+
Timestamp,
17+
)
1418
from pandas.util._validators import check_dtype_backend
1519

1620
from pandas.core.dtypes.cast import maybe_downcast_numeric
@@ -189,6 +193,8 @@ def to_numeric(
189193
return float(arg)
190194
if is_number(arg):
191195
return arg
196+
if isinstance(arg, (Timedelta, Timestamp)):
197+
return arg._value
192198
is_scalars = True
193199
values = np.array([arg], dtype="O")
194200
elif getattr(arg, "ndim", 1) > 1:

pandas/io/formats/html.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ def _write_cell(
195195
esc = {}
196196

197197
rs = pprint_thing(s, escape_chars=esc).strip()
198+
# replace spaces betweens strings with non-breaking spaces
199+
rs = rs.replace(" ", "  ")
198200

199201
if self.render_links and is_url(rs):
200202
rs_unescaped = pprint_thing(s, escape_chars={}).strip()

pandas/io/formats/style_render.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -906,9 +906,9 @@ def concatenated_visible_rows(obj):
906906
row_body_headers = [
907907
{
908908
**col,
909-
"display_value": col["display_value"]
910-
if col["is_visible"]
911-
else "",
909+
"display_value": (
910+
col["display_value"] if col["is_visible"] else ""
911+
),
912912
"cellstyle": self.ctx_index[r, c],
913913
}
914914
for c, col in enumerate(row[:index_levels])
@@ -2069,18 +2069,18 @@ def maybe_convert_css_to_tuples(style: CSSProperties) -> CSSList:
20692069
('border','1px solid red')]
20702070
"""
20712071
if isinstance(style, str):
2072-
s = style.split(";")
2073-
try:
2074-
return [
2075-
(x.split(":")[0].strip(), x.split(":")[1].strip())
2076-
for x in s
2077-
if x.strip() != ""
2078-
]
2079-
except IndexError as err:
2072+
if style and ":" not in style:
20802073
raise ValueError(
20812074
"Styles supplied as string must follow CSS rule formats, "
20822075
f"for example 'attr: val;'. '{style}' was given."
2083-
) from err
2076+
)
2077+
s = style.split(";")
2078+
return [
2079+
(x.split(":")[0].strip(), ":".join(x.split(":")[1:]).strip())
2080+
for x in s
2081+
if x.strip() != ""
2082+
]
2083+
20842084
return style
20852085

20862086

pandas/io/stata.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,16 @@ def data_label(self) -> str:
20042004
"""
20052005
Return data label of Stata file.
20062006
2007+
The data label is a descriptive string associated with the dataset
2008+
stored in the Stata file. This property provides access to that
2009+
label, if one is present.
2010+
2011+
See Also
2012+
--------
2013+
io.stata.StataReader.variable_labels : Return a dict associating each variable
2014+
name with corresponding label.
2015+
DataFrame.to_stata : Export DataFrame object to Stata dta format.
2016+
20072017
Examples
20082018
--------
20092019
>>> df = pd.DataFrame([(1,)], columns=["variable"])

0 commit comments

Comments
 (0)