Skip to content
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

Handle paths specified using Path objects #332

Open
aarchiba opened this issue Jan 31, 2023 · 2 comments
Open

Handle paths specified using Path objects #332

aarchiba opened this issue Jan 31, 2023 · 2 comments
Labels

Comments

@aarchiba
Copy link
Contributor

Python has had for a while dedicated objects for working with paths (allowing things like if parfile.exists(): or timfile = parfile.with_suffix("tim")). Currently at least the Pulsar factory cannot accept these:

parfile = Path("file.par")
timfile = Path("file.tim")
Pulsar(parfile, timfile)

yields

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[9], line 1
----> 1 psr = Pulsar((parfile), (timfile))

File ~/software/miniconda3/envs/enterprise-development/lib/python3.10/site-packages/enterprise/pulsar.py:665, in Pulsar(*args, **kwargs)
    662         os.chdir(cwd)
    663         return Tempo2Pulsar(t2pulsar, sort=sort, drop_t2pulsar=drop_t2pulsar, planets=planets)
--> 665 raise ValueError("Unknown arguments {}".format(args))

ValueError: Unknown arguments (PosixPath('../enterprise_files/J0023+0923.nb.par'), PosixPath('../enterprise_files/J0023+0923.nb.tim'))

The user must apply str to each before passing them to Pulsar(). It should work fine with these objects.

@aarchiba
Copy link
Contributor Author

aarchiba commented Feb 7, 2023

I think this could probably be fixed by broadening the check for strings in the Pulsar() function, but I'm hesitant to add any complication to the already complicated and unusual way it handles its arguments. Would it be okay to simplify the function? Specifically, accept exactly two positional arguments, with a preferred order but the ability to swap them if they are the wrong way around (optionally with a warning), plus some named keyword arguments, plus a **kwargs to be passed in to the eventual constructor?

I can put together a demo PR, though I can't run the test suite without segfaults (#339).

@paulthebaker
Copy link
Member

I can't run the test suite without segfaults

Given what we've seen with the test segfaults, I would assume you could run make lint and pytest tests/test_pulsar.py successfully, even if make test fails. After those run locally, we can count on the CI PR tests to catch anything else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants