Repository: pydata/xarray

Issue:
DataArrayResample.interpolate and passing kwargs
### What is your issue?

The docs [here](https://docs.xarray.dev/en/stable/generated/xarray.core.resample.DataArrayResample.interpolate.html) state that it is possible to use `polynomial` interpolation when resampling. 

If you try this though:

```python
data_per_minute = ds.resample(
    valid_time="1min"
).interpolate("polynomial")
```

You get the following:

```
ValueError: order is required when method=polynomial
```

The docs [here](https://docs.xarray.dev/en/stable/generated/xarray.core.resample.DataArrayResample.interpolate.html) state that you need to pass in order, how is this possible?

If you then try:

```python
data_per_minute = ds.resample(
    valid_time="1min"
).interpolate(kind="polynomial", order=3)
```

You get:

```
TypeError: Resample.interpolate() got an unexpected keyword argument 'order'
```

How can the order be specified? Thank you in advance. 

Discussion:
welcome[bot]: Thank you for opening this pull request! It may take us a few days to respond here, so thank you for being patient.
If you have questions, some answers may be found in our [contributing guidelines](http://docs.xarray.dev/en/stable/contributing.html).

dcherian: Thanks a lot @nkarasiak this is a nice first PR.

Can you update the test here please for `kind="polynomial", order=1`? https://github.com/pydata/xarray/blob/ef709df9623332e0a86881ef032b788fe5c51213/xarray/tests/test_groupby.py#L2055


nkarasiak: Tests and implementation are ok for me👍 
A bug happenned in `CI / windows-latest py3.12 (pull_request) Failing after 19m` that doesn't seem to come from any of my little update.
dcherian: Nice thanks @nkarasiak welcome to Xarray!

Patch:
diff --git a/doc/user-guide/io.rst b/doc/user-guide/io.rst
index b73d0fdc..fd6b7708 100644
--- a/doc/user-guide/io.rst
+++ b/doc/user-guide/io.rst
@@ -416,7 +416,8 @@ read the data.
 Scaling and type conversions
 ............................
 
-These encoding options work on any version of the netCDF file format:
+These encoding options (based on `CF Conventions on packed data`_) work on any
+version of the netCDF file format:
 
 - ``dtype``: Any valid NumPy dtype or string convertible to a dtype, e.g., ``'int16'``
   or ``'float32'``. This controls the type of the data written on disk.
@@ -427,7 +428,8 @@ These encoding options work on any version of the netCDF file format:
   output file, unless explicitly disabled with an encoding ``{'_FillValue': None}``.
 - ``scale_factor`` and ``add_offset``: Used to convert from encoded data on disk to
   to the decoded data in memory, according to the formula
-  ``decoded = scale_factor * encoded + add_offset``.
+  ``decoded = scale_factor * encoded + add_offset``. Please note that ``scale_factor``
+  and ``add_offset`` must be of same type and determine the type of the decoded data.
 
 These parameters can be fruitfully combined to compress discretized data on disk. For
 example, to save the variable ``foo`` with a precision of 0.1 in 16-bit integers while
@@ -435,6 +437,8 @@ converting ``NaN`` to ``-9999``, we would use
 ``encoding={'foo': {'dtype': 'int16', 'scale_factor': 0.1, '_FillValue': -9999}}``.
 Compression and decompression with such discretization is extremely fast.
 
+.. _CF Conventions on packed data: https://cfconventions.org/cf-conventions/cf-conventions.html#packed-data
+
 .. _io.string-encoding:
 
 String encoding
diff --git a/doc/whats-new.rst b/doc/whats-new.rst
index 6a97ceaf..96005e17 100644
--- a/doc/whats-new.rst
+++ b/doc/whats-new.rst
@@ -41,9 +41,15 @@ Deprecations
 Bug fixes
 ~~~~~~~~~
 
+- :py:meth:`DataArrayResample.interpolate` and :py:meth:`DatasetResample.interpolate` method now
+  support aribtrary kwargs such as ``order`` for polynomial interpolation. (:issue:`8762`).
+  By `Nicolas Karasiak <https://github.com/nkarasiak>`_.
+
 
 Documentation
 ~~~~~~~~~~~~~
+- Add link to CF Conventions on packed data and sentence on type determination in doc/user-guide/io.rst (:issue:`9041`, :pull:`9045`).
+  By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_.
 
 
 Internal Changes
diff --git a/xarray/core/resample.py b/xarray/core/resample.py
index 3bb158ac..9181bb4e 100644
--- a/xarray/core/resample.py
+++ b/xarray/core/resample.py
@@ -140,7 +140,7 @@ class Resample(GroupBy[T_Xarray]):
             {self._dim: grouper.full_index}, method="nearest", tolerance=tolerance
         )
 
-    def interpolate(self, kind: InterpOptions = "linear") -> T_Xarray:
+    def interpolate(self, kind: InterpOptions = "linear", **kwargs) -> T_Xarray:
         """Interpolate up-sampled data using the original data as knots.
 
         Parameters
@@ -168,17 +168,18 @@ class Resample(GroupBy[T_Xarray]):
         scipy.interpolate.interp1d
 
         """
-        return self._interpolate(kind=kind)
+        return self._interpolate(kind=kind, **kwargs)
 
-    def _interpolate(self, kind="linear") -> T_Xarray:
+    def _interpolate(self, kind="linear", **kwargs) -> T_Xarray:
         """Apply scipy.interpolate.interp1d along resampling dimension."""
         obj = self._drop_coords()
         (grouper,) = self.groupers
+        kwargs.setdefault("bounds_error", False)
         return obj.interp(
             coords={self._dim: grouper.full_index},
             assume_sorted=True,
             method=kind,
-            kwargs={"bounds_error": False},
+            kwargs=kwargs,
         )
 
 


Test patch:
diff --git a/xarray/tests/test_groupby.py b/xarray/tests/test_groupby.py
index a18b18f9..47cda064 100644
--- a/xarray/tests/test_groupby.py
+++ b/xarray/tests/test_groupby.py
@@ -2074,13 +2074,18 @@ class TestDataArrayResample:
             "slinear",
             "quadratic",
             "cubic",
+            "polynomial",
         ]
         for kind in kinds:
-            actual = array.resample(time="1h").interpolate(kind)
+            kwargs = {}
+            if kind == "polynomial":
+                kwargs["order"] = 1
+            actual = array.resample(time="1h").interpolate(kind, **kwargs)
+            # using interp1d, polynomial order is to set directly in kind using int
             f = interp1d(
                 np.arange(len(times)),
                 data,
-                kind=kind,
+                kind=kwargs["order"] if kind == "polynomial" else kind,
                 axis=-1,
                 bounds_error=True,
                 assume_sorted=True,
@@ -2147,14 +2152,19 @@ class TestDataArrayResample:
             "slinear",
             "quadratic",
             "cubic",
+            "polynomial",
         ]
         for kind in kinds:
-            actual = array.chunk(chunks).resample(time="1h").interpolate(kind)
+            kwargs = {}
+            if kind == "polynomial":
+                kwargs["order"] = 1
+            actual = array.chunk(chunks).resample(time="1h").interpolate(kind, **kwargs)
             actual = actual.compute()
+            # using interp1d, polynomial order is to set directly in kind using int
             f = interp1d(
                 np.arange(len(times)),
                 data,
-                kind=kind,
+                kind=kwargs["order"] if kind == "polynomial" else kind,
                 axis=-1,
                 bounds_error=True,
                 assume_sorted=True,