Skip to content

Commit b63afe8

Browse files
Dieter Vandenbusschewesm
Dieter Vandenbussche
authored andcommitted
Handle masked arrays in DataFrame constructor
1 parent ef76764 commit b63afe8

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pandas/core/frame.py

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from numpy import nan
2222
import numpy as np
23+
import numpy.ma as ma
2324

2425
from pandas.core.common import (isnull, notnull, PandasError, adjoin,
2526
_try_sort, _pfixed, _default_index,
@@ -188,6 +189,12 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
188189
mgr = mgr.astype(dtype)
189190
elif isinstance(data, dict):
190191
mgr = self._init_dict(data, index, columns, dtype=dtype)
192+
elif isinstance(data, ma.MaskedArray):
193+
mask = ma.getmaskarray(data)
194+
datacopy = ma.copy(data)
195+
datacopy[mask] = np.nan
196+
mgr = self._init_ndarray(datacopy, index, columns, dtype=dtype,
197+
copy=copy)
191198
elif isinstance(data, np.ndarray):
192199
if data.dtype.names:
193200
data_columns, data = _rec_to_dict(data)

0 commit comments

Comments
 (0)