Skip to content

Commit 279b91f

Browse files
authored
REF: remove unused allow_object kwarg from sequence_to_dt64ns (#44519)
1 parent 82b69f7 commit 279b91f

File tree

4 files changed

+18
-45
lines changed

4 files changed

+18
-45
lines changed

pandas/core/arrays/datetimes.py

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from typing import (
1010
TYPE_CHECKING,
1111
Literal,
12-
overload,
1312
)
1413
import warnings
1514

@@ -356,7 +355,7 @@ def _from_sequence_not_strict(
356355

357356
freq, freq_infer = dtl.maybe_infer_freq(freq)
358357

359-
subarr, tz, inferred_freq = sequence_to_dt64ns(
358+
subarr, tz, inferred_freq = _sequence_to_dt64ns(
360359
data,
361360
dtype=dtype,
362361
copy=copy,
@@ -1972,41 +1971,22 @@ def std(
19721971
# Constructor Helpers
19731972

19741973

1975-
@overload
1976-
def sequence_to_datetimes(
1977-
data, allow_object: Literal[False] = ..., require_iso8601: bool = ...
1978-
) -> DatetimeArray:
1979-
...
1980-
1981-
1982-
@overload
1983-
def sequence_to_datetimes(
1984-
data, allow_object: Literal[True] = ..., require_iso8601: bool = ...
1985-
) -> np.ndarray | DatetimeArray:
1986-
...
1987-
1988-
1989-
def sequence_to_datetimes(
1990-
data, allow_object: bool = False, require_iso8601: bool = False
1991-
) -> np.ndarray | DatetimeArray:
1974+
def sequence_to_datetimes(data, require_iso8601: bool = False) -> DatetimeArray:
19921975
"""
19931976
Parse/convert the passed data to either DatetimeArray or np.ndarray[object].
19941977
"""
1995-
result, tz, freq = sequence_to_dt64ns(
1978+
result, tz, freq = _sequence_to_dt64ns(
19961979
data,
1997-
allow_object=allow_object,
19981980
allow_mixed=True,
19991981
require_iso8601=require_iso8601,
20001982
)
2001-
if result.dtype == object:
2002-
return result
20031983

20041984
dtype = tz_to_dtype(tz)
20051985
dta = DatetimeArray._simple_new(result, freq=freq, dtype=dtype)
20061986
return dta
20071987

20081988

2009-
def sequence_to_dt64ns(
1989+
def _sequence_to_dt64ns(
20101990
data,
20111991
dtype=None,
20121992
copy=False,
@@ -2015,7 +1995,6 @@ def sequence_to_dt64ns(
20151995
yearfirst=False,
20161996
ambiguous="raise",
20171997
*,
2018-
allow_object: bool = False,
20191998
allow_mixed: bool = False,
20201999
require_iso8601: bool = False,
20212000
):
@@ -2030,9 +2009,6 @@ def sequence_to_dt64ns(
20302009
yearfirst : bool, default False
20312010
ambiguous : str, bool, or arraylike, default 'raise'
20322011
See pandas._libs.tslibs.tzconversion.tz_localize_to_utc.
2033-
allow_object : bool, default False
2034-
Whether to return an object-dtype ndarray instead of raising if the
2035-
data contains more than one timezone.
20362012
allow_mixed : bool, default False
20372013
Interpret integers as timestamps when datetime objects are also present.
20382014
require_iso8601 : bool, default False
@@ -2102,7 +2078,7 @@ def sequence_to_dt64ns(
21022078
data,
21032079
dayfirst=dayfirst,
21042080
yearfirst=yearfirst,
2105-
allow_object=allow_object,
2081+
allow_object=False,
21062082
allow_mixed=allow_mixed,
21072083
require_iso8601=require_iso8601,
21082084
)
@@ -2112,9 +2088,6 @@ def sequence_to_dt64ns(
21122088
data = data.view(DT64NS_DTYPE)
21132089
elif inferred_tz:
21142090
tz = inferred_tz
2115-
elif allow_object and data.dtype == object:
2116-
# We encountered mixed-timezones.
2117-
return data, None, None
21182091

21192092
data_dtype = data.dtype
21202093

pandas/core/dtypes/cast.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,7 @@ def try_datetime(v: np.ndarray) -> ArrayLike:
15231523
try:
15241524
# GH#19671 we pass require_iso8601 to be relatively strict
15251525
# when parsing strings.
1526-
dta = sequence_to_datetimes(v, require_iso8601=True, allow_object=False)
1526+
dta = sequence_to_datetimes(v, require_iso8601=True)
15271527
except (ValueError, TypeError):
15281528
# e.g. <class 'numpy.timedelta64'> is not convertible to datetime
15291529
return v.reshape(shape)
@@ -1635,7 +1635,7 @@ def maybe_cast_to_datetime(
16351635

16361636
try:
16371637
if is_datetime64:
1638-
dta = sequence_to_datetimes(value, allow_object=False)
1638+
dta = sequence_to_datetimes(value)
16391639
# GH 25843: Remove tz information since the dtype
16401640
# didn't specify one
16411641

@@ -1663,7 +1663,7 @@ def maybe_cast_to_datetime(
16631663
# datetime64tz is assumed to be naive which should
16641664
# be localized to the timezone.
16651665
is_dt_string = is_string_dtype(value.dtype)
1666-
dta = sequence_to_datetimes(value, allow_object=False)
1666+
dta = sequence_to_datetimes(value)
16671667
if dta.tz is not None:
16681668
value = dta.astype(dtype, copy=False)
16691669
elif is_dt_string:

pandas/tests/arrays/datetimes/test_constructors.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pandas as pd
77
import pandas._testing as tm
88
from pandas.core.arrays import DatetimeArray
9-
from pandas.core.arrays.datetimes import sequence_to_dt64ns
9+
from pandas.core.arrays.datetimes import _sequence_to_dt64ns
1010

1111

1212
class TestDatetimeArrayConstructor:
@@ -42,7 +42,7 @@ def test_freq_validation(self):
4242
"meth",
4343
[
4444
DatetimeArray._from_sequence,
45-
sequence_to_dt64ns,
45+
_sequence_to_dt64ns,
4646
pd.to_datetime,
4747
pd.DatetimeIndex,
4848
],
@@ -97,7 +97,7 @@ def test_bool_dtype_raises(self):
9797
DatetimeArray._from_sequence(arr)
9898

9999
with pytest.raises(TypeError, match=msg):
100-
sequence_to_dt64ns(arr)
100+
_sequence_to_dt64ns(arr)
101101

102102
with pytest.raises(TypeError, match=msg):
103103
pd.DatetimeIndex(arr)
@@ -128,13 +128,13 @@ def test_tz_dtype_mismatch_raises(self):
128128
["2000"], dtype=DatetimeTZDtype(tz="US/Central")
129129
)
130130
with pytest.raises(TypeError, match="data is already tz-aware"):
131-
sequence_to_dt64ns(arr, dtype=DatetimeTZDtype(tz="UTC"))
131+
_sequence_to_dt64ns(arr, dtype=DatetimeTZDtype(tz="UTC"))
132132

133133
def test_tz_dtype_matches(self):
134134
arr = DatetimeArray._from_sequence(
135135
["2000"], dtype=DatetimeTZDtype(tz="US/Central")
136136
)
137-
result, _, _ = sequence_to_dt64ns(arr, dtype=DatetimeTZDtype(tz="US/Central"))
137+
result, _, _ = _sequence_to_dt64ns(arr, dtype=DatetimeTZDtype(tz="US/Central"))
138138
tm.assert_numpy_array_equal(arr._data, result)
139139

140140
@pytest.mark.parametrize("order", ["F", "C"])
@@ -144,8 +144,8 @@ def test_2d(self, order):
144144
if order == "F":
145145
arr = arr.T
146146

147-
res = sequence_to_dt64ns(arr)
148-
expected = sequence_to_dt64ns(arr.ravel())
147+
res = _sequence_to_dt64ns(arr)
148+
expected = _sequence_to_dt64ns(arr.ravel())
149149

150150
tm.assert_numpy_array_equal(res[0].ravel(), expected[0])
151151
assert res[1] == expected[1]

pandas/tests/arrays/test_datetimelike.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
PeriodArray,
2727
TimedeltaArray,
2828
)
29-
from pandas.core.arrays.datetimes import sequence_to_dt64ns
29+
from pandas.core.arrays.datetimes import _sequence_to_dt64ns
3030
from pandas.core.arrays.timedeltas import sequence_to_td64ns
3131

3232

@@ -1361,7 +1361,7 @@ def test_from_pandas_array(dtype):
13611361
expected = cls._from_sequence(data)
13621362
tm.assert_extension_array_equal(result, expected)
13631363

1364-
func = {"M8[ns]": sequence_to_dt64ns, "m8[ns]": sequence_to_td64ns}[dtype]
1364+
func = {"M8[ns]": _sequence_to_dt64ns, "m8[ns]": sequence_to_td64ns}[dtype]
13651365
result = func(arr)[0]
13661366
expected = func(data)[0]
13671367
tm.assert_equal(result, expected)
@@ -1424,7 +1424,7 @@ def test_from_obscure_array(dtype, array_likes):
14241424
result = cls._from_sequence(data)
14251425
tm.assert_extension_array_equal(result, expected)
14261426

1427-
func = {"M8[ns]": sequence_to_dt64ns, "m8[ns]": sequence_to_td64ns}[dtype]
1427+
func = {"M8[ns]": _sequence_to_dt64ns, "m8[ns]": sequence_to_td64ns}[dtype]
14281428
result = func(arr)[0]
14291429
expected = func(data)[0]
14301430
tm.assert_equal(result, expected)

0 commit comments

Comments
 (0)