diff --git a/doc/source/reference/frame.rst b/doc/source/reference/frame.rst index 4b5faed0f4d2d5..37d27093efefdc 100644 --- a/doc/source/reference/frame.rst +++ b/doc/source/reference/frame.rst @@ -351,7 +351,6 @@ Serialization / IO / conversion :toctree: api/ DataFrame.from_dict - DataFrame.from_items DataFrame.from_records DataFrame.info DataFrame.to_parquet diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index c3ff0e83938fa3..7ac1830af568c7 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -312,6 +312,12 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more. - Removed the previously deprecated :meth:`Series.get_value`, :meth:`Series.set_value`, :meth:`DataFrame.get_value`, :meth:`DataFrame.set_value` (:issue:`17739`) - Changed the the default value of `inplace` in :meth:`DataFrame.set_index` and :meth:`Series.set_axis`. It now defaults to False (:issue:`27600`) +- Removed support for nested renaming in :meth:`DataFrame.aggregate`, :meth:`Series.aggregate`, :meth:`DataFrameGroupBy.aggregate`, :meth:`SeriesGroupBy.aggregate`, :meth:`Rolling.aggregate` (:issue:`18529`) +- Removed :meth:`Series.from_array` (:issue:`18258`) +- Removed :meth:`DataFrame.from_items` (:issue:`18458`) +- Removed :meth:`DataFrame.as_matrix`, :meth:`Series.as_matrix` (:issue:`18458`) +- Removed :meth:`Series.asobject` (:issue:`18477`) +- Removed :meth:`DataFrame.as_blocks`, :meth:`Series.as_blocks`, `DataFrame.blocks`, :meth:`Series.blocks` (:issue:`17656`) - :meth:`pandas.Series.str.cat` now defaults to aligning ``others``, using ``join='left'`` (:issue:`27611`) - :meth:`pandas.Series.str.cat` does not accept list-likes *within* list-likes anymore (:issue:`27611`) - Removed the previously deprecated :meth:`ExtensionArray._formatting_values`. Use :attr:`ExtensionArray._formatter` instead. (:issue:`23601`) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index cb74fff51e7a38..dbf9f1b2082a3c 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -76,7 +76,6 @@ is_iterator, is_list_like, is_named_tuple, - is_nested_list_like, is_object_dtype, is_scalar, is_sequence, @@ -342,8 +341,9 @@ class DataFrame(NDFrame): -------- DataFrame.from_records : Constructor from tuples, also record arrays. DataFrame.from_dict : From dicts of Series, arrays, or dicts. - DataFrame.from_items : From sequence of (key, value) pairs - read_csv, pandas.read_table, pandas.read_clipboard. + read_csv + read_table + read_clipboard Examples -------- @@ -387,9 +387,7 @@ def _constructor(self) -> Type["DataFrame"]: return DataFrame _constructor_sliced = Series # type: Type[Series] - _deprecations = NDFrame._deprecations | frozenset( - ["from_items"] - ) # type: FrozenSet[str] + _deprecations = NDFrame._deprecations | frozenset([]) # type: FrozenSet[str] _accessors = set() # type: Set[str] @property @@ -1850,103 +1848,6 @@ def to_records(self, index=True, column_dtypes=None, index_dtypes=None): return np.rec.fromarrays(arrays, dtype={"names": names, "formats": formats}) - @classmethod - def from_items(cls, items, columns=None, orient="columns"): - """ - Construct a DataFrame from a list of tuples. - - .. deprecated:: 0.23.0 - `from_items` is deprecated and will be removed in a future version. - Use :meth:`DataFrame.from_dict(dict(items)) ` - instead. - :meth:`DataFrame.from_dict(OrderedDict(items)) ` - may be used to preserve the key order. - - Convert (key, value) pairs to DataFrame. The keys will be the axis - index (usually the columns, but depends on the specified - orientation). The values should be arrays or Series. - - Parameters - ---------- - items : sequence of (key, value) pairs - Values should be arrays or Series. - columns : sequence of column labels, optional - Must be passed if orient='index'. - orient : {'columns', 'index'}, default 'columns' - The "orientation" of the data. If the keys of the - input correspond to column labels, pass 'columns' - (default). Otherwise if the keys correspond to the index, - pass 'index'. - - Returns - ------- - DataFrame - """ - - warnings.warn( - "from_items is deprecated. Please use " - "DataFrame.from_dict(dict(items), ...) instead. " - "DataFrame.from_dict(OrderedDict(items)) may be used to " - "preserve the key order.", - FutureWarning, - stacklevel=2, - ) - - keys, values = zip(*items) - - if orient == "columns": - if columns is not None: - columns = ensure_index(columns) - - idict = dict(items) - if len(idict) < len(items): - if not columns.equals(ensure_index(keys)): - raise ValueError( - "With non-unique item names, passed " - "columns must be identical" - ) - arrays = values - else: - arrays = [idict[k] for k in columns if k in idict] - else: - columns = ensure_index(keys) - arrays = values - - # GH 17312 - # Provide more informative error msg when scalar values passed - try: - return cls._from_arrays(arrays, columns, None) - - except ValueError: - if not is_nested_list_like(values): - raise ValueError( - "The value in each (key, value) pair " - "must be an array, Series, or dict" - ) - - elif orient == "index": - if columns is None: - raise TypeError("Must pass columns with orient='index'") - - keys = ensure_index(keys) - - # GH 17312 - # Provide more informative error msg when scalar values passed - try: - arr = np.array(values, dtype=object).T - data = [lib.maybe_convert_objects(v) for v in arr] - return cls._from_arrays(data, columns, keys) - - except TypeError: - if not is_nested_list_like(values): - raise ValueError( - "The value in each (key, value) pair " - "must be an array, Series, or dict" - ) - - else: # pragma: no cover - raise ValueError("'orient' must be either 'columns' or 'index'") - @classmethod def _from_arrays(cls, arrays, columns, index, dtype=None): mgr = arrays_to_mgr(arrays, columns, index, columns, dtype=dtype) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 4f45a96d239418..6fbe95fa973cbf 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -173,9 +173,6 @@ class NDFrame(PandasObject, SelectionMixin): _accessors = set() # type: Set[str] _deprecations = frozenset( [ - "as_blocks", - "as_matrix", - "blocks", "clip_lower", "clip_upper", "get_dtype_counts", @@ -5409,54 +5406,6 @@ def _get_bool_data(self): # ---------------------------------------------------------------------- # Internal Interface Methods - def as_matrix(self, columns=None): - """ - Convert the frame to its Numpy-array representation. - - .. deprecated:: 0.23.0 - Use :meth:`DataFrame.values` instead. - - Parameters - ---------- - columns : list, optional, default:None - If None, return all columns, otherwise, returns specified columns. - - Returns - ------- - values : ndarray - If the caller is heterogeneous and contains booleans or objects, - the result will be of dtype=object. See Notes. - - See Also - -------- - DataFrame.values - - Notes - ----- - Return is NOT a Numpy-matrix, rather, a Numpy-array. - - The dtype will be a lower-common-denominator dtype (implicit - upcasting); that is to say if the dtypes (even of numeric types) - are mixed, the one that accommodates all will be chosen. Use this - with care if you are not dealing with the blocks. - - e.g. If the dtypes are float16 and float32, dtype will be upcast to - float32. If dtypes are int32 and uint8, dtype will be upcase to - int32. By numpy.find_common_type convention, mixing int64 and uint64 - will result in a float64 dtype. - - This method is provided for backwards compatibility. Generally, - it is recommended to use '.values'. - """ - warnings.warn( - "Method .as_matrix will be removed in a future version. " - "Use .values instead.", - FutureWarning, - stacklevel=2, - ) - self._consolidate_inplace() - return self._data.as_array(transpose=self._AXIS_REVERSED, items=columns) - @property def values(self): """ @@ -5774,40 +5723,6 @@ def ftypes(self): return Series(self._data.get_ftypes(), index=self._info_axis, dtype=np.object_) - def as_blocks(self, copy=True): - """ - Convert the frame to a dict of dtype -> Constructor Types. - - .. deprecated:: 0.21.0 - - NOTE: the dtypes of the blocks WILL BE PRESERVED HERE (unlike in - as_matrix) - - Parameters - ---------- - copy : bool, default True - - Returns - ------- - dict - Mapping dtype -> Constructor Types. - """ - warnings.warn( - "as_blocks is deprecated and will be removed in a future version", - FutureWarning, - stacklevel=2, - ) - return self._to_dict_of_blocks(copy=copy) - - @property - def blocks(self): - """ - Internal property, property synonym for as_blocks(). - - .. deprecated:: 0.21.0 - """ - return self.as_blocks() - def _to_dict_of_blocks(self, copy=True): """ Return a dict of dtype -> Constructor Types that diff --git a/pandas/core/series.py b/pandas/core/series.py index 14056c99bd6863..c10871d04ef3e2 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -176,17 +176,7 @@ class Series(base.IndexOpsMixin, generic.NDFrame): base.IndexOpsMixin._deprecations | generic.NDFrame._deprecations | frozenset( - [ - "asobject", - "compress", - "valid", - "ftype", - "real", - "imag", - "put", - "ptp", - "nonzero", - ] + ["compress", "valid", "ftype", "real", "imag", "put", "ptp", "nonzero"] ) ) @@ -364,32 +354,6 @@ def _init_dict(self, data, index=None, dtype=None): s = s.reindex(index, copy=False) return s._data, s.index - @classmethod - def from_array( - cls, arr, index=None, name=None, dtype=None, copy=False, fastpath=False - ): - """ - Construct Series from array. - - .. deprecated:: 0.23.0 - Use pd.Series(..) constructor instead. - - Returns - ------- - Series - Constructed Series. - """ - 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( - arr, index=index, name=name, dtype=dtype, copy=copy, fastpath=fastpath - ) - # ---------------------------------------------------------------------- @property @@ -579,24 +543,6 @@ def get_values(self): def _internal_get_values(self): return self._data.get_values() - @property - def asobject(self): - """ - Return object Series which contains boxed values. - - .. deprecated:: 0.23.0 - - Use ``astype(object)`` instead. - - *this is an internal non-public method* - """ - warnings.warn( - "'asobject' is deprecated. Use 'astype(object)' instead", - FutureWarning, - stacklevel=2, - ) - return self.astype(object).values - # ops def ravel(self, order="C"): """ diff --git a/pandas/tests/frame/test_api.py b/pandas/tests/frame/test_api.py index 50b1dec21c5490..a86e1dfe8353ca 100644 --- a/pandas/tests/frame/test_api.py +++ b/pandas/tests/frame/test_api.py @@ -476,14 +476,6 @@ def test_values(self, float_frame): float_frame.values[:, 0] = 5.0 assert (float_frame.values[:, 0] == 5).all() - def test_as_matrix_deprecated(self, float_frame): - # GH 18458 - with tm.assert_produces_warning(FutureWarning): - cols = float_frame.columns.tolist() - result = float_frame.as_matrix(columns=cols) - expected = float_frame.values - tm.assert_numpy_array_equal(result, expected) - def test_deepcopy(self, float_frame): cp = deepcopy(float_frame) series = cp["A"] diff --git a/pandas/tests/frame/test_block_internals.py b/pandas/tests/frame/test_block_internals.py index b45c074f179a03..d491e9f25c897d 100644 --- a/pandas/tests/frame/test_block_internals.py +++ b/pandas/tests/frame/test_block_internals.py @@ -313,10 +313,7 @@ def test_copy_blocks(self, float_frame): column = df.columns[0] # use the default copy=True, change a column - - # deprecated 0.21.0 - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - blocks = df.as_blocks() + blocks = df._to_dict_of_blocks(copy=True) for dtype, _df in blocks.items(): if column in _df: _df.loc[:, column] = _df[column] + 1 @@ -330,10 +327,7 @@ def test_no_copy_blocks(self, float_frame): column = df.columns[0] # use the copy=False, change a column - - # deprecated 0.21.0 - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - blocks = df.as_blocks(copy=False) + blocks = df._to_dict_of_blocks(copy=False) for dtype, _df in blocks.items(): if column in _df: _df.loc[:, column] = _df[column] + 1 diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index cc2e37c14bdf0a..ce0ebdbe563545 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -10,7 +10,6 @@ from pandas.compat import is_platform_little_endian -from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike from pandas.core.dtypes.common import is_integer_dtype import pandas as pd @@ -1508,92 +1507,6 @@ def test_constructor_manager_resize(self, float_frame): tm.assert_index_equal(result.index, Index(index)) tm.assert_index_equal(result.columns, Index(columns)) - def test_constructor_from_items(self, float_frame, float_string_frame): - items = [(c, float_frame[c]) for c in float_frame.columns] - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - recons = DataFrame.from_items(items) - tm.assert_frame_equal(recons, float_frame) - - # pass some columns - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - recons = DataFrame.from_items(items, columns=["C", "B", "A"]) - tm.assert_frame_equal(recons, float_frame.loc[:, ["C", "B", "A"]]) - - # orient='index' - - row_items = [ - (idx, float_string_frame.xs(idx)) for idx in float_string_frame.index - ] - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - recons = DataFrame.from_items( - row_items, columns=float_string_frame.columns, orient="index" - ) - tm.assert_frame_equal(recons, float_string_frame) - assert recons["A"].dtype == np.float64 - - msg = "Must pass columns with orient='index'" - with pytest.raises(TypeError, match=msg): - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - DataFrame.from_items(row_items, orient="index") - - # orient='index', but thar be tuples - arr = construct_1d_object_array_from_listlike( - [("bar", "baz")] * len(float_string_frame) - ) - float_string_frame["foo"] = arr - row_items = [ - (idx, list(float_string_frame.xs(idx))) for idx in float_string_frame.index - ] - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - recons = DataFrame.from_items( - row_items, columns=float_string_frame.columns, orient="index" - ) - tm.assert_frame_equal(recons, float_string_frame) - assert isinstance(recons["foo"][0], tuple) - - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - rs = DataFrame.from_items( - [("A", [1, 2, 3]), ("B", [4, 5, 6])], - orient="index", - columns=["one", "two", "three"], - ) - xp = DataFrame( - [[1, 2, 3], [4, 5, 6]], index=["A", "B"], columns=["one", "two", "three"] - ) - tm.assert_frame_equal(rs, xp) - - def test_constructor_from_items_scalars(self): - # GH 17312 - msg = ( - r"The value in each \(key, value\) " - "pair must be an array, Series, or dict" - ) - with pytest.raises(ValueError, match=msg): - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - DataFrame.from_items([("A", 1), ("B", 4)]) - - msg = ( - r"The value in each \(key, value\) " - "pair must be an array, Series, or dict" - ) - with pytest.raises(ValueError, match=msg): - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - DataFrame.from_items( - [("A", 1), ("B", 2)], columns=["col1"], orient="index" - ) - - def test_from_items_deprecation(self): - # GH 17320 - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - DataFrame.from_items([("A", [1, 2, 3]), ("B", [4, 5, 6])]) - - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - DataFrame.from_items( - [("A", [1, 2, 3]), ("B", [4, 5, 6])], - columns=["col1", "col2", "col3"], - orient="index", - ) - def test_constructor_mix_series_nonseries(self, float_frame): df = DataFrame( {"A": float_frame["A"], "B": list(float_frame["B"])}, columns=["A", "B"] diff --git a/pandas/tests/series/test_api.py b/pandas/tests/series/test_api.py index 00c66c8a13bd90..1e4757ffecb5d9 100644 --- a/pandas/tests/series/test_api.py +++ b/pandas/tests/series/test_api.py @@ -199,11 +199,6 @@ def test_constructor_dict_timedelta_index(self): ) self._assert_series_equal(result, expected) - def test_from_array_deprecated(self): - - with tm.assert_produces_warning(FutureWarning, check_stacklevel=True): - self.series_klass.from_array([1, 2, 3]) - def test_sparse_accessor_updates_on_inplace(self): s = pd.Series([1, 1, 2, 3], dtype="Sparse[int]") s.drop([0, 1], inplace=True) diff --git a/pandas/tests/series/test_dtypes.py b/pandas/tests/series/test_dtypes.py index 4b03115c11cb3b..e1ace952f722da 100644 --- a/pandas/tests/series/test_dtypes.py +++ b/pandas/tests/series/test_dtypes.py @@ -44,12 +44,6 @@ def test_astype(self, dtype): assert as_typed.dtype == dtype assert as_typed.name == s.name - def test_asobject_deprecated(self): - s = Series(np.random.randn(5), name="foo") - with tm.assert_produces_warning(FutureWarning): - o = s.asobject - assert isinstance(o, np.ndarray) - def test_dtype(self, datetime_series): assert datetime_series.dtype == np.dtype("float64") diff --git a/pandas/tests/series/test_timeseries.py b/pandas/tests/series/test_timeseries.py index cf06a9a7c84158..1587ae5eb7d074 100644 --- a/pandas/tests/series/test_timeseries.py +++ b/pandas/tests/series/test_timeseries.py @@ -1040,10 +1040,6 @@ def test_from_M8_structured(self): assert isinstance(s[0], Timestamp) assert s[0] == dates[0][0] - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - s = Series.from_array(arr["Date"], Index([0])) - assert s[0] == dates[0][0] - def test_get_level_values_box(self): from pandas import MultiIndex