Skip to content

Commit ceb9031

Browse files
jaumebonetjreback
authored andcommitted
CLN: Remove Series._from_array (#19893)
1 parent e51800b commit ceb9031

File tree

4 files changed

+27
-26
lines changed

4 files changed

+27
-26
lines changed

pandas/core/dtypes/concat.py

+21
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,27 @@ def _get_frame_result_type(result, objs):
101101
ABCSparseDataFrame))
102102

103103

104+
def _get_sliced_frame_result_type(data, obj):
105+
"""
106+
return appropriate class of Series. When data is sparse
107+
it will return a SparseSeries, otherwise it will return
108+
the Series.
109+
110+
Parameters
111+
----------
112+
data : array-like
113+
obj : DataFrame
114+
115+
Returns
116+
-------
117+
Series or SparseSeries
118+
"""
119+
if is_sparse(data):
120+
from pandas.core.sparse.api import SparseSeries
121+
return SparseSeries
122+
return obj._constructor_sliced
123+
124+
104125
def _concat_compat(to_concat, axis=0):
105126
"""
106127
provide concatenation of an array of arrays each of which is a single

pandas/core/frame.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
is_iterator,
6161
is_sequence,
6262
is_named_tuple)
63+
from pandas.core.dtypes.concat import _get_sliced_frame_result_type
6364
from pandas.core.dtypes.missing import isna, notna
6465

6566

@@ -2166,8 +2167,7 @@ def _ixs(self, i, axis=0):
21662167

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

21722172
# this is a cached value, mark it so
21732173
result._set_as_cached(label, self)
@@ -2563,8 +2563,8 @@ def _box_item_values(self, key, values):
25632563

25642564
def _box_col_values(self, values, items):
25652565
""" provide boxed values for a column """
2566-
return self._constructor_sliced._from_array(values, index=self.index,
2567-
name=items, fastpath=True)
2566+
klass = _get_sliced_frame_result_type(values, self)
2567+
return klass(values, index=self.index, name=items, fastpath=True)
25682568

25692569
def __setitem__(self, key, value):
25702570
key = com._apply_if_callable(key, self)

pandas/core/series.py

+2-16
Original file line numberDiff line numberDiff line change
@@ -316,25 +316,11 @@ def from_array(cls, arr, index=None, name=None, dtype=None, copy=False,
316316
warnings.warn("'from_array' is deprecated and will be removed in a "
317317
"future version. Please use the pd.Series(..) "
318318
"constructor instead.", FutureWarning, stacklevel=2)
319-
return cls._from_array(arr, index=index, name=name, dtype=dtype,
320-
copy=copy, fastpath=fastpath)
321-
322-
@classmethod
323-
def _from_array(cls, arr, index=None, name=None, dtype=None, copy=False,
324-
fastpath=False):
325-
"""
326-
Internal method used in DataFrame.__setitem__/__getitem__.
327-
Difference with Series(..) is that this method checks if a sparse
328-
array is passed.
329-
330-
"""
331-
# return a sparse series here
332319
if isinstance(arr, ABCSparseArray):
333320
from pandas.core.sparse.series import SparseSeries
334321
cls = SparseSeries
335-
336-
return cls(arr, index=index, name=name, dtype=dtype, copy=copy,
337-
fastpath=fastpath)
322+
return cls(arr, index=index, name=name, dtype=dtype,
323+
copy=copy, fastpath=fastpath)
338324

339325
@property
340326
def _constructor(self):

pandas/core/sparse/series.py

-6
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,6 @@ def from_array(cls, arr, index=None, name=None, copy=False,
216216
warnings.warn("'from_array' is deprecated and will be removed in a "
217217
"future version. Please use the pd.SparseSeries(..) "
218218
"constructor instead.", FutureWarning, stacklevel=2)
219-
return cls._from_array(arr, index=index, name=name, copy=copy,
220-
fill_value=fill_value, fastpath=fastpath)
221-
222-
@classmethod
223-
def _from_array(cls, arr, index=None, name=None, copy=False,
224-
fill_value=None, fastpath=False):
225219
return cls(arr, index=index, name=name, copy=copy,
226220
fill_value=fill_value, fastpath=fastpath)
227221

0 commit comments

Comments
 (0)