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

DEPR: squeeze() argument in read_csv/read_table #43242

Closed
lithomas1 opened this issue Aug 27, 2021 · 7 comments · Fixed by #43427
Closed

DEPR: squeeze() argument in read_csv/read_table #43242

lithomas1 opened this issue Aug 27, 2021 · 7 comments · Fixed by #43427
Assignees
Labels
Deprecate Functionality to remove in pandas IO CSV read_csv, to_csv
Milestone

Comments

@lithomas1
Copy link
Member

I'm pretty sure you can do this directly with a .squeeze() afterwards.
The code does look pretty similar
squeeze()

axis = range(self._AXIS_LEN) if axis is None else (self._get_axis_number(axis),)
return self.iloc[
tuple(
0 if i in axis and len(a) == 1 else slice(None)
for i, a in enumerate(self.axes)
)
]

vs

read_csv(squeeze=True)

if self.squeeze and len(df.columns) == 1:
return df[df.columns[0]].copy()

@lithomas1 lithomas1 added Deprecate Functionality to remove in pandas IO CSV read_csv, to_csv Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 27, 2021
@phofl
Copy link
Member

phofl commented Aug 27, 2021

This is not completly the same, see

df = pd.DataFrame({"a": [1]})

df.squeeze()
df["a"]

First returns a scalar, the second a series.

But I think it is worth discussing this nevertheless.

@jreback
Copy link
Contributor

jreback commented Aug 27, 2021

iirc there is another issue about deprecating squeeze but in any event +1 to do it (i thought we did this long ago)

@phofl
Copy link
Member

phofl commented Aug 27, 2021

We deprecated squeeze in groupby early last year, maybe this?

@lithomas1
Copy link
Member Author

lithomas1 commented Aug 27, 2021

I think the equivalent is squeeze("columns")

>>> import pandas as pd
>>> a = pd.DataFrame({"a": [1]})
>>> a.squeeze("columns")
0    1
Name: a, dtype: int64

@phofl
Copy link
Member

phofl commented Aug 27, 2021

Good point, thx

@lithomas1 lithomas1 removed the Needs Triage Issue that has not been reviewed by a pandas team member label Aug 27, 2021
@lithomas1 lithomas1 self-assigned this Aug 27, 2021
@lithomas1 lithomas1 added this to the Contributions Welcome milestone Aug 27, 2021
@lithomas1
Copy link
Member Author

This should also be deprecated in read_excel, and ExcelFile.parse too.
cc @rhshadrach

@rhshadrach
Copy link
Member

+1 on deprecating squeeze for read_excel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecate Functionality to remove in pandas IO CSV read_csv, to_csv
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants