Skip to content

BUG: pd.array([]) should return masked array #54372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/source/whatsnew/v2.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,8 @@ Numeric
Conversion
^^^^^^^^^^
- Bug in :func:`DataFrame.style.to_latex` and :func:`DataFrame.style.to_html` if the DataFrame contains integers with more digits than can be represented by floating point double precision (:issue:`52272`)
- Bug in :func:`array` when given a ``datetime64`` or ``timedelta64`` dtype with unit of "s", "us", or "ms" returning :class:`PandasArray` instead of :class:`DatetimeArray` or :class:`TimedeltaArray` (:issue:`52859`)
- Bug in :func:`array` when given a ``datetime64`` or ``timedelta64`` dtype with unit of "s", "us", or "ms" returning :class:`NumpyExtensionArray` instead of :class:`DatetimeArray` or :class:`TimedeltaArray` (:issue:`52859`)
- Bug in :func:`array` when given an empty list and no dtype returning :class:`NumpyExtensionArray` instead of :class:`FloatingArray` (:issue:`54371`)
- Bug in :meth:`ArrowDtype.numpy_dtype` returning nanosecond units for non-nanosecond ``pyarrow.timestamp`` and ``pyarrow.duration`` types (:issue:`51800`)
- Bug in :meth:`DataFrame.__repr__` incorrectly raising a ``TypeError`` when the dtype of a column is ``np.record`` (:issue:`48526`)
- Bug in :meth:`DataFrame.info` raising ``ValueError`` when ``use_numba`` is set (:issue:`51922`)
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ def array(

elif inferred_dtype == "integer":
return IntegerArray._from_sequence(data, copy=copy)

elif inferred_dtype == "empty" and not hasattr(data, "dtype") and not len(data):
return FloatingArray._from_sequence(data, copy=copy)
elif (
inferred_dtype in ("floating", "mixed-integer-float")
and getattr(data, "dtype", None) != np.float16
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/arrays/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,19 @@ def test_dt64_array(dtype_unit):
"data, dtype, expected",
[
# Basic NumPy defaults.
([], None, FloatingArray._from_sequence([])),
([1, 2], None, IntegerArray._from_sequence([1, 2])),
([1, 2], object, NumpyExtensionArray(np.array([1, 2], dtype=object))),
(
[1, 2],
np.dtype("float32"),
NumpyExtensionArray(np.array([1.0, 2.0], dtype=np.dtype("float32"))),
),
(
np.array([], dtype=object),
None,
NumpyExtensionArray(np.array([], dtype=object)),
),
(np.array([1, 2], dtype="int64"), None, IntegerArray._from_sequence([1, 2])),
(
np.array([1.0, 2.0], dtype="float64"),
Expand Down