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
Next Next commit
Remove Series._from_array
Transfer its check to DataFrame._box_col_values
  • Loading branch information
jaumebonet committed Feb 25, 2018
commit ae676b88e414ea0ae79bbc789ab76319498d7830
15 changes: 11 additions & 4 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2166,8 +2166,7 @@ def _ixs(self, i, axis=0):

if index_len and not len(values):
values = np.array([np.nan] * index_len, dtype=object)
result = self._constructor_sliced._from_array(
values, index=self.index, name=label, fastpath=True)
result = self._box_col_values(values, label)

# this is a cached value, mark it so
result._set_as_cached(label, self)
Expand Down Expand Up @@ -2563,8 +2562,16 @@ def _box_item_values(self, key, values):

def _box_col_values(self, values, items):
""" provide boxed values for a column """
return self._constructor_sliced._from_array(values, index=self.index,
name=items, fastpath=True)
# This check here was previously performed in Series._from_array
Copy link
Contributor

Choose a reason for hiding this comment

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

remove all of this commentary

# By doing it here there is no need for that function anymore
# GH#19883.
from pandas.core.dtypes.generic import ABCSparseArray
Copy link
Contributor

Choose a reason for hiding this comment

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

make this a function like _get_series_result_type and put it near _get_frame_result_type in pandas/core/dtypes/concat.py, it should just take self and return the type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see the idea.
Wouldn't it make more sense to be in pandas/core/dtypes/commons.py ? As that file is already imported to frame.py?

Copy link
Contributor

Choose a reason for hiding this comment

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

no, common is for introspection, not conversion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok!

this_constructor_sliced = self._constructor_sliced
if isinstance(values, ABCSparseArray):
from pandas.core.sparse.series import SparseSeries
this_constructor_sliced = SparseSeries
return this_constructor_sliced(values, index=self.index,
name=items, fastpath=True)

def __setitem__(self, key, value):
key = com._apply_if_callable(key, self)
Expand Down
21 changes: 2 additions & 19 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,25 +305,8 @@ def from_array(cls, arr, index=None, name=None, dtype=None, copy=False,
warnings.warn("'from_array' is deprecated and will be removed in a "
"future version. Please use the pd.Series(..) "
"constructor instead.", FutureWarning, stacklevel=2)
return cls._from_array(arr, index=index, name=name, dtype=dtype,
copy=copy, fastpath=fastpath)

@classmethod
def _from_array(cls, arr, index=None, name=None, dtype=None, copy=False,
fastpath=False):
"""
Internal method used in DataFrame.__setitem__/__getitem__.
Difference with Series(..) is that this method checks if a sparse
array is passed.

"""
# return a sparse series here
if isinstance(arr, ABCSparseArray):
from pandas.core.sparse.series import SparseSeries
cls = SparseSeries

return cls(arr, index=index, name=name, dtype=dtype, copy=copy,
fastpath=fastpath)
return cls(arr, index=index, name=name, dtype=dtype,
copy=copy, fastpath=fastpath)

@property
def _constructor(self):
Expand Down
6 changes: 0 additions & 6 deletions pandas/core/sparse/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,6 @@ def from_array(cls, arr, index=None, name=None, copy=False,
warnings.warn("'from_array' is deprecated and will be removed in a "
"future version. Please use the pd.SparseSeries(..) "
"constructor instead.", FutureWarning, stacklevel=2)
return cls._from_array(arr, index=index, name=name, copy=copy,
fill_value=fill_value, fastpath=fastpath)

@classmethod
def _from_array(cls, arr, index=None, name=None, copy=False,
fill_value=None, fastpath=False):
return cls(arr, index=index, name=name, copy=copy,
fill_value=fill_value, fastpath=fastpath)

Expand Down