fix(pandas): only set columns when `apply_column_names` is set
Fixes
@@ -595,12 +595,17 @@ class PandasDataFrame(
# if self._enforce_dtype:
# raise exception_cls(msg) from None
- if self._columns is not None and len(self._columns) != dataframe.shape[1]:
- msg = "length of 'columns' (%d) does not match the # of columns of incoming data."
if self._apply_column_names:
- raise BadInput(msg % len(self._columns)) from None
- else:
- logger.debug(msg, len(self._columns))
+ if not self._columns:
+ raise BadInput(
+ "When apply_column_names is set, you must provide columns."
+ )
+
+ if len(self._columns) != dataframe.shape[1]:
+ raise BadInput(
+ f"length of 'columns' ({len(self._columns)}) does not match the # of columns of incoming data ({dataframe.shape[1]})."
+ ) from None
+
dataframe.columns = pd.Index(self._columns)
# TODO: convert from wide to long format (melt())
