From 39e50440646bbfac66f6724a0f6c5170432afe89 Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Sat, 19 Jan 2019 08:06:41 +0800 Subject: [PATCH 1/5] BUG: DataFrame respects dtype with masked recarray --- doc/source/whatsnew/v0.24.0.rst | 4 ++-- pandas/core/internals/construction.py | 2 +- pandas/tests/frame/test_constructors.py | 11 +++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index 3685a24d60e74..35ae1d93d9bff 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -1689,8 +1689,8 @@ Missing - Bug in :func:`Series.hasnans` that could be incorrectly cached and return incorrect answers if null elements are introduced after an initial call (:issue:`19700`) - :func:`Series.isin` now treats all NaN-floats as equal also for ``np.object``-dtype. This behavior is consistent with the behavior for float64 (:issue:`22119`) - :func:`unique` no longer mangles NaN-floats and the ``NaT``-object for ``np.object``-dtype, i.e. ``NaT`` is no longer coerced to a NaN-value and is treated as a different entity. (:issue:`22295`) -- :func:`DataFrame` and :func:`Series` now properly handle numpy masked arrays with hardened masks. Previously, constructing a DataFrame or Series from a masked array with a hard mask would create a pandas object containing the underlying value, rather than the expected NaN. (:issue:`24574`) - +- :class:`DataFrame` and :class:`Series` now properly handle numpy masked arrays with hardened masks. Previously, constructing a DataFrame or Series from a masked array with a hard mask would create a pandas object containing the underlying value, rather than the expected NaN. (:issue:`24574`) +- Bug in :class:`DataFrame` constructor where ``dtype`` argument was not honor when handling a numpy masked record array. (:issue:``) MultiIndex ^^^^^^^^^^ diff --git a/pandas/core/internals/construction.py b/pandas/core/internals/construction.py index 7af347a141781..c05a9a0f8f3c7 100644 --- a/pandas/core/internals/construction.py +++ b/pandas/core/internals/construction.py @@ -93,7 +93,7 @@ def masked_rec_array_to_mgr(data, index, columns, dtype, copy): if columns is None: columns = arr_columns - mgr = arrays_to_mgr(arrays, arr_columns, index, columns) + mgr = arrays_to_mgr(arrays, arr_columns, index, columns, dtype) if copy: mgr = mgr.copy() diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index c8b3f23db1492..6d2b06fd949ea 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -779,6 +779,17 @@ def test_constructor_maskedarray_hardened(self): dtype=float) tm.assert_frame_equal(result, expected) + def test_constructor_maskedrecarray_dtype(self): + # Ensure constructor honors dtype + data = np.ma.array( + np.ma.zeros(5, dtype=[('date', ' Date: Tue, 22 Jan 2019 17:37:44 +0800 Subject: [PATCH 2/5] honor --> honored --- doc/source/whatsnew/v0.24.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index f95b9bafbe6ad..ef0197ad49c15 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -1693,7 +1693,7 @@ Missing - :func:`Series.isin` now treats all NaN-floats as equal also for ``np.object``-dtype. This behavior is consistent with the behavior for float64 (:issue:`22119`) - :func:`unique` no longer mangles NaN-floats and the ``NaT``-object for ``np.object``-dtype, i.e. ``NaT`` is no longer coerced to a NaN-value and is treated as a different entity. (:issue:`22295`) - :class:`DataFrame` and :class:`Series` now properly handle numpy masked arrays with hardened masks. Previously, constructing a DataFrame or Series from a masked array with a hard mask would create a pandas object containing the underlying value, rather than the expected NaN. (:issue:`24574`) -- Bug in :class:`DataFrame` constructor where ``dtype`` argument was not honor when handling a numpy masked record array. (:issue:``) +- Bug in :class:`DataFrame` constructor where ``dtype`` argument was not honored when handling a numpy masked record array. (:issue:``) MultiIndex ^^^^^^^^^^ From a4ee6ff8a86467963529e2da28d9aa525c77a81e Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Tue, 22 Jan 2019 17:39:49 +0800 Subject: [PATCH 3/5] Add PR number --- doc/source/whatsnew/v0.24.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index ef0197ad49c15..8d92cd6e50ce7 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -1693,7 +1693,7 @@ Missing - :func:`Series.isin` now treats all NaN-floats as equal also for ``np.object``-dtype. This behavior is consistent with the behavior for float64 (:issue:`22119`) - :func:`unique` no longer mangles NaN-floats and the ``NaT``-object for ``np.object``-dtype, i.e. ``NaT`` is no longer coerced to a NaN-value and is treated as a different entity. (:issue:`22295`) - :class:`DataFrame` and :class:`Series` now properly handle numpy masked arrays with hardened masks. Previously, constructing a DataFrame or Series from a masked array with a hard mask would create a pandas object containing the underlying value, rather than the expected NaN. (:issue:`24574`) -- Bug in :class:`DataFrame` constructor where ``dtype`` argument was not honored when handling a numpy masked record array. (:issue:``) +- Bug in :class:`DataFrame` constructor where ``dtype`` argument was not honored when handling a numpy masked record array. (:issue:`24874`) MultiIndex ^^^^^^^^^^ From 2d3f35b22fa9b051e3682619f5a32d2195e297c1 Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Tue, 22 Jan 2019 17:47:05 +0800 Subject: [PATCH 4/5] pluralize, (CI dummy commit) --- doc/source/whatsnew/v0.24.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index 8d92cd6e50ce7..d782e3d6858a4 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -1693,7 +1693,7 @@ Missing - :func:`Series.isin` now treats all NaN-floats as equal also for ``np.object``-dtype. This behavior is consistent with the behavior for float64 (:issue:`22119`) - :func:`unique` no longer mangles NaN-floats and the ``NaT``-object for ``np.object``-dtype, i.e. ``NaT`` is no longer coerced to a NaN-value and is treated as a different entity. (:issue:`22295`) - :class:`DataFrame` and :class:`Series` now properly handle numpy masked arrays with hardened masks. Previously, constructing a DataFrame or Series from a masked array with a hard mask would create a pandas object containing the underlying value, rather than the expected NaN. (:issue:`24574`) -- Bug in :class:`DataFrame` constructor where ``dtype`` argument was not honored when handling a numpy masked record array. (:issue:`24874`) +- Bug in :class:`DataFrame` constructor where ``dtype`` argument was not honored when handling numpy masked record arrays. (:issue:`24874`) MultiIndex ^^^^^^^^^^ From b3bd0420d01a3d875312a509d8bd10ec2401ce21 Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Tue, 22 Jan 2019 20:11:02 +0800 Subject: [PATCH 5/5] Fix import --- pandas/tests/frame/test_constructors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index ec5799a80e235..90ad48cac3a5f 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -792,7 +792,7 @@ def test_constructor_maskedrecarray_dtype(self): data = np.ma.array( np.ma.zeros(5, dtype=[('date', '