question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ENH: Return Path in `data_path`?

See original GitHub issue

I saw @hoechenberger’s code here:

sample_dir = mne.datasets.sample.data_path()
raw_path = Path(sample_dir) / 'MEG' / 'sample' / 'sample_audvis_raw.fif'

And thought it was a bit sad that he had to Path(...) the data_path() result.

Since 1.0 is coming out, I think one small breaking change we could make would be to return Path instead of str in data_path.

  1. It actually matches the name of the function better
  2. It should help people modernize their code a bit with things like ...data_path() / 'subject'
  3. op.join still works and returns str

The big problem I see is:

  1. This fails:
    >>> Path('.') + '/foo'
    TypeError: unsupported operand type(s) for +: 'PosixPath' and 'str'
    
    The fix is pretty easy in this case, but it will break people’s code. The fix is pretty easy, but it’s still some pain…

We can probably get around this, though, with some class magic – we could subclass PosixPath and WindowsPath with support for a + operator, where if the other arg is a str then we cast to str and return op.join(path_str, other_str) (after stripping op.sep from the other_str).

Thoughts?

An alternative would be to do something like data_path(..., out='path'), but I’m not sure that’s much better than having people import from pathlib (though I guess it’s shorter). One advantage of that approach is that we could deprecate out='str' -> out='path' to give people time to change.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:26 (26 by maintainers)

github_iconTop GitHub Comments

2reactions
cbrnrcommented, Feb 10, 2022

I’m in favor of this change. With our usual deprecation cycle, I think it’s OK if people need to update their code. I don’t think you can expect to run an old analysis with the latest MNE-Python – for this use case, people can use older versions of MNE-Python. It’s not worth adding a lot of custom code just to keep the old + behavior around.

1reaction
cbrnrcommented, Feb 11, 2022

Yes sure, but why don’t you use the MNE version you used when you created the script? Ideally, you should already have an environment which preserves exact versions. But I know, that’s probably not what the average user does.

Anyhow, this discussion is drifting off a bit, so to come back to the original issue and proposed solution, I think we all agree that @larsoner’s suggestion both uses proper deprecation and in two versions will be gone without any leftovers for us to keep maintaining - so a perfect solution to me!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot Datapath Handling by UTD and URL-Filtering
This document describes how to troubleshoot UTD aka Snort and URL Filtering on IOS-XE SD-WAN edge (cEdge) routers.
Read more >
Question: how to take out the image path when using Pipeline ...
I use ops.FileReader to read training data & labels. But it seems the pipeline directly return the image content, I do not know...
Read more >
The Design of Low-Power Digital Datapath Circuits ENG
Abstract. This thesis outlines the design of the digital section of a transmit DAC, as well as the methods used for limiting the...
Read more >
How to get the directory that needs to be used in tessbase.init ...
So I am trying to figure out how to use TessBase, and I get an error at baseApi.init(dataPath, "eng") . The error I...
Read more >
draft-ietf-mpls-return-path-specified-lsp-ping-12 - IETF Datatracker
It can be used to detect data path failures in all MPLS LSPs, and was originally designed for unidirectional LSPs. LSP are increasingly...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found