-
Notifications
You must be signed in to change notification settings - Fork 219
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
Add support for passing pathlib.Path objects as filenames #1382
Add support for passing pathlib.Path objects as filenames #1382
Conversation
💖 Thanks for opening this pull request! 💖 Please make sure you read our contributing guidelines and abide by our code of conduct. A few things to keep in mind:
|
Hmm, supporting pathlib.Path might not be as simple as I thought. We'll need to convert the Line 106 in 60a92b3
yield str(arg) perhaps?
|
I'm sorry for the delay! I've examined the I've pushed my changes to my branch already, and will keep an eye on the tests in case something fails again. Thanks for your help! |
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'm sorry for the delay! I've examined the
virtualfile_from_data
function and modified the conditional statement to castdata
tostr
in presence of"file"
data kind, instead of modifying thedummy_context
function.
Nice one, that's a much better solution! Will see if the tests pass on all platforms (Linux/macOS/Windows).
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.
Thanks @aitorres, looks good. I'll merge in 24hrs unless any of the other devs have something to add.
Edit: Please resolve #1382 (comment) before we can proceed.
pygmt/helpers/utils.py
Outdated
@@ -66,7 +71,7 @@ def data_kind(data, x=None, y=None, z=None): | |||
if data is None and (x is None or y is None): | |||
raise GMTInvalidInput("Must provided both x and y.") | |||
|
|||
if isinstance(data, str): | |||
if isinstance(data, (str, pathlib.Path)): |
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 will happen if people use pathlib.PurePath
or path.PurePosixPath
?
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.
The answer at https://stackoverflow.com/questions/58647584/how-to-test-if-object-is-a-pathlib-path/58966089#58966089 suggests using isinstance(pathlib.PurePath)
. @aitorres, could you perhaps see if this works?
if isinstance(data, (str, pathlib.Path)): | |
if isinstance(data, (str, pathlib.PurePath)): |
Also, it might be a good idea to test that PureWindowsPath
and PurePosixPath
objects work on Windows and macOS/Linux respectively. Let us know if you're able to update the unit test to do that. If not, we can also just ignore it.
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.
Gentle ping @aitorres to see if you're still available to finish up this PR! If not, we can get one of the maintainers to finish this up in the next week or so.
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.
Really sorry for the delay! I've just added and pushed the changes to use PurePath
, and added two tests that specifically use PureWindowsPath
and PurePosixPath
.
Ping @aitorres to finalize this PR if you have time. Otherwise, I'll take over this PR and make edits to this branch. |
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.
Should be ok to merge after tests all pass, but prefer to have a second approval.
pathlib.Path
into pygmt modules
🎉🎉🎉 Congrats on merging your first pull request and welcome to the team! 🎉🎉🎉 Please open a new pull request to add yourself to the |
…pingTools#1382) Co-authored-by: Dongdong Tian <seisman.info@gmail.com> Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
Description of proposed changes
This PR addresses and fixes issue #1381. By adding support to
pathlib.Path
values that represent file paths to thedata_kind
helper function, it can be used interchangeably with file name strings onpygmt
modules.Fixes #1381
Reminders
make format
andmake check
to make sure the code follows the style guide.doc/api/index.rst
.Slash Commands
You can write slash commands (
/command
) in the first line of a comment to performspecific operations. Supported slash commands are:
/format
: automatically format and lint the code/test-gmt-dev
: run full tests on the latest GMT development version