Skip to content

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

Merged
merged 11 commits into from
Jun 14, 2017

Conversation

alixdamman
Copy link
Collaborator

until #153 is fixed.

@alixdamman alixdamman changed the title fix #291 : excluding 0D arrays when saving a session. fix #291 + #313 : excluding 0D arrays when saving a session + Session.save create new Excel file if not exist Jun 13, 2017
Copy link
Contributor

@gdementen gdementen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a test for #313 and changelog entries for both. A test for #291 would be nice but it's up to you given that it will be obsolete when we fix #153.

@@ -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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently not supported

@alixdamman
Copy link
Collaborator Author

alixdamman commented Jun 13, 2017

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.

@gdementen
Copy link
Contributor

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`).
Copy link
Contributor

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`).
Copy link
Contributor

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 ...

@@ -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):
Copy link
Contributor

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.

@alixdamman
Copy link
Collaborator Author

Do you want me to include issue #293 in this PR or another?

@gdementen
Copy link
Contributor

as you prefer.

@alixdamman alixdamman changed the title fix #291 + #313 : excluding 0D arrays when saving a session + Session.save create new Excel file if not exist fix #291 + #293 + #313 : Session.save (0D arrays + Excel + overwrite file by default) Jun 14, 2017
@alixdamman
Copy link
Collaborator Author

Not sure for issue #293

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)
Copy link
Contributor

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?

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excel file

# update an array (overwrite=False)
s['e'] = self.e2
s.save(fpath, overwrite=False)
s.load(fpath)
Copy link
Contributor

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.

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.
Copy link
Contributor

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.
Copy link
Contributor

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)
Copy link
Contributor

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 :)

Copy link
Collaborator Author

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 ;)

Copy link
Contributor

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 :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgot changelog, sorry.

@gdementen
Copy link
Contributor

LGTM

@gdementen gdementen merged commit 5962207 into larray-project:master Jun 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants