Skip to content

Allow passing pathlib.PosixPath to the function read_from_text_file()#787

Open
xingularity wants to merge 4 commits into
solvcon:masterfrom
xingularity:hotfix/handle-posix-path-issue-786
Open

Allow passing pathlib.PosixPath to the function read_from_text_file()#787
xingularity wants to merge 4 commits into
solvcon:masterfrom
xingularity:hotfix/handle-posix-path-issue-786

Conversation

@xingularity
Copy link
Copy Markdown

@xingularity xingularity commented May 17, 2026

Modified if statement in modmesh/track/dataframe. This is to handle file name as a PosixPath instance.

This is for issue #786.

Modified if statement to handle PosixPath instance file name in the same way with
handling string file name.
@xingularity xingularity marked this pull request as draft May 21, 2026 07:04
Changes made in this commit:
1. Cross-platform type check with os.PathLike
2. Combine isinstance calls with isinstance(fname, (str, os.PathLike))
3. Added tests for different types of path
4. Tighten error type by using FileNotFoundErrorn not Exceptions
@xingularity xingularity force-pushed the hotfix/handle-posix-path-issue-786 branch from a8ab00b to 9930fd0 Compare May 23, 2026 05:01
@xingularity xingularity marked this pull request as ready for review May 23, 2026 09:35
@tigercosmos
Copy link
Copy Markdown
Collaborator

Sorry maybe I didn't fully understand the test cases. I wonder are the test cases be able to catch the errors that happens in #786?

@xingularity
Copy link
Copy Markdown
Author

xingularity commented May 23, 2026

Sorry maybe I didn't fully understand the test cases. I wonder are the test cases be able to catch the errors that happens in #786?

Yes, test case test_read_from_text_file_accepts_pathlib_path is for it. The pathlib.Path function call is going to generate a pathlib.PosixPath instance under linux.

@yungyuc yungyuc changed the title Fixed issue-786 Allow passing pathlib.PosixPath to the function read_from_text_file() May 23, 2026
@yungyuc yungyuc added the array Multi-dimensional array implementation label May 23, 2026
@yungyuc yungyuc moved this to In Progress in tabular data processing May 23, 2026
@yungyuc
Copy link
Copy Markdown
Member

yungyuc commented May 23, 2026

I changed the subject to be more informative.

Copy link
Copy Markdown
Member

@yungyuc yungyuc left a comment

Choose a reason for hiding this comment

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

Please leave inline annotations in the PR. The fix itself is simple, but the unit tests are not trivial. Also leave a global comment to request for review.

See the PR protocol in issue #811 .

Added comment to `test_read_from_text_file_accepts_pathlib_path`
to illustrate the background and purpose of this test case.
@xingularity
Copy link
Copy Markdown
Author

Please leave inline annotations in the PR. The fix itself is simple, but the unit tests are not trivial. Also leave a global comment to request for review.

See the PR protocol in issue #811 .

@yungyuc and @tigercosmos The comment has been added, you can review now.

Copy link
Copy Markdown
Member

@yungyuc yungyuc left a comment

Choose a reason for hiding this comment

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

  • Use inline annotation for discussions in the PR, not code comments.
  • Also check for error messages, not just the exception type.

finally:
os.unlink(path)

# Theis test is for a bug reported in issue #786:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator

@tigercosmos tigercosmos May 24, 2026

Choose a reason for hiding this comment

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

Nitpick: there is a typo Theis.

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):
Copy link
Copy Markdown
Member

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.

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):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also check for error messages, not just the exception type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

array Multi-dimensional array implementation

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants