-
Notifications
You must be signed in to change notification settings - Fork 6
fix #291 + #293 + #313 : Session.save (0D arrays + Excel + overwrite file by default) #312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
larray/io/session.py
Outdated
@@ -114,6 +115,10 @@ def dump_arrays(self, key_values, *args, **kwargs): | |||
display = kwargs.pop('display', False) | |||
self._open_for_write() | |||
for key, value in key_values: | |||
if isinstance(value, ABCLArray) and value.ndim == 0: | |||
if display: | |||
print('Cannot dump {}. Dumping 0D arrays is not supported currently.'.format(key)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currently not supported
Did you run pytest after commit 1286d67 ? Because you removed the larray method from Range class but not the call from getattr a few lines below. |
Oops, nice catch! I thought I did run the tests. Maybe I will need to add another one. |
@@ -57,3 +57,9 @@ Fixes | |||
* fixed the array() method on excel.Sheet returning float labels when int labels are expected. | |||
|
|||
* fixed getting float data instead of int when converting an Excel Sheet or Range to an larray or numpy array. | |||
|
|||
* fixed crash of Session.save method when it contains a 0D array. | |||
0D arrays are skiped when saving a session (closes issue:`291`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are now skipped
0D arrays are skiped when saving a session (closes issue:`291`). | ||
|
||
* fixed crash of Session.save method when trying to save a session in an Excel that does not exist. | ||
A new Excel file is created if it does not exist yet (closes issue:`313`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't crash a too strong word for something which failed with a relatively nice error message? I would write something like:
fixed Session.save and Session.to_excel failing to create new Excel files (it only worked if the file already existed). Closes ...
larray/tests/test_session.py
Outdated
@@ -161,6 +162,8 @@ def test_xlsx_pandas_io(self): | |||
@pytest.mark.skipif(xw is None, reason="xlwings is not available") | |||
def test_xlsx_xlwings_io(self): | |||
fpath = abspath('test_session_xw.xlsx') | |||
if os.path.isfile(fpath): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we also need an explicit test where the file already existed.
Do you want me to include issue #293 in this PR or another? |
as you prefer. |
Not sure for issue #293 |
larray/tests/test_session.py
Outdated
s.save(fpath, engine='pandas_excel', overwrite=False) | ||
s.load(fpath, engine='pandas_excel') | ||
self.assertEqual(list(s.keys()), ['e', 'g', 'f']) | ||
#assert_array_nan_equal(s['e'], self.e2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this line commented?
larray/tests/test_session.py
Outdated
@@ -161,12 +178,21 @@ def test_xlsx_pandas_io(self): | |||
@pytest.mark.skipif(xw is None, reason="xlwings is not available") | |||
def test_xlsx_xlwings_io(self): | |||
fpath = abspath('test_session_xw.xlsx') | |||
# test save when Excel does not exist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excel file
larray/tests/test_session.py
Outdated
# update an array (overwrite=False) | ||
s['e'] = self.e2 | ||
s.save(fpath, overwrite=False) | ||
s.load(fpath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test (and all similar tests below) is a bit misleading. It will pass even if the file is completely wiped out, because the arrays still exist in the session s and s.load(path) does not clear the session. Maybe we want to change that last point, but that would be for another PR/release.
larray/core/session.py
Outdated
Dump using `engine`. Defaults to 'auto' (use default engine for | ||
the format guessed from the file extension). | ||
overwrite: bool, optional | ||
Whether or not to overwrite an existing file, if any. Only for non CSV files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignored for CSV files?
@@ -18,6 +18,8 @@ | |||
a0 0 1 | |||
a1 2 3 | |||
|
|||
* added new boolean argument 'overwrite' to Session.save method. If True, overwrite existing file if any. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- we should also mention other "save" methods: to_excel, etc. which are also impacted by this change.
- I don't think it is clear enough that the default behaviour changed from overwrite=False to overwrite=True
@@ -164,7 +169,7 @@ def list(self): | |||
|
|||
def _read_array(self, key, *args, **kwargs): | |||
df = self.handle.parse(key, *args, **kwargs) | |||
return df_aslarray(df) | |||
return df_aslarray(df, raw=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the relation with the rest? Is this an extra fix? If so it needs a test & changelog :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an extra fix for an issue discovered when I tried to update the IO tests for Session ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, this is not entirely correct. We should use: raw=index_col is None. But I admit the chance users ever hit this case is close to zero :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forgot changelog, sorry.
…file if it does not exist.
…hod (defaults to True).
…l to df_aslarray function
LGTM |
until #153 is fixed.