pyrosm icon indicating copy to clipboard operation
pyrosm copied to clipboard

OSM constructor not accepting pathlib Path objects

Open chrstnbwnkl opened this issue 3 years ago • 3 comments

Expected Behavior

Constructing an OSM object by passing the filepath as a pathlib.Path object instead of a string should work just as well.

Actual Behavior

validate_input_file() only accepts strings as filepaths, and an exception is raised:

Steps to Reproduce the Problem

from pyrosm import OSM
from pathlib import Path

some_osm_data = OSM(Path.cwd() / "some_osm.osm.pbf")

Specifications

  • Version: 0.6.1
  • Platform: MacOS 10.15.7
  • Python version: 3.9.7

chrstnbwnkl avatar Oct 28 '21 07:10 chrstnbwnkl

@chrstnbwnkl Thanks for suggesting this. Yes, this should be doable, although I think this is straightforward to handle by yourself. I.e. you can convert it to string or get the posix path and construct the filepath before passing it into the OSM object, i.e.:

from pyrosm import OSM
from pathlib import Path
import os

# As posix
OSM(os.path.join(Path.cwd().as_posix(), "some_osm.osm.pbf"))

# Converting to string
OSM(os.path.join(str(Path.cwd()), "some_osm.osm.pbf"))

Using path objects however does work with pandas/geopandas, so I guess it makes sense to include it here as well. 👍🏻

HTenkanen avatar Oct 28 '21 13:10 HTenkanen

Thanks for your time to check this (and for this very convenient library of course)! True, one could easily convert to string, so it's more convenience feature than anything else. I could draft a PR if you want!

chrstnbwnkl avatar Oct 29 '21 06:10 chrstnbwnkl

@chrstnbwnkl I would be very happy if you have the time to take a look at this and draft a PR! 🙂 👍🏻 The help is always welcome.

There is a section here where you can get some generic guidelines for contributing: https://pyrosm.readthedocs.io/en/latest/contributions.html

HTenkanen avatar Oct 29 '21 13:10 HTenkanen