Skip to content

Commit c2d9c6e

Browse files
authored
Merge branch 'main' into to_timestamp
2 parents 2e52720 + 05fa958 commit c2d9c6e

File tree

7 files changed

+50
-3
lines changed

7 files changed

+50
-3
lines changed

ci/code_checks.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,17 +159,14 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
159159
-i "pandas.errors.ValueLabelTypeMismatch SA01" \
160160
-i "pandas.infer_freq SA01" \
161161
-i "pandas.io.json.build_table_schema PR07,RT03,SA01" \
162-
-i "pandas.io.stata.StataReader.data_label SA01" \
163162
-i "pandas.io.stata.StataReader.value_labels RT03,SA01" \
164163
-i "pandas.io.stata.StataReader.variable_labels RT03,SA01" \
165164
-i "pandas.io.stata.StataWriter.write_file SA01" \
166165
-i "pandas.json_normalize RT03,SA01" \
167-
-i "pandas.period_range RT03,SA01" \
168166
-i "pandas.plotting.andrews_curves RT03,SA01" \
169167
-i "pandas.plotting.lag_plot RT03,SA01" \
170168
-i "pandas.plotting.scatter_matrix PR07,SA01" \
171169
-i "pandas.set_eng_float_format RT03,SA01" \
172-
-i "pandas.testing.assert_extension_array_equal SA01" \
173170
-i "pandas.tseries.offsets.BDay PR02,SA01" \
174171
-i "pandas.tseries.offsets.BQuarterBegin.is_on_offset GL08" \
175172
-i "pandas.tseries.offsets.BQuarterBegin.n GL08" \

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ Other
702702
- Bug in :func:`eval` on :class:`ExtensionArray` on including division ``/`` failed with a ``TypeError``. (:issue:`58748`)
703703
- Bug in :func:`eval` where the names of the :class:`Series` were not preserved when using ``engine="numexpr"``. (:issue:`10239`)
704704
- Bug in :func:`eval` with ``engine="numexpr"`` returning unexpected result for float division. (:issue:`59736`)
705+
- Bug in :func:`to_numeric` raising ``TypeError`` when ``arg`` is a :class:`Timedelta` or :class:`Timestamp` scalar. (:issue:`59944`)
705706
- Bug in :func:`unique` on :class:`Index` not always returning :class:`Index` (:issue:`57043`)
706707
- Bug in :meth:`DataFrame.apply` where passing ``engine="numba"`` ignored ``args`` passed to the applied function (:issue:`58712`)
707708
- 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/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/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"])

pandas/tests/tools/test_to_numeric.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,21 @@ def test_timedelta(transform_assert_equal):
384384
assert_equal(result, expected)
385385

386386

387+
@pytest.mark.parametrize(
388+
"scalar",
389+
[
390+
pd.Timedelta(1, "D"),
391+
pd.Timestamp("2017-01-01T12"),
392+
pd.Timestamp("2017-01-01T12", tz="US/Pacific"),
393+
],
394+
)
395+
def test_timedelta_timestamp_scalar(scalar):
396+
# GH#59944
397+
result = to_numeric(scalar)
398+
expected = to_numeric(Series(scalar))[0]
399+
assert result == expected
400+
401+
387402
def test_period(request, transform_assert_equal):
388403
transform, assert_equal = transform_assert_equal
389404

0 commit comments

Comments
 (0)