Repository: astropy/ccdproc

Issue:
`Combiner` and `combine` should accept a generator as argument
Both `Combine` and `combiner` should accept a generator (e.g. `Combiner(ifo.ccds())`) instead of requiring that the input be a list (e.g. `Combiner ([ccd for ccd in ifc.ccds()])`). This issue was first raised by @janerigby in #754.

Comments:

Patch:
diff --git a/AUTHORS.rst b/AUTHORS.rst
index aaf3470..f067a45 100644
--- a/AUTHORS.rst
+++ b/AUTHORS.rst
@@ -56,6 +56,7 @@ Alphabetical list of contributors
 * Nathan Walker (@walkerna22)
 * Benjamin Weiner (@bjweiner)
 * Jiyong Youn (@hletrd)
+* Yash Gondhalekar (@Yash-10)
 
 (If you have contributed to the ccdproc project and your name is missing,
 please send an email to the coordinators, or
diff --git a/CHANGES.rst b/CHANGES.rst
index 1d9ac18..d21f3a1 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -16,6 +16,8 @@ Bug Fixes
 - ``test_image_collection.py`` in the test suite no longer produces
  permanent files on disk and cleans up after itself. [#738]
 
+- Change ``Combiner`` to allow accepting either a list or a generator [#757]
+
 2.1.0 (2019-12-24)
 ------------------
 
diff --git a/ccdproc/combiner.py b/ccdproc/combiner.py
index 2e6eefc..39f3e28 100644
--- a/ccdproc/combiner.py
+++ b/ccdproc/combiner.py
@@ -22,8 +22,8 @@ class Combiner:
 
     Parameters
     -----------
-    ccd_list : list
-        A list of CCDData objects that will be combined together.
+    ccd_iter : list or generator
+        A list or generator of CCDData objects that will be combined together.
 
     dtype : str or `numpy.dtype` or None, optional
         Allows user to set dtype. See `numpy.array` ``dtype`` parameter
@@ -33,7 +33,7 @@ class Combiner:
     Raises
     ------
     TypeError
-        If the ``ccd_list`` are not `~astropy.nddata.CCDData` objects, have different
+        If the ``ccd_iter`` are not `~astropy.nddata.CCDData` objects, have different
         units, or are different shapes.
 
     Examples
@@ -56,15 +56,18 @@ class Combiner:
                  [ 0.66666667,  0.66666667,  0.66666667,  0.66666667],
                  [ 0.66666667,  0.66666667,  0.66666667,  0.66666667]])
     """
-    def __init__(self, ccd_list, dtype=None):
-        if ccd_list is None:
-            raise TypeError("ccd_list should be a list of CCDData objects.")
+    def __init__(self, ccd_iter, dtype=None):
+        if ccd_iter is None:
+            raise TypeError("ccd_iter should be a list or a generator of CCDData objects.")
 
         if dtype is None:
             dtype = np.float64
 
         default_shape = None
         default_unit = None
+
+        ccd_list = list(ccd_iter)
+
         for ccd in ccd_list:
             # raise an error if the objects aren't CCDData objects
             if not isinstance(ccd, CCDData):


Test patch:
diff --git a/ccdproc/tests/test_combiner.py b/ccdproc/tests/test_combiner.py
index a9988d3..b758c66 100644
--- a/ccdproc/tests/test_combiner.py
+++ b/ccdproc/tests/test_combiner.py
@@ -696,3 +696,13 @@ def test_ystep_calculation(num_chunks, expected):
 
     xstep, ystep = _calculate_step_sizes(2000, 2000, num_chunks)
     assert xstep == expected[0] and ystep == expected[1]
+
+def test_combiner_gen():
+    ccd_data = ccd_data_func()
+    def create_gen():
+        yield ccd_data
+        yield ccd_data
+        yield ccd_data
+    c = Combiner(create_gen())
+    assert c.data_arr.shape == (3, 100, 100)
+    assert c.data_arr.mask.shape == (3, 100, 100)