Skip to content

Commit f88ce60

Browse files
authored
Simplify updating new kwargs in NDCube.to_nddata
1 parent c54cfb0 commit f88ce60

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

ndcube/ndcube.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,11 +1476,12 @@ def to_nddata(self, *, nddata_type=NDData, **kwargs):
14761476
or a class that behaves like one. Default=`~astropy.nddata.NDData`.
14771477
14781478
kwargs:
1479-
Attributes to change on output object. For example, to change the data on the
1480-
returned object compare to this instance, set a kwarg ``data=new_data``.
1481-
Note that kwargs set to ``None`` will not be passed to the constructor
1482-
of the ``nddata_type``. Therefore, if that attribute exists on the new type,
1483-
it will be given the default value defined by ``nddata_type``'s call signature.
1479+
Inputs to the ``nddata_type`` constructor that should differ from the values
1480+
stored in attributes of this instance. For example, to set different data values
1481+
on the returned object, set a kwarg ``data=new_data``, where ``new_data`` is an
1482+
an array of compatible shape and dtype. Note that kwargs given by the user and
1483+
attributes on this instance that are not supported by the ``nddata_type``
1484+
constructor are ignored.
14841485
14851486
Returns
14861487
-------
@@ -1496,14 +1497,10 @@ def to_nddata(self, *, nddata_type=NDData, **kwargs):
14961497
14971498
>>> nddata_without_coords = cube.to_nddata(wcs=None) # doctest: +SKIP
14981499
"""
1499-
# Build dictionary of new attribute values from this NDCube instance.
1500+
# Build dictionary of new attribute values from this NDCube instance
1501+
# and update with user-defined kwargs.
15001502
new_kwargs = {key.strip("_"): value for key, value in self.__dict__.items()}
1501-
# Remove kwargs set to None and add kwargs that don't correspond to NDCube attrs.
1502-
for key, value in kwargs.items():
1503-
if value is None:
1504-
del new_kwargs[key]
1505-
else:
1506-
new_kwargs[key] = value
1503+
new_kwargs.update(kwargs)
15071504
# Inspect call signature of new_nddata class and
15081505
# remove unsupported items from new_kwargs.
15091506
nddata_sig = inspect.signature(nddata_type).parameters.keys()

0 commit comments

Comments
 (0)