Skip to content

Commit e7d2c7a

Browse files
authored
TST: dont test private constructors (#55654)
* REF: dont test intermediate constructor helpers * avoid unnecessary copy
1 parent 8b7fd0d commit e7d2c7a

File tree

8 files changed

+17
-58
lines changed

8 files changed

+17
-58
lines changed

pandas/core/arrays/datetimes.py

+1
Original file line numberDiff line numberDiff line change
@@ -2308,6 +2308,7 @@ def _sequence_to_dt64ns(
23082308
# assume this data are epoch timestamps
23092309
if data.dtype != INT64_DTYPE:
23102310
data = data.astype(np.int64, copy=False)
2311+
copy = False
23112312
result = data.view(out_dtype)
23122313

23132314
if copy:

pandas/tests/arrays/datetimes/test_constructors.py

+2-16
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import pandas as pd
99
import pandas._testing as tm
1010
from pandas.core.arrays import DatetimeArray
11-
from pandas.core.arrays.datetimes import _sequence_to_dt64ns
1211

1312

1413
class TestDatetimeArrayConstructor:
@@ -44,7 +43,6 @@ def test_freq_validation(self):
4443
"meth",
4544
[
4645
DatetimeArray._from_sequence,
47-
_sequence_to_dt64ns,
4846
pd.to_datetime,
4947
pd.DatetimeIndex,
5048
],
@@ -104,9 +102,6 @@ def test_bool_dtype_raises(self):
104102
with pytest.raises(TypeError, match=msg):
105103
DatetimeArray._from_sequence(arr)
106104

107-
with pytest.raises(TypeError, match=msg):
108-
_sequence_to_dt64ns(arr)
109-
110105
with pytest.raises(TypeError, match=msg):
111106
pd.DatetimeIndex(arr)
112107

@@ -143,14 +138,12 @@ def test_tz_dtype_mismatch_raises(self):
143138
["2000"], dtype=DatetimeTZDtype(tz="US/Central")
144139
)
145140
with pytest.raises(TypeError, match="data is already tz-aware"):
146-
DatetimeArray._from_sequence_not_strict(
147-
arr, dtype=DatetimeTZDtype(tz="UTC")
148-
)
141+
DatetimeArray._from_sequence(arr, dtype=DatetimeTZDtype(tz="UTC"))
149142

150143
def test_tz_dtype_matches(self):
151144
dtype = DatetimeTZDtype(tz="US/Central")
152145
arr = DatetimeArray._from_sequence(["2000"], dtype=dtype)
153-
result = DatetimeArray._from_sequence_not_strict(arr, dtype=dtype)
146+
result = DatetimeArray._from_sequence(arr, dtype=dtype)
154147
tm.assert_equal(arr, result)
155148

156149
@pytest.mark.parametrize("order", ["F", "C"])
@@ -160,13 +153,6 @@ def test_2d(self, order):
160153
if order == "F":
161154
arr = arr.T
162155

163-
res = _sequence_to_dt64ns(arr)
164-
expected = _sequence_to_dt64ns(arr.ravel())
165-
166-
tm.assert_numpy_array_equal(res[0].ravel(), expected[0])
167-
assert res[1] == expected[1]
168-
assert res[2] == expected[2]
169-
170156
res = DatetimeArray._from_sequence(arr)
171157
expected = DatetimeArray._from_sequence(arr.ravel()).reshape(arr.shape)
172158
tm.assert_datetime_array_equal(res, expected)

pandas/tests/arrays/datetimes/test_cumulative.py

+7-12
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,35 @@
77
class TestAccumulator:
88
def test_accumulators_freq(self):
99
# GH#50297
10-
arr = DatetimeArray._from_sequence_not_strict(
10+
arr = DatetimeArray._from_sequence(
1111
[
1212
"2000-01-01",
1313
"2000-01-02",
1414
"2000-01-03",
15-
],
16-
freq="D",
17-
)
15+
]
16+
)._with_freq("infer")
1817
result = arr._accumulate("cummin")
19-
expected = DatetimeArray._from_sequence_not_strict(
20-
["2000-01-01"] * 3, freq=None
21-
)
18+
expected = DatetimeArray._from_sequence(["2000-01-01"] * 3)
2219
tm.assert_datetime_array_equal(result, expected)
2320

2421
result = arr._accumulate("cummax")
25-
expected = DatetimeArray._from_sequence_not_strict(
22+
expected = DatetimeArray._from_sequence(
2623
[
2724
"2000-01-01",
2825
"2000-01-02",
2926
"2000-01-03",
3027
],
31-
freq=None,
3228
)
3329
tm.assert_datetime_array_equal(result, expected)
3430

3531
@pytest.mark.parametrize("func", ["cumsum", "cumprod"])
3632
def test_accumulators_disallowed(self, func):
3733
# GH#50297
38-
arr = DatetimeArray._from_sequence_not_strict(
34+
arr = DatetimeArray._from_sequence(
3935
[
4036
"2000-01-01",
4137
"2000-01-02",
4238
],
43-
freq="D",
44-
)
39+
)._with_freq("infer")
4540
with pytest.raises(TypeError, match=f"Accumulation {func}"):
4641
arr._accumulate(func)

pandas/tests/arrays/test_datetimelike.py

-7
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
PeriodArray,
2828
TimedeltaArray,
2929
)
30-
from pandas.core.arrays.datetimes import _sequence_to_dt64ns
31-
from pandas.core.arrays.timedeltas import sequence_to_td64ns
3230

3331

3432
# TODO: more freq variants
@@ -1314,11 +1312,6 @@ def test_from_pandas_array(dtype):
13141312
expected = cls._from_sequence(data)
13151313
tm.assert_extension_array_equal(result, expected)
13161314

1317-
func = {"M8[ns]": _sequence_to_dt64ns, "m8[ns]": sequence_to_td64ns}[dtype]
1318-
result = func(arr)[0]
1319-
expected = func(data)[0]
1320-
tm.assert_equal(result, expected)
1321-
13221315
func = {"M8[ns]": pd.to_datetime, "m8[ns]": pd.to_timedelta}[dtype]
13231316
result = func(arr).array
13241317
expected = func(data).array

pandas/tests/arrays/timedeltas/test_cumulative.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
class TestAccumulator:
88
def test_accumulators_disallowed(self):
99
# GH#50297
10-
arr = TimedeltaArray._from_sequence_not_strict(["1D", "2D"])
10+
arr = TimedeltaArray._from_sequence(["1D", "2D"])
1111
with pytest.raises(TypeError, match="cumprod not supported"):
1212
arr._accumulate("cumprod")
1313

1414
def test_cumsum(self):
1515
# GH#50297
16-
arr = TimedeltaArray._from_sequence_not_strict(["1D", "2D"])
16+
arr = TimedeltaArray._from_sequence(["1D", "2D"])
1717
result = arr._accumulate("cumsum")
18-
expected = TimedeltaArray._from_sequence_not_strict(["1D", "3D"])
18+
expected = TimedeltaArray._from_sequence(["1D", "3D"])
1919
tm.assert_timedelta_array_equal(result, expected)

pandas/tests/indexes/datetimes/test_constructors.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,17 @@ def test_explicit_tz_none(self):
7474
with pytest.raises(ValueError, match=msg):
7575
DatetimeIndex([], dtype="M8[ns, UTC]", tz=None)
7676

77-
@pytest.mark.parametrize(
78-
"dt_cls", [DatetimeIndex, DatetimeArray._from_sequence_not_strict]
79-
)
80-
def test_freq_validation_with_nat(self, dt_cls):
77+
def test_freq_validation_with_nat(self):
8178
# GH#11587 make sure we get a useful error message when generate_range
8279
# raises
8380
msg = (
8481
"Inferred frequency None from passed values does not conform "
8582
"to passed frequency D"
8683
)
8784
with pytest.raises(ValueError, match=msg):
88-
dt_cls([pd.NaT, Timestamp("2011-01-01")], freq="D")
85+
DatetimeIndex([pd.NaT, Timestamp("2011-01-01")], freq="D")
8986
with pytest.raises(ValueError, match=msg):
90-
dt_cls([pd.NaT, Timestamp("2011-01-01")._value], freq="D")
87+
DatetimeIndex([pd.NaT, Timestamp("2011-01-01")._value], freq="D")
9188

9289
# TODO: better place for tests shared by DTI/TDI?
9390
@pytest.mark.parametrize(

pandas/tests/indexes/timedeltas/test_constructors.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
to_timedelta,
1212
)
1313
import pandas._testing as tm
14-
from pandas.core.arrays.timedeltas import (
15-
TimedeltaArray,
16-
sequence_to_td64ns,
17-
)
14+
from pandas.core.arrays.timedeltas import TimedeltaArray
1815

1916

2017
class TestTimedeltaIndex:
@@ -36,9 +33,6 @@ def test_array_of_dt64_nat_raises(self):
3633
with pytest.raises(TypeError, match=msg):
3734
TimedeltaArray._from_sequence(arr)
3835

39-
with pytest.raises(TypeError, match=msg):
40-
sequence_to_td64ns(arr)
41-
4236
with pytest.raises(TypeError, match=msg):
4337
to_timedelta(arr)
4438

pandas/tests/test_downstream.py

-7
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
DatetimeArray,
2424
TimedeltaArray,
2525
)
26-
from pandas.core.arrays.datetimes import _sequence_to_dt64ns
27-
from pandas.core.arrays.timedeltas import sequence_to_td64ns
2826

2927

3028
@pytest.fixture
@@ -316,11 +314,6 @@ def test_from_obscure_array(dtype, array_likes):
316314
result = cls._from_sequence(data)
317315
tm.assert_extension_array_equal(result, expected)
318316

319-
func = {"M8[ns]": _sequence_to_dt64ns, "m8[ns]": sequence_to_td64ns}[dtype]
320-
result = func(arr)[0]
321-
expected = func(data)[0]
322-
tm.assert_equal(result, expected)
323-
324317
if not isinstance(data, memoryview):
325318
# FIXME(GH#44431) these raise on memoryview and attempted fix
326319
# fails on py3.10

0 commit comments

Comments
 (0)