Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
style fixes
  • Loading branch information
jaumebonet committed Feb 26, 2018
commit f000fdb9bb03c6fc15ea038db69833557ca4fcdc
17 changes: 13 additions & 4 deletions pandas/core/dtypes/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,23 @@ def _get_frame_result_type(result, objs):

def _get_sliced_frame_result_type(data, obj):
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a full doc-string

return appropriate class of Series depending on whether
the data is sparse or not.
return appropriate class of Series. When data is sparse
it will return a SparseSeries, otherwise it will return
the Series.

Parameters
----------
data : ndarray
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array-like

obj : DataFrame

Returns
-------
Series or SparseSeries
"""
if is_sparse(data):
from pandas.core.sparse.api import SparseSeries
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from pandas import

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from pandas import SparseSeries

return SparseSeries
else:
return obj._constructor_sliced
return obj._constructor_sliced


def _concat_compat(to_concat, axis=0):
Expand Down
7 changes: 3 additions & 4 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
is_iterator,
is_sequence,
is_named_tuple)
from pandas.core.dtypes.concat import _get_sliced_frame_result_type
from pandas.core.dtypes.missing import isna, notna


Expand Down Expand Up @@ -2562,10 +2563,8 @@ def _box_item_values(self, key, values):

def _box_col_values(self, values, items):
""" provide boxed values for a column """
from pandas.core.dtypes.concat import _get_sliced_frame_result_type
this_constructor_sliced = _get_sliced_frame_result_type(values, self)
return this_constructor_sliced(values, index=self.index,
name=items, fastpath=True)
klass = _get_sliced_frame_result_type(values, self)
return klass(values, index=self.index, name=items, fastpath=True)

def __setitem__(self, key, value):
key = com._apply_if_callable(key, self)
Expand Down