-
Notifications
You must be signed in to change notification settings - Fork 61
Allow passing pathlib.PosixPath to the function read_from_text_file()
#787
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,9 @@ | |
| # POSSIBILITY OF SUCH DAMAGE. | ||
|
|
||
| import io | ||
| import os | ||
| import pathlib | ||
| import tempfile | ||
| import unittest | ||
|
|
||
| import numpy as np | ||
|
|
@@ -163,3 +166,45 @@ def test_dataframe_sort(self): | |
| col_data = reordered_tsdf['DELTA_VEL[1]'] | ||
| nd_arr = np.genfromtxt(io.StringIO(self.dlc_data), delimiter=',')[1:] | ||
| self.assertEqual(list(col_data), list(nd_arr[:, 1])) | ||
|
|
||
| def test_read_from_text_file_accepts_str_path(self): | ||
| tsdf = dataframe.DataFrame() | ||
| with tempfile.NamedTemporaryFile( | ||
| mode='w', suffix='.csv', delete=False, | ||
| ) as fh: | ||
| fh.write(self.dlc_data) | ||
| path = fh.name | ||
| try: | ||
| tsdf.read_from_text_file(path) | ||
| self.assertEqual(tsdf._columns, self.col_sol) | ||
| self.assertEqual(tsdf._index_name, 'EPOCH') | ||
| finally: | ||
| os.unlink(path) | ||
|
|
||
| # Theis test is for a bug reported in issue #786: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that you misunderstood what we meant by inline annotations. In #787 (review), "inline annotations in the PR" is like the inline comment I am leaving here. It is not code remarks/comments. Please remove the unnecessary code comments and turn it into a PR inline annotation.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: there is a typo |
||
| # https://github.com/solvcon/modmesh/issues/786 | ||
| # Issue #786: If user uses time series dataframe under Linux, | ||
| # it is likely to be given a `pathlib.PosixPath` instance to | ||
| # indicate the path to text file. This test is to make sure | ||
| # dataframe support a path which is from `pathlib` | ||
| def test_read_from_text_file_accepts_pathlib_path(self): | ||
| tsdf = dataframe.DataFrame() | ||
| with tempfile.NamedTemporaryFile( | ||
| mode='w', suffix='.csv', delete=False, | ||
| ) as fh: | ||
| fh.write(self.dlc_data) | ||
| path = pathlib.Path(fh.name) | ||
| try: | ||
| tsdf.read_from_text_file(path) | ||
| self.assertEqual(tsdf._columns, self.col_sol) | ||
| self.assertEqual(tsdf._index_name, 'EPOCH') | ||
| finally: | ||
| path.unlink() | ||
|
|
||
| def test_read_from_text_file_missing_raises_filenotfound(self): | ||
| tsdf = dataframe.DataFrame() | ||
| missing = pathlib.Path(tempfile.gettempdir()) / 'no_such_file.csv' | ||
| with self.assertRaises(FileNotFoundError): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also check for error messages, not just the exception type. |
||
| tsdf.read_from_text_file(missing) | ||
|
|
||
| # vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4 tw=79: | ||
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 does not look like related to the fix. Please share with us why do you want to include it.