Skip to content

COMPAT: DataFrame construction compat with xarray.Dataset #12356

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

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 3 additions & 3 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
is_sequence, _infer_dtype_from_scalar, _values_from_object, is_list_like,
_maybe_box_datetimelike, is_categorical_dtype, is_object_dtype,
is_internal_type, is_datetimetz, _possibly_infer_to_datetimelike,
_dict_compat)
_dict_compat, is_dict_like)
from pandas.core.generic import NDFrame, _shared_docs
from pandas.core.index import Index, MultiIndex, _ensure_index
from pandas.core.indexing import (maybe_droplevels, convert_to_index_sliceable,
Expand Down Expand Up @@ -219,8 +219,6 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
if isinstance(data, BlockManager):
mgr = self._init_mgr(data, axes=dict(index=index, columns=columns),
dtype=dtype, copy=copy)
elif isinstance(data, dict):
mgr = self._init_dict(data, index, columns, dtype=dtype)
elif isinstance(data, ma.MaskedArray):
import numpy.ma.mrecords as mrecords
# masked recarray
Expand Down Expand Up @@ -252,6 +250,8 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
else:
mgr = self._init_ndarray(data, index, columns, dtype=dtype,
copy=copy)
elif is_dict_like(data):
mgr = self._init_dict(data, index, columns, dtype=dtype)
elif isinstance(data, (list, types.GeneratorType)):
if isinstance(data, types.GeneratorType):
data = list(data)
Expand Down
5 changes: 3 additions & 2 deletions pandas/core/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
from pandas.compat import (map, zip, range, u, OrderedDict, OrderedDefaultdict)
from pandas.core.categorical import Categorical
from pandas.core.common import (PandasError, _try_sort, _default_index,
_infer_dtype_from_scalar, is_list_like)
_infer_dtype_from_scalar, is_list_like,
is_dict_like)
from pandas.core.frame import DataFrame
from pandas.core.generic import NDFrame, _shared_docs
from pandas.core.index import (Index, MultiIndex, _ensure_index,
Expand Down Expand Up @@ -157,7 +158,7 @@ def _init_data(self, data, copy, dtype, **kwargs):
axes = [x if x is not None else y
for x, y in zip(passed_axes, data.axes)]
mgr = data
elif isinstance(data, dict):
elif is_dict_like(data):
mgr = self._init_dict(data, passed_axes, dtype=dtype)
copy = False
dtype = None
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,8 @@ def testit(index, check_index_type=True):
self.assertIsInstance(result, DataArray)
assert_series_equal(result.to_series(), s)

#assert_series_equal(Series(result), s)


class TestDataFrame(tm.TestCase, Generic):
_typ = DataFrame
Expand Down Expand Up @@ -1832,6 +1834,10 @@ def test_to_xarray(self):
expected,
check_index_type=False)

assert_frame_equal(DataFrame(result).set_index('foo'),
expected,
check_index_type=False)

# not implemented
df.index = pd.MultiIndex.from_product([['a'], range(3)],
names=['one', 'two'])
Expand Down Expand Up @@ -1859,6 +1865,8 @@ def test_to_xarray(self):
# idempotency
assert_panel_equal(result.to_pandas(), p)

#assert_panel_equal(Panel(result), p)


class TestPanel4D(tm.TestCase, Generic):
_typ = Panel4D
Expand Down