Skip to content

API: Add support for PEP 519 #13823

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

Closed
AnkurDedania opened this issue Jul 27, 2016 · 3 comments · Fixed by #16301
Closed

API: Add support for PEP 519 #13823

AnkurDedania opened this issue Jul 27, 2016 · 3 comments · Fixed by #16301
Labels
Compat pandas objects compatability with Numpy or Python functions IO Data IO issues that don't fit into a more specific label

Comments

@AnkurDedania
Copy link

AnkurDedania commented Jul 27, 2016

File System Path Protocol has been accepted and implemented into Python 3.6, a backwards compatibility layer to support the introduced PEP 519 for python version < 3.6.

@shoyer
Copy link
Member

shoyer commented Jul 28, 2016

See this section for guidance relevant to pandas:
https://www.python.org/dev/peps/pep-0519/#backwards-compatibility

Libraries wishing to support path objects and a version of Python prior to Python 3.6 and the existence of os.fspath() can use the idiom of path.__fspath__() if hasattr(path, "__fspath__") else path .

@sinhrks sinhrks added Compat pandas objects compatability with Numpy or Python functions IO Data IO issues that don't fit into a more specific label labels Jul 28, 2016
AnkurDedania added a commit to AnkurDedania/pandas that referenced this issue Aug 31, 2016
@jreback jreback added this to the Next Major Release milestone Nov 17, 2016
AnkurDedania added a commit to AnkurDedania/pandas that referenced this issue Jan 6, 2017
@flying-sheep
Copy link
Contributor

flying-sheep commented Jan 12, 2017

so we add to compat/__init__.py (with extracted stuff from here)

def fspath(path):
	if isinstance(path, (str, bytes)):
 		return path
	
	if _PATHLIB_INTSTALLED and isinstance(path, pathlib.Path):
		path = text_type(path)  # 3.4/3.5 compat
	if _PYPATH_INSTALLED and isinstance(path, LocalPath):
		path = path.strpath
	else:
		path_type = type(path)
		try:
			path = path_type.__fspath__(path)
		except AttributeError:
			if hasattr(path_type, '__fspath__'):
				raise
			raise TypeError("expected str, bytes, py.path.LocalPath or os.PathLike object, not " + path_type.__name__) from None
	
	if isinstance(path, (str, bytes)):
		return path
	else:
		raise TypeError("expected __fspath__() to return str or bytes, not " + type(path).__name__)

@jreback
Copy link
Contributor

jreback commented Jan 12, 2017

there are already routines in io/common.py to handle pathlike things - they just need some updating

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat pandas objects compatability with Numpy or Python functions IO Data IO issues that don't fit into a more specific label
Projects
None yet
5 participants