Skip to content

REGR: ValueError raised when both prefix and names are set to None #42690

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

Merged
merged 11 commits into from
Jul 30, 2021

Conversation

lithomas1
Copy link
Member

@lithomas1 lithomas1 changed the title Prefix names raises REGR: ValueError raised when both prefix and names are set to None Jul 23, 2021
@lithomas1 lithomas1 added IO CSV read_csv, to_csv Regression Functionality that used to work in a prior pandas version labels Jul 23, 2021
@lithomas1 lithomas1 added this to the 1.3.1 milestone Jul 23, 2021
Copy link
Member

@phofl phofl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation is good, but we are now inconsistent with sep and delimiter, which still raises if None and not lib.no_default is given.

I think we discussed this a year ago or something like that to use lib.no_default?

@@ -505,11 +505,11 @@ def read_csv(
delimiter=None,
# Column and Index Locations and Names
header="infer",
names=lib.no_default,
names=None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would rather leave these as no_default and fix the check itself

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only have one way of representing none/null, so we should either use None or lib.no_default, not have both. I think I prefer None given that lib.no_default is private.

If we want to keep using lib.no_default then, we should probably close OP as wontfix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no i think you can simply revert these back to lib.no_default and fix the check on L1305. the point is that these are still invalid if actual None is passed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure iiuc, but pd.read_csv(xxx, names=None, prefix=None) should fail?

Copy link
Member Author

@lithomas1 lithomas1 Jul 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should work. It worked at least in previous versions. If None is passed for both, it would just get the column names from header, or use the "0,1,2,..." naming scheme, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right i agree this should work, but i also think you can leave the no_default and it will work (just odify the comparison)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thx for clarifying, update incoming soon.

@@ -1302,11 +1302,11 @@ def _refine_defaults_read(
if delimiter and (sep is not lib.no_default):
raise ValueError("Specified a sep and a delimiter; you can only specify one.")

if names is not lib.no_default and prefix is not lib.no_default:
if names is not None and prefix is not None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g here

@simonjayhawkins simonjayhawkins mentioned this pull request Jul 24, 2021
@lithomas1 lithomas1 removed this from the 1.3.1 milestone Jul 24, 2021
@simonjayhawkins simonjayhawkins added this to the 1.3.2 milestone Jul 26, 2021
@pep8speaks
Copy link

pep8speaks commented Jul 29, 2021

Hello @lithomas1! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-07-29 23:28:33 UTC

@@ -1302,7 +1302,8 @@ def _refine_defaults_read(
if delimiter and (sep is not lib.no_default):
raise ValueError("Specified a sep and a delimiter; you can only specify one.")

if names is not lib.no_default and prefix is not lib.no_default:
allowed_names_prefix = {None, lib.no_default}
if names not in allowed_names_prefix and prefix not in allowed_names_prefix:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work with lists

@jreback
Copy link
Contributor

jreback commented Jul 29, 2021

lgtm. @phofl if you can give a once over.

Copy link
Member

@phofl phofl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

meeseeksmachine pushed a commit to meeseeksmachine/pandas that referenced this pull request Jul 30, 2021
simonjayhawkins pushed a commit that referenced this pull request Jul 30, 2021
@lithomas1 lithomas1 deleted the prefix-names-raises branch July 30, 2021 14:30
Leonardofreua pushed a commit to Leonardofreua/pandas that referenced this pull request Jul 30, 2021
…andas-dev#42690)

* REGR: ValueError raised when both prefix and names are set to None

* Update readers.py

* whitespace

* Update v1.3.1.rst

* Update v1.3.2.rst

* Update readers.py

* Update readers.py

Co-authored-by: Jeff Reback <[email protected]>
attack68 added a commit that referenced this pull request Jul 31, 2021
* TST: Fix doctests for pandas.io.formats.style

* Modified: pandas/io/formats/style.py

* Added some expected results

* Skipped some tests

* TST: Add link to redirect to Table Visualization user guide

* Modified style.py

* Updated the doctest of the apply()

* Updated the doctest of the applymap()

* Updated the doctest of the set_table_styles()

* Updated the doctest of the set_properties()

* TST: Add image to pipe function result

* Modified style.py

* Updated the doctest of the pipe()

* TST: Remove unnecessary outputs

* Modified pandas/io/formats/style.py

* Updated the doctests of the set_tooltips()

* Updated the doctests of the to_latex()

* Updated the doctests of the set_td_classes()

* Updated the doctests of the set_table_attributes()

* TST: Add the output to the Styler.format doctest in to_latex()

* REG: DataFrame.agg where func returns lists and axis=1 (#42762)

* Fix typing issues for CI (#42770)

* BUG: groupby.shift returns different columns when fill_value is specified (#41858)

* PERF: extract_array earlier in DataFrame construction (#42774)

* ENH: `sparse_columns` and `sparse_index` added to `Styler.to_html`  (#41946)

* TYP: Fix typing for searchsorted (#42788)

* DOC GH42756 Update documentation for pandas.DataFrame.drop to clarify tuples. (#42789)

* CI: Fix doctests (#42790)

* REGR: nanosecond timestamp comparisons to OOB datetimes (#42796)

* COMPAT: MPL 3.4.0 (#42803)

* Delete duplicates and unused code from reshape tests (#42802)

* REGR: ValueError raised when both prefix and names are set to None (#42690)

* REGR: ValueError raised when both prefix and names are set to None

* Update readers.py

* whitespace

* Update v1.3.1.rst

* Update v1.3.2.rst

* Update readers.py

* Update readers.py

Co-authored-by: Jeff Reback <[email protected]>

* TST: Add style.py to the doctest check

* TST: fixed eng_formatter doctest for #42671 (#42705)

* TST: Revert x and y position in some doctests

* Updated the doctest of the hide_columns()

Co-authored-by: Richard Shadrach <[email protected]>
Co-authored-by: Irv Lustig <[email protected]>
Co-authored-by: Thomas Smith <[email protected]>
Co-authored-by: jbrockmendel <[email protected]>
Co-authored-by: attack68 <[email protected]>
Co-authored-by: Mike Phung <[email protected]>
Co-authored-by: Matthew Zeitlin <[email protected]>
Co-authored-by: Thomas Li <[email protected]>
Co-authored-by: Patrick Hoefler <[email protected]>
Co-authored-by: Jeff Reback <[email protected]>
Co-authored-by: Krishna Chivukula <[email protected]>
feefladder pushed a commit to feefladder/pandas that referenced this pull request Sep 7, 2021
…andas-dev#42690)

* REGR: ValueError raised when both prefix and names are set to None

* Update readers.py

* whitespace

* Update v1.3.1.rst

* Update v1.3.2.rst

* Update readers.py

* Update readers.py

Co-authored-by: Jeff Reback <[email protected]>
feefladder pushed a commit to feefladder/pandas that referenced this pull request Sep 7, 2021
* TST: Fix doctests for pandas.io.formats.style

* Modified: pandas/io/formats/style.py

* Added some expected results

* Skipped some tests

* TST: Add link to redirect to Table Visualization user guide

* Modified style.py

* Updated the doctest of the apply()

* Updated the doctest of the applymap()

* Updated the doctest of the set_table_styles()

* Updated the doctest of the set_properties()

* TST: Add image to pipe function result

* Modified style.py

* Updated the doctest of the pipe()

* TST: Remove unnecessary outputs

* Modified pandas/io/formats/style.py

* Updated the doctests of the set_tooltips()

* Updated the doctests of the to_latex()

* Updated the doctests of the set_td_classes()

* Updated the doctests of the set_table_attributes()

* TST: Add the output to the Styler.format doctest in to_latex()

* REG: DataFrame.agg where func returns lists and axis=1 (pandas-dev#42762)

* Fix typing issues for CI (pandas-dev#42770)

* BUG: groupby.shift returns different columns when fill_value is specified (pandas-dev#41858)

* PERF: extract_array earlier in DataFrame construction (pandas-dev#42774)

* ENH: `sparse_columns` and `sparse_index` added to `Styler.to_html`  (pandas-dev#41946)

* TYP: Fix typing for searchsorted (pandas-dev#42788)

* DOC GH42756 Update documentation for pandas.DataFrame.drop to clarify tuples. (pandas-dev#42789)

* CI: Fix doctests (pandas-dev#42790)

* REGR: nanosecond timestamp comparisons to OOB datetimes (pandas-dev#42796)

* COMPAT: MPL 3.4.0 (pandas-dev#42803)

* Delete duplicates and unused code from reshape tests (pandas-dev#42802)

* REGR: ValueError raised when both prefix and names are set to None (pandas-dev#42690)

* REGR: ValueError raised when both prefix and names are set to None

* Update readers.py

* whitespace

* Update v1.3.1.rst

* Update v1.3.2.rst

* Update readers.py

* Update readers.py

Co-authored-by: Jeff Reback <[email protected]>

* TST: Add style.py to the doctest check

* TST: fixed eng_formatter doctest for pandas-dev#42671 (pandas-dev#42705)

* TST: Revert x and y position in some doctests

* Updated the doctest of the hide_columns()

Co-authored-by: Richard Shadrach <[email protected]>
Co-authored-by: Irv Lustig <[email protected]>
Co-authored-by: Thomas Smith <[email protected]>
Co-authored-by: jbrockmendel <[email protected]>
Co-authored-by: attack68 <[email protected]>
Co-authored-by: Mike Phung <[email protected]>
Co-authored-by: Matthew Zeitlin <[email protected]>
Co-authored-by: Thomas Li <[email protected]>
Co-authored-by: Patrick Hoefler <[email protected]>
Co-authored-by: Jeff Reback <[email protected]>
Co-authored-by: Krishna Chivukula <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO CSV read_csv, to_csv Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: read_csv raises an error when both prefix and names are set to None
5 participants