Skip to content

Commit f8b9ce7

Browse files
jbrockmendeljreback
authored andcommitted
REF: change parameter name fname -> path (#30338)
1 parent 5b25df2 commit f8b9ce7

File tree

5 files changed

+48
-24
lines changed

5 files changed

+48
-24
lines changed

doc/source/user_guide/io.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -4763,10 +4763,10 @@ Parquet supports partitioning of data based on the values of one or more columns
47634763
.. ipython:: python
47644764
47654765
df = pd.DataFrame({'a': [0, 0, 1, 1], 'b': [0, 1, 0, 1]})
4766-
df.to_parquet(fname='test', engine='pyarrow',
4766+
df.to_parquet(path='test', engine='pyarrow',
47674767
partition_cols=['a'], compression=None)
47684768
4769-
The `fname` specifies the parent directory to which data will be saved.
4769+
The `path` specifies the parent directory to which data will be saved.
47704770
The `partition_cols` are the column names by which the dataset will be partitioned.
47714771
Columns are partitioned in the order they are given. The partition splits are
47724772
determined by the unique values in the partition columns.

doc/source/whatsnew/v1.0.0.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,8 @@ Deprecations
502502
- :func:`pandas.json_normalize` is now exposed in the top-level namespace.
503503
Usage of ``json_normalize`` as ``pandas.io.json.json_normalize`` is now deprecated and
504504
it is recommended to use ``json_normalize`` as :func:`pandas.json_normalize` instead (:issue:`27586`).
505-
-
505+
- :meth:`DataFrame.to_stata`, :meth:`DataFrame.to_feather`, and :meth:`DataFrame.to_parquet` argument "fname" is deprecated, use "path" instead (:issue:`23574`)
506+
506507

507508
.. _whatsnew_1000.prior_deprecations:
508509

pandas/core/frame.py

+26-11
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@
3737

3838
from pandas._libs import algos as libalgos, lib
3939
from pandas.compat.numpy import function as nv
40-
from pandas.util._decorators import Appender, Substitution, rewrite_axis_style_signature
40+
from pandas.util._decorators import (
41+
Appender,
42+
Substitution,
43+
deprecate_kwarg,
44+
rewrite_axis_style_signature,
45+
)
4146
from pandas.util._validators import (
4247
validate_axis_style_args,
4348
validate_bool_kwarg,
@@ -1829,9 +1834,10 @@ def _from_arrays(cls, arrays, columns, index, dtype=None):
18291834
mgr = arrays_to_mgr(arrays, columns, index, columns, dtype=dtype)
18301835
return cls(mgr)
18311836

1837+
@deprecate_kwarg(old_arg_name="fname", new_arg_name="path")
18321838
def to_stata(
18331839
self,
1834-
fname,
1840+
path,
18351841
convert_dates=None,
18361842
write_index=True,
18371843
byteorder=None,
@@ -1849,11 +1855,16 @@ def to_stata(
18491855
18501856
Parameters
18511857
----------
1852-
fname : str, buffer or path object
1858+
path : str, buffer or path object
18531859
String, path object (pathlib.Path or py._path.local.LocalPath) or
18541860
object implementing a binary write() function. If using a buffer
18551861
then the buffer will not be automatically closed after the file
18561862
data has been written.
1863+
1864+
.. versionchanged:: 1.0.0
1865+
1866+
Previously this was "fname"
1867+
18571868
convert_dates : dict
18581869
Dictionary mapping columns containing datetime types to stata
18591870
internal format to use when writing the dates. Options are 'tc',
@@ -1927,7 +1938,7 @@ def to_stata(
19271938
kwargs["convert_strl"] = convert_strl
19281939

19291940
writer = statawriter(
1930-
fname,
1941+
path,
19311942
self,
19321943
convert_dates=convert_dates,
19331944
byteorder=byteorder,
@@ -1939,22 +1950,24 @@ def to_stata(
19391950
)
19401951
writer.write_file()
19411952

1942-
def to_feather(self, fname):
1953+
@deprecate_kwarg(old_arg_name="fname", new_arg_name="path")
1954+
def to_feather(self, path):
19431955
"""
19441956
Write out the binary feather-format for DataFrames.
19451957
19461958
Parameters
19471959
----------
1948-
fname : str
1960+
path : str
19491961
String file path.
19501962
"""
19511963
from pandas.io.feather_format import to_feather
19521964

1953-
to_feather(self, fname)
1965+
to_feather(self, path)
19541966

1967+
@deprecate_kwarg(old_arg_name="fname", new_arg_name="path")
19551968
def to_parquet(
19561969
self,
1957-
fname,
1970+
path,
19581971
engine="auto",
19591972
compression="snappy",
19601973
index=None,
@@ -1973,11 +1986,13 @@ def to_parquet(
19731986
19741987
Parameters
19751988
----------
1976-
fname : str
1989+
path : str
19771990
File path or Root Directory path. Will be used as Root Directory
19781991
path while writing a partitioned dataset.
19791992
1980-
.. versionchanged:: 0.24.0
1993+
.. versionchanged:: 1.0.0
1994+
1995+
Previously this was "fname"
19811996
19821997
engine : {'auto', 'pyarrow', 'fastparquet'}, default 'auto'
19831998
Parquet library to use. If 'auto', then the option
@@ -2034,7 +2049,7 @@ def to_parquet(
20342049

20352050
to_parquet(
20362051
self,
2037-
fname,
2052+
path,
20382053
engine,
20392054
compression=compression,
20402055
index=index,

pandas/io/feather_format.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ def to_feather(df: DataFrame, path):
3434
# raise on anything else as we don't serialize the index
3535

3636
if not isinstance(df.index, Int64Index):
37+
typ = type(df.index)
3738
raise ValueError(
38-
"feather does not support serializing {} "
39+
f"feather does not support serializing {typ} "
3940
"for the index; you can .reset_index() "
40-
"to make the index into column(s)".format(type(df.index))
41+
"to make the index into column(s)"
4142
)
4243

4344
if not df.index.equals(RangeIndex.from_range(range(len(df)))):
@@ -63,7 +64,7 @@ def to_feather(df: DataFrame, path):
6364
feather.write_feather(df, path)
6465

6566

66-
def read_feather(path, columns=None, use_threads=True):
67+
def read_feather(path, columns=None, use_threads: bool = True):
6768
"""
6869
Load a feather-format object from the file path.
6970

pandas/io/parquet.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def get_engine(engine: str) -> "BaseImpl":
4646

4747
class BaseImpl:
4848
@staticmethod
49-
def validate_dataframe(df):
49+
def validate_dataframe(df: DataFrame):
5050

5151
if not isinstance(df, DataFrame):
5252
raise ValueError("to_parquet only supports IO with DataFrames")
@@ -62,7 +62,7 @@ def validate_dataframe(df):
6262
if not valid_names:
6363
raise ValueError("Index level names must be strings")
6464

65-
def write(self, df, path, compression, **kwargs):
65+
def write(self, df: DataFrame, path, compression, **kwargs):
6666
raise AbstractMethodError(self)
6767

6868
def read(self, path, columns=None, **kwargs):
@@ -80,7 +80,7 @@ def __init__(self):
8080

8181
def write(
8282
self,
83-
df,
83+
df: DataFrame,
8484
path,
8585
compression="snappy",
8686
coerce_timestamps="ms",
@@ -137,7 +137,13 @@ def __init__(self):
137137
self.api = fastparquet
138138

139139
def write(
140-
self, df, path, compression="snappy", index=None, partition_cols=None, **kwargs
140+
self,
141+
df: DataFrame,
142+
path,
143+
compression="snappy",
144+
index=None,
145+
partition_cols=None,
146+
**kwargs,
141147
):
142148
self.validate_dataframe(df)
143149
# thriftpy/protocol/compact.py:339:
@@ -196,9 +202,9 @@ def read(self, path, columns=None, **kwargs):
196202

197203

198204
def to_parquet(
199-
df,
205+
df: DataFrame,
200206
path,
201-
engine="auto",
207+
engine: str = "auto",
202208
compression="snappy",
203209
index: Optional[bool] = None,
204210
partition_cols=None,
@@ -209,6 +215,7 @@ def to_parquet(
209215
210216
Parameters
211217
----------
218+
df : DataFrame
212219
path : str
213220
File path or Root Directory path. Will be used as Root Directory path
214221
while writing a partitioned dataset.
@@ -255,7 +262,7 @@ def to_parquet(
255262
)
256263

257264

258-
def read_parquet(path, engine="auto", columns=None, **kwargs):
265+
def read_parquet(path, engine: str = "auto", columns=None, **kwargs):
259266
"""
260267
Load a parquet object from the file path, returning a DataFrame.
261268

0 commit comments

Comments
 (0)