Skip to content

Commit f25791d

Browse files
jbrockmendelproost
authored andcommitted
DEPR: remove Series.from_array, DataFrame.from_items, as_matrix, asobject, as_blocks, blocks (pandas-dev#29720)
1 parent 47e5082 commit f25791d

File tree

11 files changed

+13
-362
lines changed

11 files changed

+13
-362
lines changed

doc/source/reference/frame.rst

-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,6 @@ Serialization / IO / conversion
351351
:toctree: api/
352352

353353
DataFrame.from_dict
354-
DataFrame.from_items
355354
DataFrame.from_records
356355
DataFrame.info
357356
DataFrame.to_parquet

doc/source/whatsnew/v1.0.0.rst

+6
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,12 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more.
312312

313313
- Removed the previously deprecated :meth:`Series.get_value`, :meth:`Series.set_value`, :meth:`DataFrame.get_value`, :meth:`DataFrame.set_value` (:issue:`17739`)
314314
- Changed the the default value of `inplace` in :meth:`DataFrame.set_index` and :meth:`Series.set_axis`. It now defaults to False (:issue:`27600`)
315+
- Removed support for nested renaming in :meth:`DataFrame.aggregate`, :meth:`Series.aggregate`, :meth:`DataFrameGroupBy.aggregate`, :meth:`SeriesGroupBy.aggregate`, :meth:`Rolling.aggregate` (:issue:`18529`)
316+
- Removed :meth:`Series.from_array` (:issue:`18258`)
317+
- Removed :meth:`DataFrame.from_items` (:issue:`18458`)
318+
- Removed :meth:`DataFrame.as_matrix`, :meth:`Series.as_matrix` (:issue:`18458`)
319+
- Removed :meth:`Series.asobject` (:issue:`18477`)
320+
- Removed :meth:`DataFrame.as_blocks`, :meth:`Series.as_blocks`, `DataFrame.blocks`, :meth:`Series.blocks` (:issue:`17656`)
315321
- :meth:`pandas.Series.str.cat` now defaults to aligning ``others``, using ``join='left'`` (:issue:`27611`)
316322
- :meth:`pandas.Series.str.cat` does not accept list-likes *within* list-likes anymore (:issue:`27611`)
317323
- Removed the previously deprecated :meth:`ExtensionArray._formatting_values`. Use :attr:`ExtensionArray._formatter` instead. (:issue:`23601`)

pandas/core/frame.py

+4-103
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
is_iterator,
7777
is_list_like,
7878
is_named_tuple,
79-
is_nested_list_like,
8079
is_object_dtype,
8180
is_scalar,
8281
is_sequence,
@@ -342,8 +341,9 @@ class DataFrame(NDFrame):
342341
--------
343342
DataFrame.from_records : Constructor from tuples, also record arrays.
344343
DataFrame.from_dict : From dicts of Series, arrays, or dicts.
345-
DataFrame.from_items : From sequence of (key, value) pairs
346-
read_csv, pandas.read_table, pandas.read_clipboard.
344+
read_csv
345+
read_table
346+
read_clipboard
347347
348348
Examples
349349
--------
@@ -387,9 +387,7 @@ def _constructor(self) -> Type["DataFrame"]:
387387
return DataFrame
388388

389389
_constructor_sliced = Series # type: Type[Series]
390-
_deprecations = NDFrame._deprecations | frozenset(
391-
["from_items"]
392-
) # type: FrozenSet[str]
390+
_deprecations = NDFrame._deprecations | frozenset([]) # type: FrozenSet[str]
393391
_accessors = set() # type: Set[str]
394392

395393
@property
@@ -1850,103 +1848,6 @@ def to_records(self, index=True, column_dtypes=None, index_dtypes=None):
18501848

18511849
return np.rec.fromarrays(arrays, dtype={"names": names, "formats": formats})
18521850

1853-
@classmethod
1854-
def from_items(cls, items, columns=None, orient="columns"):
1855-
"""
1856-
Construct a DataFrame from a list of tuples.
1857-
1858-
.. deprecated:: 0.23.0
1859-
`from_items` is deprecated and will be removed in a future version.
1860-
Use :meth:`DataFrame.from_dict(dict(items)) <DataFrame.from_dict>`
1861-
instead.
1862-
:meth:`DataFrame.from_dict(OrderedDict(items)) <DataFrame.from_dict>`
1863-
may be used to preserve the key order.
1864-
1865-
Convert (key, value) pairs to DataFrame. The keys will be the axis
1866-
index (usually the columns, but depends on the specified
1867-
orientation). The values should be arrays or Series.
1868-
1869-
Parameters
1870-
----------
1871-
items : sequence of (key, value) pairs
1872-
Values should be arrays or Series.
1873-
columns : sequence of column labels, optional
1874-
Must be passed if orient='index'.
1875-
orient : {'columns', 'index'}, default 'columns'
1876-
The "orientation" of the data. If the keys of the
1877-
input correspond to column labels, pass 'columns'
1878-
(default). Otherwise if the keys correspond to the index,
1879-
pass 'index'.
1880-
1881-
Returns
1882-
-------
1883-
DataFrame
1884-
"""
1885-
1886-
warnings.warn(
1887-
"from_items is deprecated. Please use "
1888-
"DataFrame.from_dict(dict(items), ...) instead. "
1889-
"DataFrame.from_dict(OrderedDict(items)) may be used to "
1890-
"preserve the key order.",
1891-
FutureWarning,
1892-
stacklevel=2,
1893-
)
1894-
1895-
keys, values = zip(*items)
1896-
1897-
if orient == "columns":
1898-
if columns is not None:
1899-
columns = ensure_index(columns)
1900-
1901-
idict = dict(items)
1902-
if len(idict) < len(items):
1903-
if not columns.equals(ensure_index(keys)):
1904-
raise ValueError(
1905-
"With non-unique item names, passed "
1906-
"columns must be identical"
1907-
)
1908-
arrays = values
1909-
else:
1910-
arrays = [idict[k] for k in columns if k in idict]
1911-
else:
1912-
columns = ensure_index(keys)
1913-
arrays = values
1914-
1915-
# GH 17312
1916-
# Provide more informative error msg when scalar values passed
1917-
try:
1918-
return cls._from_arrays(arrays, columns, None)
1919-
1920-
except ValueError:
1921-
if not is_nested_list_like(values):
1922-
raise ValueError(
1923-
"The value in each (key, value) pair "
1924-
"must be an array, Series, or dict"
1925-
)
1926-
1927-
elif orient == "index":
1928-
if columns is None:
1929-
raise TypeError("Must pass columns with orient='index'")
1930-
1931-
keys = ensure_index(keys)
1932-
1933-
# GH 17312
1934-
# Provide more informative error msg when scalar values passed
1935-
try:
1936-
arr = np.array(values, dtype=object).T
1937-
data = [lib.maybe_convert_objects(v) for v in arr]
1938-
return cls._from_arrays(data, columns, keys)
1939-
1940-
except TypeError:
1941-
if not is_nested_list_like(values):
1942-
raise ValueError(
1943-
"The value in each (key, value) pair "
1944-
"must be an array, Series, or dict"
1945-
)
1946-
1947-
else: # pragma: no cover
1948-
raise ValueError("'orient' must be either 'columns' or 'index'")
1949-
19501851
@classmethod
19511852
def _from_arrays(cls, arrays, columns, index, dtype=None):
19521853
mgr = arrays_to_mgr(arrays, columns, index, columns, dtype=dtype)

pandas/core/generic.py

-85
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,6 @@ class NDFrame(PandasObject, SelectionMixin):
173173
_accessors = set() # type: Set[str]
174174
_deprecations = frozenset(
175175
[
176-
"as_blocks",
177-
"as_matrix",
178-
"blocks",
179176
"clip_lower",
180177
"clip_upper",
181178
"get_dtype_counts",
@@ -5409,54 +5406,6 @@ def _get_bool_data(self):
54095406
# ----------------------------------------------------------------------
54105407
# Internal Interface Methods
54115408

5412-
def as_matrix(self, columns=None):
5413-
"""
5414-
Convert the frame to its Numpy-array representation.
5415-
5416-
.. deprecated:: 0.23.0
5417-
Use :meth:`DataFrame.values` instead.
5418-
5419-
Parameters
5420-
----------
5421-
columns : list, optional, default:None
5422-
If None, return all columns, otherwise, returns specified columns.
5423-
5424-
Returns
5425-
-------
5426-
values : ndarray
5427-
If the caller is heterogeneous and contains booleans or objects,
5428-
the result will be of dtype=object. See Notes.
5429-
5430-
See Also
5431-
--------
5432-
DataFrame.values
5433-
5434-
Notes
5435-
-----
5436-
Return is NOT a Numpy-matrix, rather, a Numpy-array.
5437-
5438-
The dtype will be a lower-common-denominator dtype (implicit
5439-
upcasting); that is to say if the dtypes (even of numeric types)
5440-
are mixed, the one that accommodates all will be chosen. Use this
5441-
with care if you are not dealing with the blocks.
5442-
5443-
e.g. If the dtypes are float16 and float32, dtype will be upcast to
5444-
float32. If dtypes are int32 and uint8, dtype will be upcase to
5445-
int32. By numpy.find_common_type convention, mixing int64 and uint64
5446-
will result in a float64 dtype.
5447-
5448-
This method is provided for backwards compatibility. Generally,
5449-
it is recommended to use '.values'.
5450-
"""
5451-
warnings.warn(
5452-
"Method .as_matrix will be removed in a future version. "
5453-
"Use .values instead.",
5454-
FutureWarning,
5455-
stacklevel=2,
5456-
)
5457-
self._consolidate_inplace()
5458-
return self._data.as_array(transpose=self._AXIS_REVERSED, items=columns)
5459-
54605409
@property
54615410
def values(self):
54625411
"""
@@ -5774,40 +5723,6 @@ def ftypes(self):
57745723

57755724
return Series(self._data.get_ftypes(), index=self._info_axis, dtype=np.object_)
57765725

5777-
def as_blocks(self, copy=True):
5778-
"""
5779-
Convert the frame to a dict of dtype -> Constructor Types.
5780-
5781-
.. deprecated:: 0.21.0
5782-
5783-
NOTE: the dtypes of the blocks WILL BE PRESERVED HERE (unlike in
5784-
as_matrix)
5785-
5786-
Parameters
5787-
----------
5788-
copy : bool, default True
5789-
5790-
Returns
5791-
-------
5792-
dict
5793-
Mapping dtype -> Constructor Types.
5794-
"""
5795-
warnings.warn(
5796-
"as_blocks is deprecated and will be removed in a future version",
5797-
FutureWarning,
5798-
stacklevel=2,
5799-
)
5800-
return self._to_dict_of_blocks(copy=copy)
5801-
5802-
@property
5803-
def blocks(self):
5804-
"""
5805-
Internal property, property synonym for as_blocks().
5806-
5807-
.. deprecated:: 0.21.0
5808-
"""
5809-
return self.as_blocks()
5810-
58115726
def _to_dict_of_blocks(self, copy=True):
58125727
"""
58135728
Return a dict of dtype -> Constructor Types that

pandas/core/series.py

+1-55
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,7 @@ class Series(base.IndexOpsMixin, generic.NDFrame):
176176
base.IndexOpsMixin._deprecations
177177
| generic.NDFrame._deprecations
178178
| frozenset(
179-
[
180-
"asobject",
181-
"compress",
182-
"valid",
183-
"ftype",
184-
"real",
185-
"imag",
186-
"put",
187-
"ptp",
188-
"nonzero",
189-
]
179+
["compress", "valid", "ftype", "real", "imag", "put", "ptp", "nonzero"]
190180
)
191181
)
192182

@@ -364,32 +354,6 @@ def _init_dict(self, data, index=None, dtype=None):
364354
s = s.reindex(index, copy=False)
365355
return s._data, s.index
366356

367-
@classmethod
368-
def from_array(
369-
cls, arr, index=None, name=None, dtype=None, copy=False, fastpath=False
370-
):
371-
"""
372-
Construct Series from array.
373-
374-
.. deprecated:: 0.23.0
375-
Use pd.Series(..) constructor instead.
376-
377-
Returns
378-
-------
379-
Series
380-
Constructed Series.
381-
"""
382-
warnings.warn(
383-
"'from_array' is deprecated and will be removed in a "
384-
"future version. Please use the pd.Series(..) "
385-
"constructor instead.",
386-
FutureWarning,
387-
stacklevel=2,
388-
)
389-
return cls(
390-
arr, index=index, name=name, dtype=dtype, copy=copy, fastpath=fastpath
391-
)
392-
393357
# ----------------------------------------------------------------------
394358

395359
@property
@@ -579,24 +543,6 @@ def get_values(self):
579543
def _internal_get_values(self):
580544
return self._data.get_values()
581545

582-
@property
583-
def asobject(self):
584-
"""
585-
Return object Series which contains boxed values.
586-
587-
.. deprecated:: 0.23.0
588-
589-
Use ``astype(object)`` instead.
590-
591-
*this is an internal non-public method*
592-
"""
593-
warnings.warn(
594-
"'asobject' is deprecated. Use 'astype(object)' instead",
595-
FutureWarning,
596-
stacklevel=2,
597-
)
598-
return self.astype(object).values
599-
600546
# ops
601547
def ravel(self, order="C"):
602548
"""

pandas/tests/frame/test_api.py

-8
Original file line numberDiff line numberDiff line change
@@ -476,14 +476,6 @@ def test_values(self, float_frame):
476476
float_frame.values[:, 0] = 5.0
477477
assert (float_frame.values[:, 0] == 5).all()
478478

479-
def test_as_matrix_deprecated(self, float_frame):
480-
# GH 18458
481-
with tm.assert_produces_warning(FutureWarning):
482-
cols = float_frame.columns.tolist()
483-
result = float_frame.as_matrix(columns=cols)
484-
expected = float_frame.values
485-
tm.assert_numpy_array_equal(result, expected)
486-
487479
def test_deepcopy(self, float_frame):
488480
cp = deepcopy(float_frame)
489481
series = cp["A"]

pandas/tests/frame/test_block_internals.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,7 @@ def test_copy_blocks(self, float_frame):
313313
column = df.columns[0]
314314

315315
# use the default copy=True, change a column
316-
317-
# deprecated 0.21.0
318-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
319-
blocks = df.as_blocks()
316+
blocks = df._to_dict_of_blocks(copy=True)
320317
for dtype, _df in blocks.items():
321318
if column in _df:
322319
_df.loc[:, column] = _df[column] + 1
@@ -330,10 +327,7 @@ def test_no_copy_blocks(self, float_frame):
330327
column = df.columns[0]
331328

332329
# use the copy=False, change a column
333-
334-
# deprecated 0.21.0
335-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
336-
blocks = df.as_blocks(copy=False)
330+
blocks = df._to_dict_of_blocks(copy=False)
337331
for dtype, _df in blocks.items():
338332
if column in _df:
339333
_df.loc[:, column] = _df[column] + 1

0 commit comments

Comments
 (0)