Skip to content

Commit 2a20a2f

Browse files
fixed data check in create_series_with_explicit_index + renmae of helper
1 parent eaeb29d commit 2a20a2f

13 files changed

+41
-43
lines changed

pandas/core/construction.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ def create_series_with_explicit_dtype(
626626
if is_empty_data(data) and dtype is None:
627627
dtype = dtype_if_empty
628628

629-
return create_series_with_explicit_index_type(
629+
return create_series_with_explicit_index(
630630
data=data,
631631
index=index,
632632
dtype=dtype,
@@ -637,7 +637,7 @@ def create_series_with_explicit_dtype(
637637
)
638638

639639

640-
def create_series_with_explicit_index_type(
640+
def create_series_with_explicit_index(
641641
data: Any = None,
642642
index: Optional[Union[ArrayLike, "Index"]] = None,
643643
dtype: Optional[Dtype] = None,
@@ -674,7 +674,7 @@ def create_series_with_explicit_index_type(
674674
if index_if_empty is None:
675675
index_if_empty = Index([])
676676

677-
if index is None and data == []:
677+
if index is None and isinstance(data, list) and len(data) == 0:
678678
index = index_if_empty
679679
return Series(
680680
data=data, index=index, dtype=dtype, name=name, copy=copy, fastpath=fastpath

pandas/tests/series/indexing/test_boolean.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from pandas import Index, Series
55
import pandas._testing as tm
6-
from pandas.core.construction import create_series_with_explicit_index_type
6+
from pandas.core.construction import create_series_with_explicit_index
77
from pandas.core.indexing import IndexingError
88

99
from pandas.tseries.offsets import BDay
@@ -21,7 +21,7 @@ def test_getitem_boolean(string_series):
2121

2222

2323
def test_getitem_boolean_empty():
24-
s = create_series_with_explicit_index_type([], dtype=np.int64)
24+
s = create_series_with_explicit_index([], dtype=np.int64)
2525
s.index.name = "index_name"
2626
s = s[s.isna()]
2727
assert s.index.name == "index_name"
@@ -31,7 +31,7 @@ def test_getitem_boolean_empty():
3131
# indexing with empty series
3232
s = Series(["A", "B"])
3333
expected = Series(dtype=object, index=Index([], dtype="int64"))
34-
result = s[create_series_with_explicit_index_type([], dtype=object)]
34+
result = s[create_series_with_explicit_index([], dtype=object)]
3535
tm.assert_series_equal(result, expected)
3636

3737
# invalid because of the boolean indexer
@@ -41,7 +41,7 @@ def test_getitem_boolean_empty():
4141
r"the boolean Series and of the indexed object do not match"
4242
)
4343
with pytest.raises(IndexingError, match=msg):
44-
s[create_series_with_explicit_index_type([], dtype=bool)]
44+
s[create_series_with_explicit_index([], dtype=bool)]
4545

4646
with pytest.raises(IndexingError, match=msg):
4747
s[Series([True], dtype=bool)]

pandas/tests/series/indexing/test_indexing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import pandas as pd
1111
from pandas import Categorical, DataFrame, MultiIndex, Series, Timedelta, Timestamp
1212
import pandas._testing as tm
13-
from pandas.core.construction import create_series_with_explicit_index_type
13+
from pandas.core.construction import create_series_with_explicit_index
1414

1515
from pandas.tseries.offsets import BDay
1616

@@ -618,7 +618,7 @@ def test_setitem_na():
618618

619619
def test_timedelta_assignment():
620620
# GH 8209
621-
s = create_series_with_explicit_index_type([], dtype=object)
621+
s = create_series_with_explicit_index([], dtype=object)
622622
s.loc["B"] = timedelta(1)
623623
tm.assert_series_equal(s, Series(Timedelta("1 days"), index=["B"]))
624624

pandas/tests/series/methods/test_drop_duplicates.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from pandas import Categorical, Series
55
import pandas._testing as tm
6-
from pandas.core.construction import create_series_with_explicit_index_type
6+
from pandas.core.construction import create_series_with_explicit_index
77

88

99
@pytest.mark.parametrize(
@@ -47,8 +47,8 @@ def test_drop_duplicates_bool(keep, expected):
4747

4848
@pytest.mark.parametrize("values", [[], list(range(5))])
4949
def test_drop_duplicates_no_duplicates(any_numpy_dtype, keep, values):
50-
tc = create_series_with_explicit_index_type(values, dtype=np.dtype(any_numpy_dtype))
51-
expected = create_series_with_explicit_index_type([False] * len(tc), dtype="bool")
50+
tc = create_series_with_explicit_index(values, dtype=np.dtype(any_numpy_dtype))
51+
expected = create_series_with_explicit_index([False] * len(tc), dtype="bool")
5252

5353
if tc.dtype == "bool":
5454
# 0 -> False and 1-> True

pandas/tests/series/methods/test_quantile.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
from pandas import Index, Series
88
import pandas._testing as tm
9-
from pandas.core.construction import create_series_with_explicit_index_type
9+
from pandas.core.construction import create_series_with_explicit_index
1010
from pandas.core.indexes.datetimes import Timestamp
1111

1212

@@ -105,7 +105,7 @@ def test_quantile_nan(self):
105105
assert result == expected
106106

107107
# all nan/empty
108-
s1 = create_series_with_explicit_index_type([], dtype=object)
108+
s1 = create_series_with_explicit_index([], dtype=object)
109109
cases = [s1, Series([np.nan, np.nan])]
110110

111111
for s in cases:
@@ -165,10 +165,10 @@ def test_quantile_box(self, case):
165165
def test_datetime_timedelta_quantiles(self):
166166
# covers #9694
167167
assert pd.isna(
168-
create_series_with_explicit_index_type([], dtype="M8[ns]").quantile(0.5)
168+
create_series_with_explicit_index([], dtype="M8[ns]").quantile(0.5)
169169
)
170170
assert pd.isna(
171-
create_series_with_explicit_index_type([], dtype="m8[ns]").quantile(0.5)
171+
create_series_with_explicit_index([], dtype="m8[ns]").quantile(0.5)
172172
)
173173

174174
def test_quantile_nat(self):
@@ -191,7 +191,7 @@ def test_quantile_sparse(self, values, dtype):
191191
def test_quantile_empty(self):
192192

193193
# floats
194-
s = create_series_with_explicit_index_type([], dtype="float64")
194+
s = create_series_with_explicit_index([], dtype="float64")
195195

196196
res = s.quantile(0.5)
197197
assert np.isnan(res)
@@ -201,7 +201,7 @@ def test_quantile_empty(self):
201201
tm.assert_series_equal(res, exp)
202202

203203
# int
204-
s = create_series_with_explicit_index_type([], dtype="int64")
204+
s = create_series_with_explicit_index([], dtype="int64")
205205

206206
res = s.quantile(0.5)
207207
assert np.isnan(res)
@@ -211,7 +211,7 @@ def test_quantile_empty(self):
211211
tm.assert_series_equal(res, exp)
212212

213213
# datetime
214-
s = create_series_with_explicit_index_type([], dtype="datetime64[ns]")
214+
s = create_series_with_explicit_index([], dtype="datetime64[ns]")
215215

216216
res = s.quantile(0.5)
217217
assert res is pd.NaT

pandas/tests/series/test_apply.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from pandas import DataFrame, Index, Series, isna
1111
import pandas._testing as tm
1212
from pandas.core.base import SpecificationError
13-
from pandas.core.construction import create_series_with_explicit_index_type
13+
from pandas.core.construction import create_series_with_explicit_index
1414

1515

1616
class TestSeriesApply:
@@ -520,7 +520,7 @@ def test_map_empty(self, indices):
520520
if isinstance(indices, ABCMultiIndex):
521521
pytest.skip("Initializing a Series from a MultiIndex is not supported")
522522

523-
s = create_series_with_explicit_index_type(indices)
523+
s = create_series_with_explicit_index(indices)
524524
result = s.map({})
525525

526526
expected = pd.Series(np.nan, index=s.index)

pandas/tests/series/test_combine_concat.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import pandas as pd
55
from pandas import Series
6-
from pandas.core.construction import create_series_with_explicit_index_type
6+
from pandas.core.construction import create_series_with_explicit_index
77

88

99
class TestSeriesConcat:
@@ -96,9 +96,7 @@ def test_concat_empty_series_dtype_category_with_array(self):
9696
assert (
9797
pd.concat(
9898
[
99-
create_series_with_explicit_index_type(
100-
np.array([]), dtype="category"
101-
),
99+
create_series_with_explicit_index(np.array([]), dtype="category"),
102100
Series(dtype="float64"),
103101
]
104102
).dtype

pandas/tests/series/test_constructors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
)
2929
import pandas._testing as tm
3030
from pandas.core.arrays import IntervalArray, period_array
31-
from pandas.core.construction import create_series_with_explicit_index_type
31+
from pandas.core.construction import create_series_with_explicit_index
3232

3333

3434
class TestSeriesConstructors:
@@ -1401,7 +1401,7 @@ def test_constructor_generic_timestamp_no_frequency(self, dtype):
14011401
msg = "dtype has no unit. Please pass in"
14021402

14031403
with pytest.raises(ValueError, match=msg):
1404-
create_series_with_explicit_index_type([], dtype=dtype)
1404+
create_series_with_explicit_index([], dtype=dtype)
14051405

14061406
@pytest.mark.parametrize(
14071407
"dtype,msg",
@@ -1414,7 +1414,7 @@ def test_constructor_generic_timestamp_bad_frequency(self, dtype, msg):
14141414
# see gh-15524, gh-15987
14151415

14161416
with pytest.raises(TypeError, match=msg):
1417-
create_series_with_explicit_index_type([], dtype=dtype)
1417+
create_series_with_explicit_index([], dtype=dtype)
14181418

14191419
@pytest.mark.parametrize("dtype", [None, "uint8", "category"])
14201420
def test_constructor_range_dtype(self, dtype):

pandas/tests/series/test_dtypes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
date_range,
2222
)
2323
import pandas._testing as tm
24-
from pandas.core.construction import create_series_with_explicit_index_type
24+
from pandas.core.construction import create_series_with_explicit_index
2525

2626

2727
class TestSeriesDtypes:
@@ -405,9 +405,9 @@ def test_astype_empty_constructor_equality(self, dtype):
405405
"M",
406406
"m", # Generic timestamps raise a ValueError. Already tested.
407407
):
408-
init_empty = create_series_with_explicit_index_type([], dtype=dtype)
408+
init_empty = create_series_with_explicit_index([], dtype=dtype)
409409
with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=False):
410-
as_type_empty = create_series_with_explicit_index_type([]).astype(dtype)
410+
as_type_empty = create_series_with_explicit_index([]).astype(dtype)
411411
tm.assert_series_equal(init_empty, as_type_empty)
412412

413413
def test_arg_for_errors_in_astype(self):

pandas/tests/series/test_duplicates.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pandas._testing as tm
66
from pandas.core.construction import (
77
create_series_with_explicit_dtype,
8-
create_series_with_explicit_index_type,
8+
create_series_with_explicit_index,
99
)
1010

1111

@@ -18,7 +18,7 @@ def test_nunique():
1818
assert result == 11
1919

2020
# GH 18051
21-
s = create_series_with_explicit_index_type(Categorical([]))
21+
s = create_series_with_explicit_index(Categorical([]))
2222
assert s.nunique() == 0
2323
s = Series(Categorical([np.nan]))
2424
assert s.nunique() == 0
@@ -49,7 +49,7 @@ def test_unique():
4949
tm.assert_numpy_array_equal(result, expected)
5050

5151
# GH 18051
52-
s = create_series_with_explicit_index_type(Categorical([]))
52+
s = create_series_with_explicit_index(Categorical([]))
5353
tm.assert_categorical_equal(s.unique(), Categorical([]))
5454
s = Series(Categorical([np.nan]))
5555
tm.assert_categorical_equal(s.unique(), Categorical([np.nan]))

pandas/tests/series/test_missing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
isna,
2121
)
2222
import pandas._testing as tm
23-
from pandas.core.construction import create_series_with_explicit_index_type
23+
from pandas.core.construction import create_series_with_explicit_index
2424

2525

2626
class TestSeriesMissingData:
@@ -563,7 +563,7 @@ def test_fillna(self, datetime_series):
563563
tm.assert_series_equal(result, expected)
564564
result = s1.fillna({})
565565
tm.assert_series_equal(result, s1)
566-
result = s1.fillna(create_series_with_explicit_index_type((), dtype=object))
566+
result = s1.fillna(create_series_with_explicit_index((), dtype=object))
567567
tm.assert_series_equal(result, s1)
568568
result = s2.fillna(s1)
569569
tm.assert_series_equal(result, s2)
@@ -678,7 +678,7 @@ def test_timedelta64_nan(self):
678678
# tm.assert_series_equal(selector, expected)
679679

680680
def test_dropna_empty(self):
681-
s = create_series_with_explicit_index_type([], dtype=object)
681+
s = create_series_with_explicit_index([], dtype=object)
682682

683683
assert len(s.dropna()) == 0
684684
s.dropna(inplace=True)

pandas/tests/series/test_operators.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pandas import DataFrame, Index, Series, bdate_range
99
import pandas._testing as tm
1010
from pandas.core import ops
11-
from pandas.core.construction import create_series_with_explicit_index_type
11+
from pandas.core.construction import create_series_with_explicit_index
1212

1313

1414
class TestSeriesLogicalOps:
@@ -33,7 +33,7 @@ def test_logical_operators_bool_dtype_with_empty(self):
3333

3434
s_tft = Series([True, False, True], index=index)
3535
s_fff = Series([False, False, False], index=index)
36-
s_empty = create_series_with_explicit_index_type([], dtype=object)
36+
s_empty = create_series_with_explicit_index([], dtype=object)
3737

3838
res = s_tft & s_empty
3939
expected = s_fff
@@ -408,7 +408,7 @@ def test_logical_ops_label_based(self):
408408
# filling
409409

410410
# vs empty
411-
empty = create_series_with_explicit_index_type([], dtype=object)
411+
empty = create_series_with_explicit_index([], dtype=object)
412412

413413
result = a & empty.copy()
414414
expected = Series([False, False, False], list("bca"))

pandas/tests/series/test_repr.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
timedelta_range,
1717
)
1818
import pandas._testing as tm
19-
from pandas.core.construction import create_series_with_explicit_index_type
19+
from pandas.core.construction import create_series_with_explicit_index
2020

2121

2222
class TestSeriesRepr:
@@ -125,10 +125,10 @@ def test_repr(self, datetime_series, string_series, object_series):
125125
assert "a\n" not in repr(ser)
126126

127127
# with empty series (#4651)
128-
s = create_series_with_explicit_index_type([], dtype=np.int64, name="foo")
128+
s = create_series_with_explicit_index([], dtype=np.int64, name="foo")
129129
assert repr(s) == "Series([], Name: foo, dtype: int64)"
130130

131-
s = create_series_with_explicit_index_type([], dtype=np.int64, name=None)
131+
s = create_series_with_explicit_index([], dtype=np.int64, name=None)
132132
assert repr(s) == "Series([], dtype: int64)"
133133

134134
def test_tidy_repr(self):

0 commit comments

Comments
 (0)