Skip to content

Commit 9008ee5

Browse files
authored
Remove support for py.path objects in IO readers (#57091)
* CLN: Remove testing for py.path objects * Add whatsnew * Missed annotation * Add whatsnew
1 parent 8288b9b commit 9008ee5

File tree

18 files changed

+10
-181
lines changed

18 files changed

+10
-181
lines changed

doc/source/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,6 @@
460460
"dateutil": ("https://dateutil.readthedocs.io/en/latest/", None),
461461
"matplotlib": ("https://matplotlib.org/stable/", None),
462462
"numpy": ("https://numpy.org/doc/stable/", None),
463-
"py": ("https://pylib.readthedocs.io/en/latest/", None),
464463
"python": ("https://docs.python.org/3/", None),
465464
"scipy": ("https://docs.scipy.org/doc/scipy/", None),
466465
"pyarrow": ("https://arrow.apache.org/docs/", None),

doc/source/user_guide/io.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ Basic
6161
+++++
6262

6363
filepath_or_buffer : various
64-
Either a path to a file (a :class:`python:str`, :class:`python:pathlib.Path`,
65-
or :class:`py:py._path.local.LocalPath`), URL (including http, ftp, and S3
64+
Either a path to a file (a :class:`python:str`, :class:`python:pathlib.Path`)
65+
URL (including http, ftp, and S3
6666
locations), or any object with a ``read()`` method (such as an open file or
6767
:class:`~python:io.StringIO`).
6868
sep : str, defaults to ``','`` for :func:`read_csv`, ``\t`` for :func:`read_table`

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ See :ref:`install.dependencies` and :ref:`install.optional_dependencies` for mor
8484

8585
Other API changes
8686
^^^^^^^^^^^^^^^^^
87-
-
87+
- 3rd party ``py.path`` objects are no longer explicitly supported in IO methods. Use :py:class:`pathlib.Path` objects instead (:issue:`57091`)
8888
-
8989

9090
.. ---------------------------------------------------------------------------

pandas/_testing/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
Series,
3535
)
3636
from pandas._testing._io import (
37-
round_trip_localpath,
3837
round_trip_pathlib,
3938
round_trip_pickle,
4039
write_to_compressed,
@@ -609,7 +608,6 @@ def shares_memory(left, right) -> bool:
609608
"OBJECT_DTYPES",
610609
"raise_assert_detail",
611610
"raises_chained_assignment_error",
612-
"round_trip_localpath",
613611
"round_trip_pathlib",
614612
"round_trip_pickle",
615613
"setitem",

pandas/_testing/_io.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -89,35 +89,6 @@ def round_trip_pathlib(writer, reader, path: str | None = None):
8989
return obj
9090

9191

92-
def round_trip_localpath(writer, reader, path: str | None = None):
93-
"""
94-
Write an object to file specified by a py.path LocalPath and read it back.
95-
96-
Parameters
97-
----------
98-
writer : callable bound to pandas object
99-
IO writing function (e.g. DataFrame.to_csv )
100-
reader : callable
101-
IO reading function (e.g. pd.read_csv )
102-
path : str, default None
103-
The path where the object is written and then read.
104-
105-
Returns
106-
-------
107-
pandas object
108-
The original object that was serialized and then re-read.
109-
"""
110-
import pytest
111-
112-
LocalPath = pytest.importorskip("py.path").local
113-
if path is None:
114-
path = "___localpath___"
115-
with ensure_clean(path) as path:
116-
writer(LocalPath(path))
117-
obj = reader(LocalPath(path))
118-
return obj
119-
120-
12192
def write_to_compressed(compression, path, data, dest: str = "test") -> None:
12293
"""
12394
Write data to a compressed file.

pandas/io/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def _get_filepath_or_buffer(
318318
319319
Parameters
320320
----------
321-
filepath_or_buffer : a url, filepath (str, py.path.local or pathlib.Path),
321+
filepath_or_buffer : a url, filepath (str or pathlib.Path),
322322
or buffer
323323
{compression_options}
324324

pandas/io/excel/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1441,7 +1441,7 @@ class ExcelFile:
14411441
14421442
Parameters
14431443
----------
1444-
path_or_buffer : str, bytes, path object (pathlib.Path or py._path.local.LocalPath),
1444+
path_or_buffer : str, bytes, pathlib.Path,
14451445
A file-like object, xlrd workbook or openpyxl workbook.
14461446
If a string or path object, expected to be a path to a
14471447
.xls, .xlsx, .xlsb, .xlsm, .odf, .ods, or .odt file.

pandas/io/stata.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@
216216
Parameters
217217
----------
218218
path_or_buf : path (string), buffer or path object
219-
string, path object (pathlib.Path or py._path.local.LocalPath) or object
219+
string, pathlib.Path or object
220220
implementing a binary read() functions.
221221
{_statafile_processing_params1}
222222
{_statafile_processing_params2}
@@ -2258,7 +2258,7 @@ class StataWriter(StataParser):
22582258
Parameters
22592259
----------
22602260
fname : path (string), buffer or path object
2261-
string, path object (pathlib.Path or py._path.local.LocalPath) or
2261+
string, pathlib.Path or
22622262
object implementing a binary write() functions. If using a buffer
22632263
then the buffer will not be automatically closed after the file
22642264
is written.
@@ -3208,7 +3208,7 @@ class StataWriter117(StataWriter):
32083208
Parameters
32093209
----------
32103210
fname : path (string), buffer or path object
3211-
string, path object (pathlib.Path or py._path.local.LocalPath) or
3211+
string, pathlib.Path or
32123212
object implementing a binary write() functions. If using a buffer
32133213
then the buffer will not be automatically closed after the file
32143214
is written.
@@ -3594,7 +3594,7 @@ class StataWriterUTF8(StataWriter117):
35943594
Parameters
35953595
----------
35963596
fname : path (string), buffer or path object
3597-
string, path object (pathlib.Path or py._path.local.LocalPath) or
3597+
string, pathlib.Path or
35983598
object implementing a binary write() functions. If using a buffer
35993599
then the buffer will not be automatically closed after the file
36003600
is written.

pandas/tests/io/excel/test_readers.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -966,19 +966,6 @@ def test_read_from_pathlib_path(self, read_ext):
966966

967967
tm.assert_frame_equal(expected, actual)
968968

969-
@td.skip_if_no("py.path")
970-
def test_read_from_py_localpath(self, read_ext):
971-
# GH12655
972-
from py.path import local as LocalPath
973-
974-
str_path = os.path.join("test1" + read_ext)
975-
expected = pd.read_excel(str_path, sheet_name="Sheet1", index_col=0)
976-
977-
path_obj = LocalPath().join("test1" + read_ext)
978-
actual = pd.read_excel(path_obj, sheet_name="Sheet1", index_col=0)
979-
980-
tm.assert_frame_equal(expected, actual)
981-
982969
def test_close_from_py_localpath(self, read_ext):
983970
# GH31467
984971
str_path = os.path.join("test1" + read_ext)

pandas/tests/io/excel/test_writers.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,18 +1319,6 @@ def test_path_path_lib(self, engine, ext):
13191319
result = tm.round_trip_pathlib(writer, reader, path=f"foo{ext}")
13201320
tm.assert_frame_equal(result, df)
13211321

1322-
def test_path_local_path(self, engine, ext):
1323-
df = DataFrame(
1324-
1.1 * np.arange(120).reshape((30, 4)),
1325-
columns=Index(list("ABCD")),
1326-
index=Index([f"i-{i}" for i in range(30)]),
1327-
)
1328-
writer = partial(df.to_excel, engine=engine)
1329-
1330-
reader = partial(pd.read_excel, index_col=0)
1331-
result = tm.round_trip_localpath(writer, reader, path=f"foo{ext}")
1332-
tm.assert_frame_equal(result, df)
1333-
13341322
def test_merged_cell_custom_objects(self, path):
13351323
# see GH-27006
13361324
mi = MultiIndex.from_tuples(

0 commit comments

Comments
 (0)