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

Convert '-' to '_' in summary dataframe #215

Merged
merged 20 commits into from
Nov 20, 2023
Merged

Conversation

ns-rse
Copy link
Contributor

@ns-rse ns-rse commented Oct 16, 2023

No description provided.

@jni
Copy link
Owner

jni commented Oct 16, 2023

Ach — looks like your editor had string normalisation on, as well as a few other settings that caused unrelated changes (removing some parentheses, changing 1. to 1.0...). Do you think you could find your fix and try again without all the changes?

@ns-rse
Copy link
Contributor Author

ns-rse commented Oct 17, 2023

Sorry about that, I'd setup the local repository to apply yapf automatically on commits using pre-commit but its not quite working as I expected. Will make sure future PRs don't have that problem.

@ns-rse
Copy link
Contributor Author

ns-rse commented Nov 17, 2023

Anything else required for this @jni ?

Copy link
Owner

@jni jni left a comment

Choose a reason for hiding this comment

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

@ns-rse Sorry, I assumed you were still working on this! Have you looked at the changes tab? There's still many unrelated changes — many look like black, e.g. line length exceeding 80c, 4 space indents...

src/skan/csr.py Outdated Show resolved Hide resolved
src/skan/csr.py Outdated Show resolved Hide resolved
@ns-rse
Copy link
Contributor Author

ns-rse commented Nov 17, 2023

Sorry @jni I thought I'd caught everything, will sort things out now.

@ns-rse
Copy link
Contributor Author

ns-rse commented Nov 17, 2023

Applied yapf via pre-commit run --all-files (twice as first time I was rushing and didn't remove the # yapf: disable / # yapf: ignore lines).

@ns-rse ns-rse requested a review from jni November 17, 2023 14:10
@ns-rse
Copy link
Contributor Author

ns-rse commented Nov 17, 2023

Was scratching my head 🤔 as to why the tests were failing until I realised my fork/branch were behind.

Hopefully sorted now.

@jni
Copy link
Owner

jni commented Nov 18, 2023

@ns-rse cool, this is ready now. I was about to merge but then I got worried that it would be a very disruptive change for our users. I think we should add a keyword argument to deprecate the - over two releases. It would be relatively easy:

  • add a keyword argument, say, separator=None;
  • in the code, do:
if separator is None:
    separator = '-';
    warnings.warn(
            "separator in column name will change to _ in next version; "
            "use `separator='-'` to maintain current behaviour and silence this warning; "
            "use `separator='_'` to switch to the new behaviour and silence this warning."
            )
  • at the end of the function, do summary.rename(columns=lambda s: s.replace('_', separator)
  • in all the tests, call the function with separator='_'
  • finally, add a test with with pytests.warns that calls it without a separator argument to check that the default works.

Actually I might just push the changes directly and then merge. 😂 I hope this solution is ok with you!

@jni
Copy link
Owner

jni commented Nov 18, 2023

Well I'm glad I did that cos it made me check the docs, which needed to be updated with the new separator. @ns-rse can you sanity-check for me that this is an ok approach? I was a bit annoyed with adding separator= everywhere, but at the same time, it's a lot easier for downstream users to do separator='-' to their summarize calls, rather than hunt down every downstream usage of a column identifier...

Copy link
Contributor Author

@ns-rse ns-rse left a comment

Choose a reason for hiding this comment

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

Sorry for missing updates to documentation.

I agree that its sensible to deprecate this with warnings and give people the opportunity to phase things out and this looks like a sensible approach. I've never undertaken deprecations before so I've learnt about when to use DeprecationWarning v FutureWarning. Do you think skan might be being used by other developers and warrant a DeprecationWarning?

One minor suggestion I have is to raise the warning when separator = '-' is explicitly given as whilst the chances are people will have read the warning at least once if they are explicitly specifying it, it would perhaps be useful to remind them of the need to change existing code.

src/skan/csr.py Show resolved Hide resolved
doc/examples/visualizing_3d_skeletons.md Outdated Show resolved Hide resolved
src/skan/test/test_csr.py Show resolved Hide resolved
@jni
Copy link
Owner

jni commented Nov 20, 2023

What you say is the correct approach if we plan to remove support for - in the future. However, I don't think we want to do that, because then users have to go through two deprecation cycles: one to set separator='_', then another to remove the separator argument. That's annoying, and maybe people would be happy with using separator='-' forever — we don't have to use it in our docs and/or internal usage. So, we can decide to warn only when separator is not given, and keep separator around ~forever, or until 1.0.

Probably I would do VisibleDeprecationWarning rather than DeprecationWarning, as many users don't see DeprecationWarnings. But I agree that it's better than FutureWarning.

@jni
Copy link
Owner

jni commented Nov 20, 2023

🤦 I completely forgot to update the docs, sorry.

Don't worry, I would have forgotten too if I hadn't git grep summarized. I need to add tests of the docs build. Actually there's other parts of the docs that are broken right now, but I left fixing them to another PR.

@jni jni added this to the 0.12 milestone Nov 20, 2023
@jni jni merged commit 1aee194 into jni:main Nov 20, 2023
11 checks passed
@ns-rse ns-rse deleted the ns-rse/rename-df-vars branch November 20, 2023 10:34
@ns-rse
Copy link
Contributor Author

ns-rse commented Nov 20, 2023

Actually there's other parts of the docs that are broken right now, but I left fixing them to another PR.

The pytest-doctestplus plugin might be of some use here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants