Skip to content

Commit 6bd2e29

Browse files
committed
Fix Panel.update
1 parent eae2fec commit 6bd2e29

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

doc/source/whatsnew/v0.24.0.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ Deprecations
975975
- The ``fastpath`` keyword of the different Index constructors is deprecated (:issue:`23110`).
976976
- :meth:`Timestamp.tz_localize`, :meth:`DatetimeIndex.tz_localize`, and :meth:`Series.tz_localize` have deprecated the ``errors`` argument in favor of the ``nonexistent`` argument (:issue:`8917`)
977977
- The class ``FrozenNDArray`` has been deprecated. When unpickling, ``FrozenNDArray`` will be unpickled to ``np.ndarray`` once this class is removed (:issue:`9031`)
978-
- The method :meth:`DataFrame.update` has deprecated the ``raise_conflict=False|True`` keyword in favor of ``errors='ignore'|'raise'`` (:issue:`23585`)
978+
- The methods :meth:`DataFrame.update` and :meth:`Panel.update` have deprecated the ``raise_conflict=False|True`` keyword in favor of ``errors='ignore'|'raise'`` (:issue:`23585`)
979979
- Deprecated the `nthreads` keyword of :func:`pandas.read_feather` in favor of
980980
`use_threads` to reflect the changes in pyarrow 0.11.0. (:issue:`23053`)
981981
- :func:`pandas.read_excel` has deprecated accepting ``usecols`` as an integer. Please pass in a list of ints from 0 to ``usecols`` inclusive instead (:issue:`23527`)

pandas/core/panel.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
create_block_manager_from_blocks)
3333
from pandas.core.series import Series
3434
from pandas.core.reshape.util import cartesian_product
35-
from pandas.util._decorators import Appender, Substitution
35+
from pandas.util._decorators import Appender, Substitution, deprecate_kwarg
3636
from pandas.util._validators import validate_axis_style_args
3737

3838
_shared_doc_kwargs = dict(
@@ -1235,7 +1235,12 @@ def reindex(self, *args, **kwargs):
12351235
kwargs.update(axes)
12361236
kwargs.pop('axis', None)
12371237
kwargs.pop('labels', None)
1238-
return super(Panel, self).reindex(**kwargs)
1238+
1239+
with warnings.catch_warnings():
1240+
warnings.simplefilter("ignore", FutureWarning)
1241+
# do not warn about constructing Panel when reindexing
1242+
result = super(Panel, self).reindex(**kwargs)
1243+
return result
12391244

12401245
@Substitution(**_shared_doc_kwargs)
12411246
@Appender(NDFrame.rename.__doc__)
@@ -1377,8 +1382,10 @@ def join(self, other, how='left', lsuffix='', rsuffix=''):
13771382
return concat([self] + list(other), axis=0, join=how,
13781383
join_axes=join_axes, verify_integrity=True)
13791384

1385+
@deprecate_kwarg(old_arg_name='raise_conflict', new_arg_name='errors',
1386+
mapping={False: 'ignore', True: 'raise'})
13801387
def update(self, other, join='left', overwrite=True, filter_func=None,
1381-
raise_conflict=False):
1388+
errors='ignore'):
13821389
"""
13831390
Modify Panel in place using non-NA values from passed
13841391
Panel, or object coercible to Panel. Aligns on items
@@ -1393,8 +1400,8 @@ def update(self, other, join='left', overwrite=True, filter_func=None,
13931400
filter_func : callable(1d-array) -> 1d-array<boolean>, default None
13941401
Can choose to replace values other than NA. Return True for values
13951402
that should be updated
1396-
raise_conflict : bool
1397-
If True, will raise an error if a DataFrame and other both
1403+
errors : {'raise', 'ignore'}, default 'ignore'
1404+
If 'raise', will raise an error if a DataFrame and other both
13981405
contain data in the same place.
13991406
"""
14001407

@@ -1406,8 +1413,8 @@ def update(self, other, join='left', overwrite=True, filter_func=None,
14061413
other = other.reindex(**{axis_name: axis_values})
14071414

14081415
for frame in axis_values:
1409-
self[frame].update(other[frame], join, overwrite, filter_func,
1410-
raise_conflict)
1416+
self[frame].update(other[frame], join=join, overwrite=overwrite,
1417+
filter_func=filter_func, errors=errors)
14111418

14121419
def _get_join_index(self, other, how):
14131420
if how == 'left':

pandas/tests/test_panel.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,9 +2348,12 @@ def test_update_raise(self):
23482348
[[1.5, np.nan, 3.], [1.5, np.nan, 3.],
23492349
[1.5, np.nan, 3.],
23502350
[1.5, np.nan, 3.]]])
2351+
other = Panel([[[]]])
23512352

2352-
pytest.raises(Exception, pan.update, *(pan, ),
2353-
**{'raise_conflict': True})
2353+
with pytest.raises(ValueError, match='Data overlaps'):
2354+
pan.update(pan, errors='raise')
2355+
with tm.assert_produces_warning(FutureWarning):
2356+
pan.update(other, raise_conflict=True)
23542357

23552358
def test_all_any(self):
23562359
assert (self.panel.all(axis=0).values == nanall(

0 commit comments

Comments
 (0)