From 732830742b52227bd635e51c7e7183eb34868443 Mon Sep 17 00:00:00 2001 From: Alan Velasco Date: Sat, 15 Jul 2017 22:39:50 -0500 Subject: [PATCH] Invert code to in datatype validation --- pandas/core/frame.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 38c89eb35a7f82..d6b98f7f415a10 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -2475,20 +2475,20 @@ def _ensure_valid_index(self, value): """ # GH5632, make sure that we are a Series convertible if not len(self.index): - if is_list_like(value): - try: - value = Series(value) - except: - raise ValueError('Cannot set a frame with no defined' - 'index and a value that cannot be ' - 'converted to a Series') - - self._data = self._data.reindex_axis(value.index.copy(), axis=1, - fill_value=np.nan) - else: + if not is_list_like(value): # GH16823, Raise an error due to loss of information raise ValueError('If using all scalar values, you must pass' ' an index') + try: + value = Series(value) + except: + raise ValueError('Cannot set a frame with no defined' + 'index and a value that cannot be ' + 'converted to a Series') + + self._data = self._data.reindex_axis(value.index.copy(), axis=1, + fill_value=np.nan) + def _set_item(self, key, value): """