Skip to content

Commit d6df993

Browse files
committed
Merge branch 'master' of github.com:pandas-dev/pandas into any_return_type
2 parents 7f643d6 + 39ccb35 commit d6df993

File tree

14 files changed

+277
-292
lines changed

14 files changed

+277
-292
lines changed

.github/ISSUE_TEMPLATE/bug_report.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ body:
77
- type: checkboxes
88
id: checks
99
attributes:
10+
label: Pandas version checks
1011
options:
1112
- label: >
1213
I have checked that this issue has not already been reported.

.github/ISSUE_TEMPLATE/documentation_improvement.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ labels: [Docs, Needs Triage]
66
body:
77
- type: checkboxes
88
attributes:
9+
label: Pandas version checks
910
options:
1011
- label: >
1112
I have checked that the issue still exists on the latest versions of the docs

.github/ISSUE_TEMPLATE/installation_issue.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ body:
77
- type: checkboxes
88
id: checks
99
attributes:
10+
label: Installation check
1011
options:
1112
- label: >
1213
I have read the [installation guide](https://pandas.pydata.org/pandas-docs/stable/getting_started/install.html#installing-pandas).

.github/ISSUE_TEMPLATE/performance_issue.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ body:
77
- type: checkboxes
88
id: checks
99
attributes:
10+
label: Pandas version checks
1011
options:
1112
- label: >
1213
I have checked that this issue has not already been reported.

.github/ISSUE_TEMPLATE/submit_question.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ body:
1111
usage questions, we ask that all usage questions are first asked on StackOverflow.
1212
- type: checkboxes
1313
attributes:
14+
label: Research
1415
options:
1516
- label: >
1617
I have searched the [[pandas] tag](https://stackoverflow.com/questions/tagged/pandas)

ci/run_tests.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
# https://github.com/pytest-dev/pytest/issues/1075
66
export PYTHONHASHSEED=$(python -c 'import random; print(random.randint(1, 4294967295))')
77

8+
# May help reproduce flaky CI builds if set in subsequent runs
9+
echo PYTHONHASHSEED=$PYTHONHASHSEED
10+
811
if [[ "not network" == *"$PATTERN"* ]]; then
912
export http_proxy=http://1.2.3.4 https_proxy=http://1.2.3.4;
1013
fi

doc/source/whatsnew/v1.4.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ Conversion
660660

661661
Strings
662662
^^^^^^^
663-
- Fixed bug in checking for ``string[pyarrow]`` dtype incorrectly raising an ImportError when pyarrow is not installed (:issue:`44327`)
663+
- Fixed bug in checking for ``string[pyarrow]`` dtype incorrectly raising an ImportError when pyarrow is not installed (:issue:`44276`)
664664
-
665665

666666
Interval

pandas/_testing/__init__.py

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,12 @@
2828
from pandas._typing import Dtype
2929

3030
from pandas.core.dtypes.common import (
31-
is_datetime64_dtype,
32-
is_datetime64tz_dtype,
3331
is_float_dtype,
3432
is_integer_dtype,
35-
is_period_dtype,
3633
is_sequence,
37-
is_timedelta64_dtype,
3834
is_unsigned_integer_dtype,
3935
pandas_dtype,
4036
)
41-
from pandas.core.dtypes.dtypes import IntervalDtype
4237

4338
import pandas as pd
4439
from pandas import (
@@ -112,14 +107,11 @@
112107
)
113108
from pandas.core.arrays import (
114109
BaseMaskedArray,
115-
DatetimeArray,
116110
ExtensionArray,
117111
PandasArray,
118-
PeriodArray,
119-
TimedeltaArray,
120-
period_array,
121112
)
122113
from pandas.core.arrays._mixins import NDArrayBackedExtensionArray
114+
from pandas.core.construction import extract_array
123115

124116
if TYPE_CHECKING:
125117
from pandas import (
@@ -161,6 +153,17 @@
161153
+ BYTES_DTYPES
162154
)
163155

156+
NARROW_NP_DTYPES = [
157+
np.float16,
158+
np.float32,
159+
np.int8,
160+
np.int16,
161+
np.int32,
162+
np.uint8,
163+
np.uint16,
164+
np.uint32,
165+
]
166+
164167
NULL_OBJECTS = [None, np.nan, pd.NaT, float("nan"), pd.NA, Decimal("NaN")]
165168
NP_NAT_OBJECTS = [
166169
cls("NaT", unit)
@@ -257,13 +260,6 @@ def box_expected(expected, box_cls, transpose=True):
257260
# single-row special cases in datetime arithmetic
258261
expected = expected.T
259262
expected = pd.concat([expected] * 2, ignore_index=True)
260-
elif box_cls is PeriodArray:
261-
# the PeriodArray constructor is not as flexible as period_array
262-
expected = period_array(expected)
263-
elif box_cls is DatetimeArray:
264-
expected = DatetimeArray(expected)
265-
elif box_cls is TimedeltaArray:
266-
expected = TimedeltaArray(expected)
267263
elif box_cls is np.ndarray or box_cls is np.array:
268264
expected = np.array(expected)
269265
elif box_cls is to_array:
@@ -274,21 +270,16 @@ def box_expected(expected, box_cls, transpose=True):
274270

275271

276272
def to_array(obj):
273+
"""
274+
Similar to pd.array, but does not cast numpy dtypes to nullable dtypes.
275+
"""
277276
# temporary implementation until we get pd.array in place
278277
dtype = getattr(obj, "dtype", None)
279278

280-
if is_period_dtype(dtype):
281-
return period_array(obj)
282-
elif is_datetime64_dtype(dtype) or is_datetime64tz_dtype(dtype):
283-
return DatetimeArray._from_sequence(obj)
284-
elif is_timedelta64_dtype(dtype):
285-
return TimedeltaArray._from_sequence(obj)
286-
elif isinstance(obj, pd.core.arrays.BooleanArray):
287-
return obj
288-
elif isinstance(dtype, IntervalDtype):
289-
return pd.core.arrays.IntervalArray(obj)
290-
else:
291-
return np.array(obj)
279+
if dtype is None:
280+
return np.asarray(obj)
281+
282+
return extract_array(obj, extract_numpy=True)
292283

293284

294285
# -----------------------------------------------------------------------------

pandas/conftest.py

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -599,11 +599,6 @@ def index_with_missing(request):
599599
# ----------------------------------------------------------------
600600
# Series'
601601
# ----------------------------------------------------------------
602-
@pytest.fixture
603-
def empty_series():
604-
return Series([], index=[], dtype=np.float64)
605-
606-
607602
@pytest.fixture
608603
def string_series():
609604
"""
@@ -672,31 +667,12 @@ def series_with_multilevel_index():
672667
return ser
673668

674669

675-
_narrow_dtypes = [
676-
np.float16,
677-
np.float32,
678-
np.int8,
679-
np.int16,
680-
np.int32,
681-
np.uint8,
682-
np.uint16,
683-
np.uint32,
684-
]
685670
_narrow_series = {
686671
f"{dtype.__name__}-series": tm.makeFloatSeries(name="a").astype(dtype)
687-
for dtype in _narrow_dtypes
672+
for dtype in tm.NARROW_NP_DTYPES
688673
}
689674

690675

691-
@pytest.fixture(params=_narrow_series.keys())
692-
def narrow_series(request):
693-
"""
694-
Fixture for Series with low precision data types
695-
"""
696-
# copy to avoid mutation, e.g. setting .name
697-
return _narrow_series[request.param].copy()
698-
699-
700676
_index_or_series_objs = {**indices_dict, **_series, **_narrow_series}
701677

702678

@@ -712,11 +688,6 @@ def index_or_series_obj(request):
712688
# ----------------------------------------------------------------
713689
# DataFrames
714690
# ----------------------------------------------------------------
715-
@pytest.fixture
716-
def empty_frame():
717-
return DataFrame()
718-
719-
720691
@pytest.fixture
721692
def int_frame():
722693
"""

pandas/tests/arithmetic/test_numeric.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,11 +1400,15 @@ def test_integer_array_add_list_like(
14001400
if Series == box_pandas_1d_array:
14011401
expected = Series(expected_data, dtype="Int64")
14021402
elif Series == box_1d_array:
1403-
expected = Series(expected_data, dtype="object")
1403+
if box_pandas_1d_array is tm.to_array:
1404+
expected = Series(expected_data, dtype="Int64")
1405+
else:
1406+
expected = Series(expected_data, dtype="object")
14041407
elif Index in (box_pandas_1d_array, box_1d_array):
14051408
expected = Int64Index(expected_data)
14061409
else:
1407-
expected = np.array(expected_data, dtype="object")
1410+
# box_pandas_1d_array is tm.to_array; preserves IntegerArray
1411+
expected = array(expected_data, dtype="Int64")
14081412

14091413
tm.assert_equal(left, expected)
14101414
tm.assert_equal(right, expected)

pandas/tests/base/test_misc.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
Index,
1919
Series,
2020
)
21+
import pandas._testing as tm
2122

2223

2324
@pytest.mark.parametrize(
@@ -109,8 +110,9 @@ def test_memory_usage_components_series(series_with_simple_index):
109110
assert total_usage == non_index_usage + index_usage
110111

111112

112-
def test_memory_usage_components_narrow_series(narrow_series):
113-
series = narrow_series
113+
@pytest.mark.parametrize("dtype", tm.NARROW_NP_DTYPES)
114+
def test_memory_usage_components_narrow_series(dtype):
115+
series = tm.makeFloatSeries(name="a").astype(dtype)
114116
total_usage = series.memory_usage(index=True)
115117
non_index_usage = series.memory_usage(index=False)
116118
index_usage = series.index.memory_usage()

pandas/tests/frame/methods/test_replace.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1384,8 +1384,9 @@ def test_replace_value_category_type(self):
13841384

13851385
@pytest.mark.xfail(
13861386
reason="category dtype gets changed to object type after replace, see #35268",
1387+
raises=AssertionError,
13871388
)
1388-
def test_replace_dict_category_type(self, input_category_df, expected_category_df):
1389+
def test_replace_dict_category_type(self):
13891390
"""
13901391
Test to ensure category dtypes are maintained
13911392
after replace with dict values

pandas/tests/io/json/test_pandas.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ def test_roundtrip_categorical(self, request, orient, convert_axes, numpy):
244244

245245
@pytest.mark.parametrize("convert_axes", [True, False])
246246
@pytest.mark.parametrize("numpy", [True, False])
247-
def test_roundtrip_empty(self, orient, convert_axes, numpy, empty_frame):
247+
def test_roundtrip_empty(self, orient, convert_axes, numpy):
248+
empty_frame = DataFrame()
248249
data = empty_frame.to_json(orient=orient)
249250
result = read_json(data, orient=orient, convert_axes=convert_axes, numpy=numpy)
250251
expected = empty_frame.copy()
@@ -673,7 +674,8 @@ def test_series_roundtrip_object(self, orient, numpy, dtype, object_series):
673674
tm.assert_series_equal(result, expected)
674675

675676
@pytest.mark.parametrize("numpy", [True, False])
676-
def test_series_roundtrip_empty(self, orient, numpy, empty_series):
677+
def test_series_roundtrip_empty(self, orient, numpy):
678+
empty_series = Series([], index=[], dtype=np.float64)
677679
data = empty_series.to_json(orient=orient)
678680
result = read_json(data, typ="series", orient=orient, numpy=numpy)
679681

0 commit comments

Comments
 (0)