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

Replace "foo!r" to "repr(foo)" syntax #29886

Closed
63 of 72 tasks
ShaharNaveh opened this issue Nov 27, 2019 · 30 comments
Closed
63 of 72 tasks

Replace "foo!r" to "repr(foo)" syntax #29886

ShaharNaveh opened this issue Nov 27, 2019 · 30 comments
Labels
Code Style Code style, linting, code_checks good first issue
Milestone

Comments

@ShaharNaveh
Copy link
Member

ShaharNaveh commented Nov 27, 2019

Since we are moving to f-strings and dropping old strings formats (% and .format()), we no longer need to have the redundant %r and !r specifiers, instead we use the repr() format.

Notes:

  • Don't forget to link this issue in your PR, paste this https://github.com/pandas-dev/pandas/issues/29886 in your PR.

  • If any of your changed files are related to Replace old string formatting syntax with f-strings #29547 , please make sure to link your pull request to that issue as well, simply paste this https://github.com/pandas-dev/pandas/issues/29547 in your pull request's body message as well.

  • Please comment what you are planning to work on, so we won't do double work.

  • If a file/files that should be marked as done, is'nt marked, please comment letting me know.


To check what files still needs to be fixed in the "pandas" directory:

grep -R -e '%r' -e '!r}' -e "'{}'" --include=*.{py,pyx} pandas/
Tip:

If you want to see the line number of the occurrence, replace the -l with -n
for example:

grep -n -R '%r' --include=*.{py,pyx} pandas/

The current list is:

  • ci/print_skipped.py

  • pandas/_config/config.py

  • pandas/conftest.py

  • pandas/core/accessor.py

  • pandas/core/algorithms.py

  • pandas/core/arrays/categorical.py

  • pandas/core/arrays/datetimelike.py

  • pandas/core/arrays/period.py

  • pandas/core/arrays/numpy_.py

  • pandas/core/computation/align.py

  • pandas/core/computation/eval.py

  • pandas/core/computation/expressions.py

  • pandas/core/computation/expr.py

  • pandas/core/computation/ops.py

  • pandas/core/computation/pytables.py

  • pandas/core/dtypes/common.py

  • pandas/core/dtypes/dtypes.py

  • pandas/core/frame.py

  • pandas/core/generic.py

  • pandas/core/groupby/grouper.py

  • pandas/core/indexes/base.py

  • pandas/core/indexes/datetimelike.py

  • pandas/core/indexes/interval.py

  • pandas/core/indexes/numeric.py

  • pandas/core/internals/concat.py

  • pandas/core/internals/managers.py

  • pandas/core/missing.py

  • pandas/core/nanops.py

  • pandas/core/reshape/concat.py

  • pandas/core/reshape/merge.py

  • pandas/core/reshape/tile.py

  • pandas/core/series.py

  • pandas/core/sorting.py

  • pandas/core/strings.py

  • pandas/core/window/rolling.py

  • pandas/__init__.py

  • pandas/io/formats/css.py

  • pandas/io/formats/excel.py

  • pandas/io/formats/style.py

  • pandas/io/html.py

  • pandas/io/parsers.py

  • pandas/_libs/interval.pyx

  • pandas/plotting/_core.py

  • pandas/tests/computation/test_eval.py

  • pandas/tests/frame/test_alter_axes.py

  • pandas/tests/frame/test_analytics.py

  • pandas/tests/frame/test_query_eval.py

  • pandas/tests/groupby/test_whitelist.py

  • pandas/tests/indexes/datetimes/test_datetime.py

  • pandas/tests/indexes/multi/test_integrity.py

  • pandas/tests/indexes/period/test_period.py

  • pandas/tests/indexes/test_common.py

  • pandas/tests/indexes/timedeltas/test_timedelta.py

  • pandas/tests/io/msgpack/test_case.py

  • pandas/tests/io/msgpack/test_extension.py

  • pandas/tests/io/parser/test_unsupported.py

  • pandas/tests/io/test_html.py

  • pandas/tests/test_expressions.py

  • pandas/tests/test_strings.py

  • pandas/tests/io/test_sql.py

  • pandas/tests/reshape/test_concat.py

  • pandas/tests/scalar/timedelta/test_timedelta.py

  • pandas/tests/series/test_missing.py

  • pandas/tests/tseries/offsets/test_fiscal.py

  • pandas/tests/tseries/offsets/test_offsets.py

  • pandas/tseries/offsets.py

  • pandas/util/_decorators.py

  • pandas/util/_test_decorators.py

  • pandas/util/testing.py

  • pandas/_version.py

  • /scripts/tests/test_validate_docstrings.py


Lastly:

  • Add a test case (so we won't regress)
@ShaharNaveh ShaharNaveh changed the title Replace redundant !r to expressive repr() Replace redundant %r and !r to repr() Nov 27, 2019
@simonjayhawkins simonjayhawkins added Code Style Code style, linting, code_checks good first issue labels Nov 27, 2019
@jbrockmendel
Copy link
Member

Another option that we use in quite a few places is single quotes "foo '{bar}' baz"

@ShaharNaveh
Copy link
Member Author

Another option that we use in quite a few places is single quotes "foo '{bar}' baz"

@jbrockmendel I'm kinda obligated about how to find them systemically, meaning what if there's is a change to the repr() function, and the single quotas are there to differ from the repr() (If they're any). plus I'm not sure how to grep for this pattern.

@ShaharNaveh
Copy link
Member Author

ShaharNaveh commented Nov 30, 2019

I'll take:

  • pandas/tests/tseries/offsets/test_fiscal.py

  • pandas/tests/tseries/offsets/test_offsets.py

  • pandas/tseries/offsets.py

  • pandas/util/testing.py

@souravs17031999
Copy link
Contributor

souravs17031999 commented Dec 3, 2019

working on :

  • pandas/core/sorting.py
  • pandas/core/string.py
  • pandas/core/series.py

currently if no one has taken it yet.
will add more as i go further.

@kvn219
Copy link
Contributor

kvn219 commented Dec 3, 2019

Working on: pandas/core/sorting.py

@kvn219 kvn219 mentioned this issue Dec 3, 2019
4 tasks
souravs17031999 added a commit to souravs17031999/pandas that referenced this issue Dec 4, 2019
As described in the following issue
pandas-dev#29886
, usage of !r is currently redundant and so changing to f strings in place of it.
@souravs17031999
Copy link
Contributor

hi @kvn219 , actually i am already working on three files one of which is what you have also mentioned , can you please work on some other file.

@JvPy
Copy link
Contributor

JvPy commented Dec 4, 2019

I`ll take

pandas/pandas/io/parsers.py

pandas/pandas/io/html.py

JvPy added a commit to JvPy/pandas that referenced this issue Dec 4, 2019
JvPy added a commit to JvPy/pandas that referenced this issue Dec 5, 2019
JvPy added a commit to JvPy/pandas that referenced this issue Dec 5, 2019
@EydenVillanueva
Copy link
Contributor

Hi to everyone, I will take:

  • pandas/_config/config.py
  • pandas/conftest.py
  • pandas/core/accessor.py
  • pandas/core/algorithms.py

@ShaharNaveh
Copy link
Member Author

ShaharNaveh commented Dec 23, 2019

@WillAyd Can you please reopen this issue?

In this PR there is a use of the word fix and after that this PR number, so it closed it.

@WillAyd WillAyd reopened this Dec 23, 2019
@WillAyd
Copy link
Member

WillAyd commented Dec 23, 2019

done - thanks!

@AncientRickles
Copy link
Contributor

@WillAyd Can you please reopen this issue?

In this PR there is a use of the word fix and after that this PR number, so it closed it.

Sorry about that. Still kinda new to this...

@ShaharNaveh
Copy link
Member Author

Sorry about that. Still kinda new to this...

It's perfectly fine :)

@naomi172839
Copy link
Contributor

pandas/tests/test_strings.py was checked and already uses f-strings.
pandas/core/dtypes/common.py was checked and already uses f-strings.
pandas/tests/indexes/test_common.py was checked and already uses f-strings.
pandas/core/window/rolling.py was checked and already uses f-strings.
pandas/core/computation/pytables.py was checked and already uses f-strings.
pandas/tests/indexes/datetimes/test_datetime.py was checked and already uses f-strings.
pandas/core/generic.py was checked and already uses f-strings.

If possible, it would be great to update the master list.

@ShaharNaveh
Copy link
Member Author

pandas/tests/test_strings.py was checked and already uses f-strings.
pandas/core/dtypes/common.py was checked and already uses f-strings.
pandas/tests/indexes/test_common.py was checked and already uses f-strings.
pandas/core/window/rolling.py was checked and already uses f-strings.
pandas/core/computation/pytables.py was checked and already uses f-strings.
pandas/tests/indexes/datetimes/test_datetime.py was checked and already uses f-strings.
pandas/core/generic.py was checked and already uses f-strings.

If possible, it would be great to update the master list.

TY, really appreciate it

@ShaharNaveh
Copy link
Member Author

@jreback Can you please reopen this issue?

The PR was suppose to contain two test cases, but it only contained one.

This should be reopen.

@jreback jreback reopened this Dec 25, 2019
@jreback jreback modified the milestones: Contributions Welcome, 1.0 Dec 25, 2019
@ShaharNaveh
Copy link
Member Author

Thanks @jreback

@naomi172839
Copy link
Contributor

pandas/core/arrays/datetimelike.py
pandas/core/arrays/period.py

Both of the above are free of the old style strings.
I am working on:
pandas/init.py

naomi172839 added a commit to naomi172839/pandas that referenced this issue Dec 27, 2019
Fixed the remaining files.

Signed-off-by: nbonnin <naomi172839@gmail.com>
@naomi172839
Copy link
Contributor

I tackled the remaining files. Did not implement a test though.

AlexKirko pushed a commit to AlexKirko/pandas that referenced this issue Dec 29, 2019
keechongtan added a commit to keechongtan/pandas that referenced this issue Dec 29, 2019
…ndexing-1row-df

* upstream/master: (333 commits)
  CI: troubleshoot Web_and_Docs failing (pandas-dev#30534)
  WARN: Ignore NumbaPerformanceWarning in test suite (pandas-dev#30525)
  DEPR: camelCase in offsets, get_offset (pandas-dev#30340)
  PERF: implement scalar ops blockwise (pandas-dev#29853)
  DEPR: Remove Series.compress (pandas-dev#30514)
  ENH: Add numba engine for rolling apply (pandas-dev#30151)
  [ENH] Add to_markdown method (pandas-dev#30350)
  DEPR: Deprecate pandas.np module (pandas-dev#30386)
  ENH: Add ignore_index for df.drop_duplicates (pandas-dev#30405)
  BUG: The setting xrot=0 in DataFrame.hist() doesn't work with by and subplots pandas-dev#30288 (pandas-dev#30491)
  CI: Fix GBQ Tests (pandas-dev#30478)
  Bug groupby quantile listlike q and int columns (pandas-dev#30485)
  ENH: Add ignore_index for df.sort_values and series.sort_values (pandas-dev#30402)
  TYP: Typing hints in pandas/io/formats/{css,csvs}.py (pandas-dev#30398)
  BUG: raise on non-hashable Index name, closes pandas-dev#29069 (pandas-dev#30335)
  Replace "foo!r" to "repr(foo)" syntax pandas-dev#29886 (pandas-dev#30502)
  BUG: preserve EA dtype in transpose (pandas-dev#30091)
  BLD: add check to prevent tempita name error, clsoes pandas-dev#28836 (pandas-dev#30498)
  REF/TST: method-specific files for test_append (pandas-dev#30503)
  marked unused parameters (pandas-dev#30504)
  ...
@TomAugspurger
Copy link
Contributor

So the only remaining item is a code check test for !r rather than repr?

@TomAugspurger
Copy link
Contributor

Actually, it looks like we have a check for that. @MomIsBestFriend is there anything else to do here?

@ShaharNaveh
Copy link
Member Author

@TomAugspurger I think not 😃

Thank you all for helping ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Style Code style, linting, code_checks good first issue
Projects
None yet
Development

No branches or pull requests