pytest --collect-only needs a one char shortcut command I find myself needing to run very often and that cli argument is a very long to type one. I do think that it would be great to allocate a character for it, not sure which one yet. Please use up/down thumbs to vote if you would find it useful or not and eventually proposing which char should be used. Clearly this is a change very easy to implement but first I want to see if others would find it useful or not. pytest --collect-only needs a one char shortcut command I find myself needing to run very often and that cli argument is a very long to type one. I do think that it would be great to allocate a character for it, not sure which one yet. Please use up/down thumbs to vote if you would find it useful or not and eventually proposing which char should be used. Clearly this is a change very easy to implement but first I want to see if others would find it useful or not.


Show deprecation warning if junitfamily is not set Show a deprecation warning if the user has not configured ()


Regression in 5.2.3: pytest tries to collect random files This was caught by our build server this morning. It seems that pytest 5.2.3 tries to import any file under the current directory. (We have some package that is only used on windows and cannot be imported on linux.) Here is a minimal example using tox that reproduces the problem (I'm running on Debian 10 with Python 3.7.3):


'.[' replaced with '[' in the headline shown of the test report The replaced with in the headline shown with long report output. The same problem also causing the vscode-python test discovery error. I trace back the source code. The headline comes from line 148. comes from line 437 The headline comes from line 306 This line of code causes the problem. We should replace it with . After changing this, run , pass all the tests and resolve this issue. But I can't find this line of code for what purpose.


--setup-plan and --setup-only seem to claim different things I have the following example: When running with , I get the following output (indicating extra teardown of fixture1 and 2): When running with , the SETUP and TEARDOWN markers occur where my actual setup and teardown code executes: --setup-plan and --setup-only seem to claim different things I have the following example: When running with , I get the following output (indicating extra teardown of fixture1 and 2): When running with , the SETUP and TEARDOWN markers occur where my actual setup and teardown code executes:


Calls to () in skipif causes all logging calls to be duplicated to stderr Using pytest 5.2.2 / 5.3.0, when a function called from a uses a logging function, the captured log calls are duplicated to stderr. Minimal working example: Results in the following. Notice "Schmift" is printed both to "Captured stderr call" and "Captured log call". Removing the logging call from results in the expected behaviour, "Schmift" is not duplicated to stderr:


disallow absolute and non-normalized paths for mktemp followup to this is an potential issue and attack vector, absolute paths are no tmpdir and escaping paths aren't either, just normalizing would also break the world so we should only ever accept normalized relative paths for it


Module re-write doesn't work with non dist-info based installations More context behind this issue is available at: TL;DR: The function doesn't detect modules that can be rewritten, if they are installed by a method which doesn't adopt the dist-info format. An easy way to reproduce the problem is to: in one environment and in another and compare the output for: Because of this problem, rpm maintainers are unable to run the tests for pytest-mock, since they rely on which creates egg-info directories.


Improve deprecation docs for Node.fromparent In the "Node Construction changed to Node.fromparent" section in the deprecation docs, we definitely need to add: [x] An example of the warning that users will see (so they can find the session on google). [x] The warning should point to the deprecation docs. [x] Show a "before -after" example. [x] ensure fromparent will not support config/session


Expressions match against folder structure above pytest root Say I have a test file If I want to match only , this works as expected However if I want to execute only using similar means: both tests are collected because is in the parent path even though it might not have anything to do with the test environment. Is this expected behaviour?


-k mishandles numbers Using . It seems that pytest cannot handle keyword selection with numbers, like . Considering the following tests: Selecting with works: But selecting with doesn't, as I get all tests: If I make it a string though, using , then it works again: I see there are some notes about selecting based on keywords here but it was not clear if it applied to this case: So, is this a bug? Thanks!


unittest.TestCase cleanup functions not invoked on test failure stdlib unittest style cleanup functions registered with are not invoked when a test fails. It appears this issue was introduced in pytest version 5.4.0, examples below for version 5.4.1. Ubuntu 18.04.3 LTS Python 3.6.8 pytest 5.4.1


Wrong relative path in skip report when tested file is upper than invocation directory The problem is if tested file is upper than invocation directory . It occurs in skip report. Example: path of tested file is: and is called in location: . Instead it should be.


pytest.doctest.issetuppy raises with LC_ALL=C and UTF-8 chars in runs into an exception when collecting tests from a repository where contains UTF-8 characters, but the locale is set to . Minimal example: : To reproduce: Tested on CentOS 7.7.1908:


BytesWarning when using --setup-show with bytes parameter With Python 3.8.2, pytest 5.4.1 (or latest master; stacktraces are from there) and this file: when running (note the to turn on ByteWarning and treat it as error), I get: Shouldn't that be using or something rather than (implicitly) ?


Wrong path to test file when directory changed in fixture Files are shown as relative to new directory when working directory is changed in a fixture. This makes it impossible to jump to the error as the editor is unaware of the directory change. The displayed directory should stay relative to the original directory. The full output is:


warn when logging fails Now an expectation will be thrown and written on the output... but no warning is thrown... so the test run can't be marked as failed.


unittest.TestCase.tearDown executed on skipped tests when running --pdb With this minimal test: test is properly skipped: but when running with , the teardown seems executed: I would have expected the test to be skipped, even with . With , test was also skipped with , so this seem something that have changes between 5.4.2 and 5.4.1. (I would have loved to, but I don't have time to send a PR these days)


pytest~=4.6: While implementing a test for I've hit this: Looking at the repo, it seems to have been fixed on master by as a part of But it still persists in the branch. The fix should be trivial: just add a fallback variable value before if-blocks. No need to backport that whole PR (unless somebody thinks that it should be done, of course). Ref: [4.6.x] Add a fallback for the term report letter When plugins return report objects in an unconventional state, may skip entering if-block branches that declare the variable. It would lead to UnboundLocalError: local variable 'letter' referenced before assignment being raised. This change fixes this by setting the initial value of the before the if-block cascade so that it always has a value. [ ] Include documentation when adding new features. [ ] Include new tests or update existing tests when applicable. [ ] Allow maintainers to push and squash when merging my commits. Please uncheck this if you prefer to squash the commits yourself. Unless your change is trivial or a small documentation fix (e.g., a typo or reword of a small section) please: for details. Write sentences in the past or present tense, examples: Improved verbose diff output with sequences. Terminal summary statistics now use multiple colors. Also make sure to end the sentence with a . [ ] Add yourself to in alphabetical order.


Pytest crashes the interpreter on debug build for 3.8+ Short reproducer Related issue for improvement of this behavior:


FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pytest-of-jenkins/pytest-' Same issue as in . I think there are still some edge cases where this is not handled correctly. I am running a series of concurrent pytest processes and was able to reproduce the issue. Here is the stack trace: A potential mitigation to this problem might be to generate the numbered dir with a random suffix rather than a sequential one, unless some code depends on this logic:


Incorrect caching of skipif/xfail string condition evaluation Version: pytest 5.4.3, current master pytest caches the evaluation of the string in e.g. . The caching key is only the string itself (see in ). However, the evaluation also depends on the item's globals, so the caching can lead to incorrect results. Example: Running . Expected: is skipped, is not skipped. Actual: both are skipped. I think the most appropriate fix is to simply remove the caching, which I don't think is necessary really, and inline into .


skipping: --runxfail breaks location reporting pytest versions: 5.4.x, current master When / marks are used to skip a test, for example the expected skip location reported should point to the item itself, and this is indeed what happens when running with : However, adding breaks this: The is only about xfail and should not affect this at all. Hint: the bug is in , the hook.


Support NOCOLOR to disable colored output is a variable. The general behavior is: A command line application emits colour when attached to a TTY, but no colour otherwise e.g. when attached to a pipe. stops the application from emitting colour even when attached to a TTY My extension to the standard is to add which forces the application to emit colour escape sequences even when not outputting to a TTY e.g. if we want to pipe into a log file with colour. Originally posted by in


--log-file should create subdirectories If you provide a path with a subdirectory, which does not exist, it crashes with. For example execute produces something like this: Maybe someone want to add something like this However, there is the possibility to say that someone is not supposed to pass a directory path there. Originally posted by in


pytest 6 (?): UnicodeEncodeError in terminalwriter on Windows Just got this on GitHub Actions with the pytest 6 rc: This is the test using pytest-bdd in qutebrowser: I can't reproduce this consistently - if I'm reading the traceback right, the test failed (probably flaky?) and then pytest failed while printing the traceback... Note that I also have pytest-instafail installed and it shows up in the stacktrace. Not sure if this is actually related to pytest 6, but I've never seen it happen before.


Pytest 6: Dynamically adding xfail marker in test no longer ignores failure <!-- Thanks for submitting an issue! Here's a quick checklist for what to provide: --With pytest 5.x, we can dynamically add an xfail to a test object using (see example below). In 5.x this treated the failing test like a a test marked statically with an . With 6.0.0rc0 it raises. <details</details- [ ] pytest and operating system versions Pytest 6.0.1rc0 and MacOS 10.14.5 With 5.4.3 With 6.0.0rc0


suggestion: improve raises confusing message when matching [x] a detailed description of the bug or suggestion I would like to check if strings have parenthesis in them when match is not None, so that people have that lightbulb moment, rather than head-scratching when it presents two identical strings as not matching. [ ] output of from the virtual environment you are using I believe this is not applicable right now. I'm happy to provide one if you believe other modules or libraries are causing this behavior. [x] pytest and operating system versions Windows 10 64-bit (I know), all updates installed Pytest 5.4.3 [x] minimal example if possible edited 22:31 (same day) as the example given was the fixed code including escapes and r prefix I believe a more helpful error message


Cleaning up temporary directories occasionally raises PermissionError On Windows, I'm finding that pytest occasionally raises an exception starting with while cleaning up its temporary directories. Below is an example of the output of a test session in which the exception arises. The test file contains only the function shown in the output. A necessary condition for the exception is that pytest's base temporary directory already contains at least three temporary directories to cause pytest to try to clean up at least one directory. Also, the exception occurred more often when the computer was under load. ============================= test session starts ============================= platform win32 -- Python 3.7.7, pytest-5.4.3, py-1.9.0, pluggy-0.13.1 rootdir: C:\Users\Desktop\pytest-garbage collected 1 item F [100%] ================================== FAILURES =================================== ___ testtemp ___ tmppathfactory = TempPathFactory(givenbasetemp=None, trace=<pluggy.tracing.TagTracerSub object at 0x0000026E365FECC8, basetemp=None) def testtemp(tmppathfactory): for in range(1000): .\Programs\Miniconda3-64\envs\pytest-garbage\lib\site-packages\pytest\ in mktemp basename = self.ensurerelativetobasetemp(basename) .\Programs\Miniconda3-64\envs\pytest-garbage\lib\site-packages\pytest\ in ensurerelativetobasetemp if (self.getbasetemp() / basename).resolve().parent != self.getbasetemp(): .\Programs\Miniconda3-64\envs\pytest-garbage\lib\site-packages\pytest\ in getbasetemp prefix="pytest-", root=rootdir, keep=3, locktimeout=LOCKTIMEOUT .\Programs\Miniconda3-64\envs\pytest-garbage\lib\site-packages\pytest\ in makenumbereddirwithcleanup considerlockdeadifcreatedbefore=considerlockdeadifcreatedbefore, .\Programs\Miniconda3-64\envs\pytest-garbage\lib\site-packages\pytest\ in cleanupnumbereddir trycleanup(path, considerlockdeadifcreatedbefore) .


\Programs\Miniconda3-64\envs\pytest-garbage\lib\site-packages\pytest\ in trycleanup if ensuredeletable(path, considerlockdeadifcreatedbefore): .\Programs\Miniconda3-64\envs\pytest-garbage\lib\site-packages\pytest\ in ensuredeletable if not (): .\Programs\Miniconda3-64\envs\pytest-garbage\lib\ in exists () self = WindowsPath('') def stat(self): """ Return the result of the stat() system call on this path, like () does. """ E PermissionError: [WinError 5] Access is denied: 'C:\Users\\AppData\Local\Temp\pytest-of-\garbage--fd35-4f5b-b6c5-\.lock' ....\Programs\Miniconda3-64\envs\pytest-garbage\lib\ PermissionError =========================== short test summary info =========================== FAILED - PermissionError: [WinError 5] Access is deni... ============================== 1 failed in 0.83s ============================== It seems that sometimes the operating system continued to actually delete the files and directories inside an old directory even after the function (below) completed the call in its first statement to . Then, the second statement found that lingering directory, which renamed to the form . While was attempting again to delete its contents, the operating system finished actually deleting them, and the exception occurred. def cleanupnumbereddir( root: Path, prefix: str, keep: int, considerlockdeadifcreatedbefore: float ) -None: """cleanup for lock driven numbered directories""" for path in cleanupcandidates(root, prefix, keep): trycleanup(path, considerlockdeadifcreatedbefore) for path in ("garbage-"): trycleanup(path, considerlockdeadifcreatedbefore) I tested simply reversing the two statements, so that pytest cleans old directories before numbered directories, and that appeared to prevent the exception in my testing. The operating system is Windows 10.0.


Build , the file system is NTFS on a solid-state drive, I'm using a conda environment, and produces: Package Version ------------------ ------------------- atomicwrites 1.4.0 attrs 19.3.0 certifi 2020.6.20 colorama 0.4.3 importlib-metadata 1.7.0 more-itertools 8.4.0 packaging 20.4 pip 20.1.1 pluggy 0.13.1 py 1.9.0 pyparsing 2.4.7 pytest 5.4.3 setuptools 47.3.1.post20200622 six 1.15.0 wcwidth 0.2.5 wheel 0.34.2 wincertstore 0.2 zipp 3.1.0 I also encountered the same exception using pytest version 6.0.0rc1, although the session output differs because pytest* defers the clean-up until exit: ============================= test session starts ============================= platform win32 -- Python 3.7.7, pytest-6.0.0rc1, py-1.9.0, pluggy-0.13.1 rootdir: C:\Users\Desktop\pytest-garbage collected 1 item . [100%] ============================== 1 passed in 2.67s ============================== Error in atexit.runexitfuncs: Traceback (most recent call last): File "c:\users\programs\miniconda3-64\envs\pytest-garbage\lib\", line 1356, in exists () File "c:\users\programs\miniconda3-64\envs\pytest-garbage\lib\", line 1178, in stat return (self) PermissionError: [WinError 5] Access is denied: 'C:\Users\\AppData\Local\Temp\pytest-of-\garbage--f05a-46d7-bd84-\.lock' Is swapping the statements within a good way to resolve this issue?


pytest 6.0.0rc1: capfd.readouterr() converts \r to \n I am testing pytest 6.0.0rc1 with Fedora packages. This is the first failure I get, from borgbackup 1.1.13. I've distilled a reproducer: pytest 5: pytest 6: This is Fedora 32 with Python 3.8 (the original failure in borgbackup is Fedora 33 with Python 3.9). I could have not found anything about this change in the changelog nor at hence I assume this is a regression. I've labeled it as such, but feel free to change that.


pytest 6: Traceback in contains repr of The tests fail with pytest 6: This is because of (, "code: remove last usage of ") - it removed the , but the format string uses , so now we get the repr of the object instead of the repr of a string. I believe this should continue to use so the output is the same in all cases. cc


caplog fixture doesn't restore log level after test From the documentation at , "The log levels set are restored automatically at the end of the test". It used to work, but looks broken in new 6.0 release. Minimal example to reproduce: It prints "0" for pytest<6, "42" after.


Reintroduce warnings postponed in 6.0 A few warnings were introduced near the 6.0 release, so we can't comply with the "2 versions minimum with warnings", so for 6.0 these warnings were suppressed in We should reintroduce them in 6.1.


Since pytest 6.0.0, pylint complains about unimplemented abstract methods in custom collector Hi, we have implemented a custom pytest collector that takes testcases from YAML files. Starting with pytest 6.0.0, pylint reports the following about that collector: The collector has worked fine for a long time, and it still works fine. The line pylint reports this on is the class definition of a collector class that is based on pytest.File: The whole source code is here: Versions: Python 3.8.0 (default, Oct 15 2019, 17:49:23). This happens on all Python 3.x versions we used pytest 6.0.1 with (3.5, 3.6, 3.7, 3.8), on macOS and Ubuntu. pylint 2.4.4 astroid 2.3.3 platform linux -- Python 3.8.0, pytest-6.0.1, py-1.9.0, pluggy-0.13.1 plugins: cov-2.10.0, yagot-0.5.0, requests-mock-1.8.0 Please let me know in case a collector has to implement these methods.


logging: handler level restored incorrectly if caplog.setlevel is called more than once pytest version: 6.0.1 The fix in (backported to 6.0.1) has a bug where it does a "set" instead of "setdefault" to the . So if there are multiple calls to , the level will be restored to that of the one-before-last call, instead of the value before the test. Will submit a fix for this shortly.


Crash with NameError through decorator during collection pytest crashes when trying to collect the following file: The failure representation works with : I've started writing a test, but it fails in both modes like the first case above:


[Feature] Allow a --sw-skip shorthand cli arg like --sw itself permits The stepwise plugin exposes a shorthand option for the stepwise itself, however it requires a longer arg only for skip, I think these should be consistent and should offer shorthand versions for both. Expected:


Symlinked directories not collected since pytest 6.1.0 When there is a symlink to a directory in a test directory, is is just skipped over, but it should be followed and collected as usual. This regressed in (included in 6.1.0). For some reason I a in there, I don't remember why, but it does not match the previous behavior and should be removed. PR for this is coming up.


Deprecate I don't see the point in removing it in a release just to reintroduce it again, that just makes things more confusing for everyone. Originally posted by in


Doctest collection only returns single test for <!-- Thanks for submitting an issue! Quick check-list while reporting bugs: --will only collect a single doctest because of this: Introduced a while back by here: See failing tests: Failing doctest collection When the module is an the doctest collection only picks up 1 doctest.


Class cleanups in Python 3.8+ are not called Did not see mentioned anywhere in this repo, which is the method that should be called. See Repo: With unittest: With Pytest:


set sys.unraisablehook (py38) Python 3.8 has a new hook: sys.unraisablehook Pytest should set this to be able to associate unraisable exceptions with tests


Allow contibuting additional global variables for skipif/xfail [ ] Include documentation when adding new features. [x] Include new tests or update existing tests when applicable. [X] Allow maintainers to push and squash when merging my commits. Please uncheck this if you prefer to squash the commits yourself. for details.


Problem with faulthandler when used with Twisted Logger and "pytest --capture=no" Dear developers, thanks a stack for conceiving and maintaining this excellent package. I never expected to file an issue or submit a patch here, but here we go. On behalf of , we are currently in the progress of finally upgrading to Python 3. Kotori is based on Twisted and uses for testing. Within , we tried hard to apply some magic to make everything work together on all occasions with respect to appropriately configuring to our needs. We are on macOS 10.13.6. The background on this is that the Twisted Logger intercepts the logging by providing a file-like wrapper around the stream, which is obviously not an actual stream. In this case, when running with , 's fails when trying to restore the stream through at [1] as this will actually return , in turn signaling an invalid file descriptor [2]. It will a) raise the exception outlined below and b) won't stop the process on teardown. [1] [2] This problem is mitigated by . With kind regards, Andreas.


tmpdir creation fails when the username contains illegal characters for directory names , and rely on for determining the directory. I found that the user name returned by may return characters that are not allowed for directory names. This may lead to errors while creating the temporary directory. The situation in which I reproduced this issue was while being logged in through an ssh connection into my Windows 10 x64 Enterprise version (1909) using an OpenSSHforWindows7.7p1 server. In this configuration the command returns my domain username e.g. instead of as when logged in regularly using a local session. When trying to create a temp directory in pytest through e.g. this fails with the following error message: I could also reproduce this without the complicated ssh/windows setup with pytest 6.2.2 using the following commands from a : Thanks for having a look at this!


Starting v6.2.0, unittest setUpClass fixtures are no longer "private" <!-- Thanks for submitting an issue! Quick check-list while reporting bugs: --Minimal example: The expected (and previously implemented behavior) is that this fixture's name would start with an underscore, and would therefore only get printed if the additional flag was used. As it stands, I don't see a way to hide such generated fixtures which will not have a docstring. This breaks a code-quality CI script that makes sure we don't have undocumented pytest fixtures (and the code-base has many legacy tests that use unittest, and that will not get upgraded).


approx: Better handle Decimal in sequences and mappings <!-- Thanks for suggesting a feature! Quick check-list while suggesting features: --Right now handles Decimal comparisons gracefully, thanks to We can do this: also knows how to handle sequences and mappings: doesn't handle Decimal within sequences and mappings: Both of these tests fail with <!-- A clear and concise description of what you want to happen. --I would like these kind of tests to be passing :) A linked PR should be following shortly :eyes: <!-- Provide examples of real-world use cases that this would enable and how it solves the problem described above. --<!-- Have you tried to workaround the problem using a pytest plugin or other tools? Or a different approach to solving this issue? Please elaborate here. --<!-- Add any other context, links, etc. about the feature here. --


Generate an error when a mark is applied to a fixture Follow up from . We should generate an error if a is applied to a fixture. There is a warning in about this problem which should be updated once this issue is dealt with.


Unexpected keyword argument 'path' from plugins While troubleshooting , I stumbled onto a new error, a that occurs when using pytest-black against the current main HEAD (), easily reproducible with an empty test file and pip-run: Same problem happens with pytest-checkdocs:


Minor temporary directory security issue in pytest versions before 6.2.3 A minor temporary directory security issue was found in pytest versions before 6.2.3. This issue is fixed in pytest 6.2.3. pytest used to create directories under with world-readable permissions. This means that any user in the system was able to read information written by tests in temporary directories (such as those created by the fixture). Now the directories are created with private permissions. pytest used to silenty use a pre-existing ` directory, even if owned by another user. This means another user could pre-create such a directory and gain control of another user's temporary directory. Now such a condition results in an error.


No color output when specifying log format string with precision-formatted levelname <!-- Thanks for submitting an issue! Quick check-list while reporting bugs: --Pytest fails to output colorfully with the following log format string in This is due to  fails to match the format string due to the presence of precision bit.


Internal error when adding a skip mark to a doctest inside a contextmanager To reproduce: This is a simplified issue from a real use case in the scikit-learn repo. We sometimes want to skip doctests, for example when matplotlib (an optional dependency) is not installed. If there is be a better way to do it with pytest than using , let me know. <details<summaryconda list output</summary</details


Improve handling of skip for module level This is potentially about updating docs, updating error messages or introducing a new API. Consider the following scenario: is using Python 3,8 syntax: It should not be tested under Python 3.6 and 3.7. This is a proper way to skip the test in Python older than 3.8: My actual test involves parameterize and a 3.8 only class, so skipping the test itself is not sufficient because the 3.8 class was used in the parameterization. A naive user will try to initially skip the module like: This issues this error: Using outside of a test is not allowed. To decorate a test function, use the or decorators instead, and to skip a module use `pytestmark = {skip,skipif}. The proposed solution , does not work in my case: pytest continues to process the file and fail when it hits the 3.8 syntax (when running with an older version of Python). The correct solution, to use skip as a function is actively discouraged by the error message. This area feels a bit unpolished. A few ideas to improve: skip with in the error message. this seems in conflict with the spirit of the message. an alternative API to skip a module to make things easier: , which can call .


Enhance warning assertion capabilities while writing some other bits and pieces, I had a use case for checking the omitted, has a that doesn't quite offer yet the information is already available in there, I suspect there is a good reason why we don't have so I propose some additional capabilities on to handle warnings in isolation. With the full dict comparison may get a bit intrusive as far as warning capture is concerned. something simple like: Thoughts?


pytest -k doesn't work with "\"? <div type='discussions-op-text'<supOriginally posted by nguydavi August 7, 2021</supHey! I've been trying to use passing the name I got by parametrizing my test. For example, Note the error message I tried escaping the but that didn't work, the only way I can make it work is to remove the backslashes completely, Is just not supported by ? Or am I missing something ? Thanks! EDIT: A possible test case Which is then referred by as . Essentially a new line character in the string brings the issue (or any escaped character probably)</div


has no effect without [x] a detailed description of the bug or problem you are having The flag will "exit on test failure and continue from last failing test". The flag is supposed to "ignore the first failing test but stop on the next failing test". However, it does nothing unless used in conjunction with . The combo requirement is not mentioned in the help text, seems redundant, and is surprising behavior. I recommend that should act the same as . [x] output of from the virtual environment you are using [x] pytest and operating system versions MacOS, Python 3.9.5, pytest-6.2.4 [x] minimal example if possible Example three failures: has no effect: works as expected, stopping after first failure: only works with to stop after second failure: I believe the above behavior, the combo of the flags, should work like that even if only is used.


Show full qualified name on direct Node construction warning In , running pytest with many plugins installed gives this error: And is not clear which plugin is the culprit, I had to look at the source code of to figure it out. We might consider at least show the full qualified name of the offending class in that message, so users would see , which is a nudge in the right direction. Originally posted by in


Add a parameter to <!-- Thanks for suggesting a feature! Quick check-list while suggesting features: --<!-- What are you trying to do, that you are unable to achieve with pytest as it currently stands? --I'd like to be able to use to check deselected count. <!-- A clear and concise description of what you want to happen. --Add a parameter to <!-- Provide examples of real-world use cases that this would enable and how it solves the problem described above. --Plugins that use to change the and add change the deselected items need to be tested. Using to check the deselected count would be helpful. <!-- Have you tried to workaround the problem using a pytest plugin or other tools? Or a different approach to solving this issue? Please elaborate here. --Use instead of . returns a dictionary that includes , if there are any. However, if we have a series of tests, some that care about deselected, and some that don't, then we may have some tests using and some using , which is slightly annoying. <!-- Add any other context, links, etc. about the feature here. --


test ids with s cannot be selected with By default pytest 6.2.2 parametrize does user arguments to generate IDs, but some of these ids cannot be used with option because you endup with errors like when trying to do so. The solution for this bug is to assure that auto-generated IDs are sanitized so they can be used with -k option. Example: As you can see the first parameter includes a slash, and for good reasons. It is far from practical to have to add custom "ids" for all of these, as you can have LOTS of them. There is another annoyance related to the -k selecting for parameterized tests, is the fact that square braces have special meanings for some shells and in order to use it you must remember to quote the strings. It would be much easier if the display and selecting of parametrized tests would use only shell-safe format, so we can easily copy/paste a failed test in run it. For example I think that using colon would be safe and arguably even easier to read: .


Error message prints extra code line when using assert in python3.9 <!-- Thanks for submitting an issue! Quick check-list while reporting bugs: --- [x] a detailed description of the bug or problem you are having [x] output of from the virtual environment you are using [x] pytest and operating system versions [ ] minimal example if possible I have a test like this: The test "testrightstatement" fails at the first assertion,but print extra code (the "t" decorator) in error details, like this: And the same thing did not happen when using python3.7.10 Is there some problems when calculate the statement lineno? pytest 6.2.5 Windows 10 Seems to happen in python 3.9,not 3.7


[prerelease] addition to is backwards-incompatible a new parameter to , cc However, this actually is an incompatible change: Doing e.g. followed by worked fine before, but now fails because the now included does not equal . This breaks pytest-bdd: - I could swear I also saw another project in fail after fixing the initial issue it had, but then Christmas and stuff came along and now I don't remember which one it was, and of course can't find it anymore. A (quite) reveals that more projects might be affected by this (excludes to avoid matches in copies of pytest's source code). Some examples I could dig up (but haven't verified): (maybe) I think the change in itself makes sense, but at the same time fixes like are a bit cumbersome. Two questions: What should we do about this for 7.0? (even if the answer just is "live with it and document it as backwards-incompatible in the changelog) What (if anything) should we do about this so that it doesn't happen again for future releases? I guess not much we can do, as long as we want to assume 0 for outcomes which have not been given...


INTERNALERRORTypeError: init() missing 1 required positional argument: 'testmethod' [ ] a detailed description of the bug or problem you are having [ ] output of from the virtual environment you are using [ ] pytest and operating system versions pytest-7.0.0 CentOS Stream 8 [ ] minimal example if possible Issue happened only once, as far as I know. I will update this issue if it happens multiple times and if I manage to reproduce it outside of GitHub Actions CI.


Pytest 7 not ignoring warnings as instructed on <!-- Thanks for submitting an issue! Quick check-list while reporting bugs: --- [x] a detailed description of the bug or problem you are having [x] output of from the virtual environment you are using [x] pytest and operating system versions [x] minimal example if possible Hello, with the latest version of Pytest a series of new issues has started to pop-up to warn users (and plugin maintainers) about future changes on how Pytest will work. This is a great work done by Pytest maintainers, and pushes the community towards a better future. However, after informing plugin maintainers about the upcoming changes, I would like to silence these warnings so I can focus in fixing the errors detected on the tests (otherwise the output is too big and difficult to scroll through to find useful information). To solve this, I naturally tried to modify my file with a filter for these warnings, however Pytest is still printing some of them even after I the warning filters. The following script can be used to reproduce the problem: Relevant output: (The warnings seem to be shown only once per worker per plugin, but considering you have 32 workers with and 4 plugins that haven't adapted to the changes yet, the output can be very verbose and difficult to navigate) Pytest should not print the warnings: -


0 regression: Existence of messes up package discovery with importlib + pythonpath mode (ModuleNotFoundError: No module named 'tests.<test-packages') Consider the following demo project: (existence of this file breaks package discovery) pytest (version 7.0.0) errors with: What's particularly surprising: The example works, when renaming the to e.g. . I.e., it seems that the existence of the implies that it is no longer possible to import from . Imports like this used to work with pre 7 pytest versions in mode despite the existence of a .


Current implementation of cannot be used to compare sets The current implementation of yields incorrect results when used to compare sets. Consider the following self-explanatory code comparing two (equal as by ) sets: Although the two sets are obviously the same, the last equality check using approx is failing. A quick view into the implementation of makes it obvious why this is the case: In , only is used (in ), but since sets are unordered, so is the resulting iterator. This means, for sets such an implementation cannot work. What makes things worse is the confusion that seems to exist here between the different abstract base classes: In the method, clearly is mentioned, explicitly. However, a set is not a sequence type, but only a collection type (because of the missing order). It is, however, iterable and since this is the only thing that is actually checked in the implementation, the code seems to work for sets, where, in fact, it does not. As a first step, I would suggest one could keep the current implementation, but explicitly check for sequence types (i.e. classes having a method) and delete all mentions of in the code as well as on the documentation page and make it crystal clear that there is only an implementation for sequence types. But what would be way better would, of course, be an implementation for arbitrary container comparisons. Tested with pytest version 7.0.1.


Version 7.1.0 seems like not picking up Over SciPy we have started to see the message in the title in our Azure Pipelines which started picking up 7.1.0 instead of 7.0.1 lastn ight. From the deprecation and removal list we couldn't see which item might have caused it. One speculation we might generate is that our mark is not registered in our file explicitly and maybe registrations are now obligatory. Here is a complete SciPy test suite example with all installation steps provided. And our file lives here Thank you for all the efforts.


ModuleNotFoundError for Numpy when fails <!-- Thanks for submitting an issue! Quick check-list while reporting bugs: --When using to compare lists in a test, a is raised for Numpy whenever the test fails. If the test succeeds, there is no such error. It appears that does not require Numpy to run, but the error message requires Numpy to display the details. Since does not require Numpy to function correctly, it should not require Numpy to display the error. macOS Big Sur Version 11.6.2 No which makes the whole error message confusing and leads you to believe it failed because Numpy is not installed instead of the fact it was an assertion error.


Improved error when (empty tuple) is passed to or When using as a context manager, you can pass an exception type or tuple of exception types; it's then an error if no exception is raised or if the exception raised is not an instance of the expected type(s). The same logic applies to , which has a near-identical API. The problem is that if you pass the empty tuple , this will always result in an error: even if an exception is raised, it can't be an instance of ! I think we should explicitly check tuple inputs, and raise a more helpful error message if they're empty. For example: "Passing is an error, because it's impossible to raise an exception which is not an instance of any type. Raising exceptions is already understood as failing the test, so you don't need any special code to say 'this should never raise an exception'." (for bonus points, should have the same message, with instead of ) The same logic, and same error message, applies to the argument to . "Passing is an error, because it's impossible to emit a warning which is not an instance of any type. To assert that no warnings are emitted, use <whatever we come up with for


Test functions that return non-None should raise a warning/error Consider this test: Did you spot the error? The second parametrization has a typo, is 9, not 8. But this test actually doesn't test anything, because it returns the assertion rather than asserting it. This is a common enough mistake, and it wouldn't normally be a problem except that it can silently cause false positives in test suites. I propose that test functions that return anything except None fail with a message that cues users that they probably meant to assert rather than return. This feature could be disabled (or enabled, if there are backwards-compatibility issues) via a config flag if necessary.


add getfeaturenames to CategoricalEncoder We should add a ` to the new CategoricalEncoder, as discussed . I think it would be good to be consistent with the PolynomialFeature which allows passing in original feature names to map them to new feature names. Also see .


linearmodel.RidgeClassifierCV's Parameter storecvvalues issue Parameter storecvvalues error on sklearn.linearmodel.RidgeClassifierCV import numpy as np from sklearn import linearmodel as lm #test database n = 100 x = (n, 30) y = (size = n) rr = lm.RidgeClassifierCV(alphas = (0.1, 1000, 0.1), normalize = True, storecvvalues = True).fit(x, y) Expected to get the usual ridge regression model output, keeping the cross validation predictions as attribute. TypeError: init() got an unexpected keyword argument 'storecvvalues' lm.RidgeClassifierCV actually has no parameter storecvvalues, even though some attributes depends on it. Windows-10-10.0.-SP0 Python 3.6.3 (default, Oct 15 2017, 03:27:45) [MSC v.1900 64 bit (AMD64)] NumPy 1.13.3 SciPy 0.19.1 Scikit-Learn 0.19.1 Add storecvvalues boolean flag support to RidgeClassifierCV Add storecvvalues support to RidgeClassifierCV - documentation claims that usage of this flag is possible: While actually usage of this flag gives


BUG Inconsistent f1score behavior when combining label indicator input with labels attribute When using label indicator inputs for ypred and ytrue, metrics.f1score calculates the macro average over all label-specific f-scores whenever the labels parameter includes column index 0. It should only average over the label-specific scores indicated by the labels parameter, as it does when 0 is not present in the labels parameter. <!-- Instructions For Filing a Bug: --<!-- Please paste or specifically describe the actual output or traceback. --Windows-7-6.1.7601-SP1 Python 3.5.3 (default, May 15 2017, 10:43:23) [MSC v.1900 64 bit (AMD64)] NumPy 1.13.1 SciPy 0.19.0 Scikit-Learn 0.19.0 <!-- Thanks for contributing! --


TfidfVectorizer dtype argument ignored TfidfVectorizer's fit/fittransform output is always np.float64 instead of the specified dtype FitFailedWarning raised by cross validation could do with better message Current message says "Classifier fit failed" but the estimator is not necessarily a classifier. (Perhaps that's too pedantic of me...) is not technically the best way to display an error message. We could either use and include the whole traceback; or we can use to print it properly (though I think this is the same as ). Another thing we can consider, now that provides structured results to and , is to store the full traceback in some array of .


integers in RidgeCV alpha making one of the alphas a float fixes the problem. This should be handled internally. Python3.6 integers in RidgeCV alpha making one of the alphas a float fixes the problem. This should be handled internally. Python3.6


loadsampleimages uses deprecated imread DeprecationWarning: is deprecated! is deprecated in SciPy 1.0.0, and will be removed in 1.2.0.


Add common test to ensure all(predict(X[mask]) == predict(X)[mask]) I don't think we currently test that estimator predictions/transformations are invariant whether performed in batch or on subsets of a dataset. For some fitted estimator , data and any boolean mask of length , we need: where is any of {, , , , }. Testing that predictions for individual samples match the predictions across the dataset might be sufficient. This should be to common tests at Indeed, reports that this is broken for one-vs-one classification. :'(


Polynomial Features for sparse data I'm not sure if that came up before but PolynomialFeatures doesn't support sparse data, which is not great. Should be easy but I haven't checked ;)


[RFC] Dissociate NaN and Inf when considering forceallfinite in checkarray Due to changes proposed in , it seems that as currently a main limitation. will force both and to be rejected. If preprocessing methods (whenever this is possible) should let pass , this argument is not enough permissive. Before to implement anything, I think it could be good to have some feedback on the way to go. I see the following solutions: could still accept a bool to preserve the behaviour. Additionally, it could accept an to filter only . proposes to have an additional argument . was worried that it makes to complex. a private function (similarly to removing the numpy version checking) in the which can be shared between the preprocessing methods. They are the solutions that I have in mind for the moment but anything else is welcomed. I would be grateful for any insight.


Move imputation out of preprocessing While we're considering additional imputers, I've wondered whether preprocessing is the right place for it. Yes, it is a preprocessing step before other learning, but it often makes use of other supervised and unsupervised learners and hence is a learning task of its own. And preprocessing is getting a bit cramped. We could also do as with other models and have imputers appear in modules on the basis of how they work rather than function: could appear in neighbors for instance. could appear where..? And the basic in dummy? probably not. In practice I think it is more useful for users to , akin to our clusterers and decomposition, and unlike our predictors and outlier detectors that are grouped by algorithm.


checkarray(X, dtype='numeric') should fail if X has strings Currently, dtype='numeric' is defined as "dtype is preserved unless is object". This seems overly lenient and strange behaviour, as in where shows that works without error and produces an array of strings! This behaviour is not tested and it's hard to believe that it is useful and intended. Perhaps we need a deprecation cycle, but I think dtype='numeric' should raise an error, or attempt to coerce, if the data does not actually have a numeric, real-valued dtype. checkarray(X, dtype='numeric') should fail if X has strings Currently, dtype='numeric' is defined as "dtype is preserved unless is object". This seems overly lenient and strange behaviour, as in where shows that works without error and produces an array of strings! This behaviour is not tested and it's hard to believe that it is useful and intended. Perhaps we need a deprecation cycle, but I think dtype='numeric' should raise an error, or attempt to coerce, if the data does not actually have a numeric, real-valued dtype.


LabelEncoder transform fails for empty lists (for certain inputs) Python 3.6.3, scikit_learn 0.19.1 Depending on which datatypes were used to fit the LabelEncoder, transforming empty lists works or not. Expected behavior would be that empty arrays are returned in both cases.


Deprecate Imputer with axis=1 After having tried to deal with a few issues related to extending behaviour, I believe we should be removing the parameter from . It seems a strange feature to support in a machine learning context, except perhaps where the features represent something like a time series. It is not stateful and can be performed with a FunctionTransformer. (We could even provide a function, if we felt it necessary, which would roughly be defined as .) It complicates the implementation, which already has a bunch of weird edge-cases (to handle sparse data with missing indicated by 0 which is an inefficient use of a sparse data structure; and to handle non-NaN missingness indicators), unnecessarily. It is often nonsensical to extend further features to the case. Do others agree? [MRG+1] Deprecate ` argument Deprecated the argument on the class.


Allow nsamples to be a tuple in makeblobs I'd like makeblobs to accept lists or tuples for nsamples to generate imbalanced classes. Could be used here for example: http://scikit-


ElasticNet overwrites X even with copyX=True The function of an , called with , overwrites X, even when : ElasticNet overwrites X even with copyX=True The function of an , called with , overwrites X, even when : [MRG] FIX ElasticNet overwrites X even with copy_X=True Made changes as suggested by please review and suggest changes


Shape of wrong for linearmodel.Lasso when using <!-- If your issue is a usage question, submit it here instead: StackOverflow with the scikit-learn tag: Mailing List: For more information, see User Questions: http://scikit- --<!-- Instructions For Filing a Bug: --Shape of wrong for linearmodel.Lasso when using Example: the second snippet should not raise, but it does. The first snippet is ok. I pasted it as a reference Linux-3.2.0-4-amd64-x8664-with-debian-7.11 ('Python', '2.7.3 (default, Mar 13 2014, 11:03:55) \n[GCC 4.7.2]') ('NumPy', '1.13.3') ('SciPy', '0.19.1') ('Scikit-Learn', '0.18.2') <!-- Thanks for contributing! --[MRG] Shape of wrong for linearmodel.Lasso when using <!-- Thanks for contributing a pull request! Please ensure you have taken a look at the contribution guidelines: --


no error on CountVectorizer(ngramrange=(2, 1)) I think if ngramrange[0] is greater than ngram_range[1] we should throw an error. Not sure what the current behavior is.


weighted KDE Not sure this is the correct place, but I would very much appreciate the ability to pass a weight for each sample in kde density estimation. There exits a adapted version of : weighted KDE Not sure this is the correct place, but I would very much appreciate the ability to pass a weight for each sample in kde density estimation. There exits a adapted version of :


fowlkesmallowsscore returns RuntimeWarning when variables get too big <!-- If your issue is a usage question, submit it here instead: StackOverflow with the scikit-learn tag: Mailing List: For more information, see User Questions: http://scikit- --<!-- Instructions For Filing a Bug: --<!-- Example: Joblib Error thrown when calling fit on LatentDirichletAllocation with evaluateevery 0--sklearn\metrics\cluster\ return tk / (pk qk) if tk != 0. else 0. This line produces RuntimeWarning: overflow encountered in intscalars when (pk qk) is bigger than 2*32, thus bypassing the int32 limit. Any code when pk and qk gets too big. <!-- Example: If the code is too long, feel free to put it in a public gist and link it in the issue: --<!-- Example: No error is thrown. Please paste or describe the expected results.--Be able to calculate tk / (pk qk) and return a float. <!-- Please paste or specifically describe the actual output or traceback. --it returns 'nan' instead. I propose to use (tk / pk) * (tk / qk) instead, which gives same result and ensuring not bypassing int32 <!-- Please run the following snippet and paste the output below. import platform; print(platform.platform()) import sys; print("Python", sys.version) import numpy; print("NumPy", numpy.version) import scipy; print("SciPy", scipy.version) import sklearn; print("Scikit-Learn", sklearn.version) --18.1 <!-- Thanks for contributing! --


In Gaussian mixtures, when ninit 1, the lowerbound is not always the max In Gaussian mixtures, when is set to any value greater than 1, the is not the max lower bound across all initializations, but just the lower bound of the last initialization. The bug can be fixed by adding the following line just before in : The test that should have caught this bug is in , but it just does a single test, so it had a 50% chance of missing the issue. It should be updated to try many random states. No error. In Gaussian mixtures, when ninit 1, the lowerbound is not always the max In Gaussian mixtures, when is set to any value greater than 1, the is not the max lower bound across all initializations, but just the lower bound of the last initialization. The bug can be fixed by adding the following line just before in : The test that should have caught this bug is in , but it just does a single test, so it had a 50% chance of missing the issue. It should be updated to try many random states. No error.


No warning when LogisticRegression does not converge <!-- If your issue is a usage question, submit it here instead: StackOverflow with the scikit-learn tag: Mailing List: For more information, see User Questions: http://scikit- --<!-- Instructions For Filing a Bug: --<!-- Example: Joblib Error thrown when calling fit on LatentDirichletAllocation with evaluateevery 0--I've run LogisticRegressionCV on the Wisconsin Breast Cancer data, and the output of was 100 for all but 1 of the variables. The default of 100 iterations was probably not sufficient in this case. Should there not be some kind of warning? I have done some tests and ~3000 iterations was probably a better choice for maxiter... <!-- Example: If the code is too long, feel free to put it in a public gist and link it in the issue: --<!-- Example: No error is thrown. Please paste or describe the expected results.--Some kind of error to be shown. E.g: "result did not converge, try increasing the maximum number of iterations (maxiter)" <!-- Please run the following snippet and paste the output below. import platform; print(platform.platform()) import sys; print("Python", sys.version) import numpy; print("NumPy", numpy.version) import scipy; print("SciPy", scipy.version) import sklearn; print("Scikit-Learn", sklearn.version) --import platform; print(platform.platform()) Darwin-16.7.0-x8664-i386-64bit import sys; print("Python", sys.version) ('Python', '2.7.14 (default, Oct 5 2017, 02:28:52) \n[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]') import numpy; print("NumPy", numpy.version) ('NumPy', '1.13.3') import scipy; print("SciPy", scipy.version) ('SciPy', '1.0.0') import sklearn; print("Scikit-Learn", sklearn.version) ('Scikit-Learn', '0.19.1') <!-- Thanks for contributing! --


Setting idf is impossible <!-- Instructions For Filing a Bug: --Rather than a bug i guess that would go as a sort of "enhancement proposition" ? I'm currently trying to persist a by basically saving its parameters in a mongoDB database and then rebuilding it alike. This technique works for but simply blocks for as there is no way to set . Is there any actual architectural reason why setting this attributes raise an error ? if yes, do you have an idea for a workaround ? I obviously want to avoid keeping the matrix on which it has been fitted as it would completely mess up the architecture (i believe that the saving/loading process should be separated from the whole treatment/learning process and trying to keep both would mean having to propagate a dirty return) functioning example on CountVectorizer This might not seem very impressive, but dictionnaries can be stored inside of mongoDB databases, which means that you can basically restore the or at least an identical copy of it by simply storing and the output of . Now the incriminated piece of code I would expect that at least one would work. However, both return an error. In the first case, it seems logical, as there is no idf/idf_ parameter In the second case, i suppose that encapsulation forbids the direct setting I think that being able to reproduce a fitted object (even if it is only for non-classifier objects) without having to recompute it at each launch would benefit a lot of applications. I'm currently developping a RestAPI that has to do heavy computations on data before feeding it to the vectorizer, having to relearn the whole model with each computing is very slow, and means i have to currently wait up to half an hour for modifications that are sometimes about 1 line of code. Windows-10-10.0. ('Python', '2.7.11 (default, Feb 16 2016, 09:58:36) [MSC v.1500 64 bit (AMD64)]') ('NumPy', '1.11.0') ('SciPy', '0.17.1') ('Scikit-Learn', '0.17.1') <!-- Thanks for contributing! --


CountVectorizer's getfeaturenames raise not NotFittedError when the vocabulary parameter is provided If you initialize a and try to perform a transformation without training you will get a exception. On the other hand if you provide the at the initialization of the vectorizer you could transform a corpus without a prior training, right? The 's calls method which sets the instance variable. In the same manner I believe that the method should not raise if the vocabulary parameter is provided but the vectorizer has not been trained.


MultiLabelBinarizer breaks when seeing unseen there be an option to handle this instead? <!-- Instructions For Filing a Bug: --I am not sure if it's intended for MultiLabelBinarizer to fit and transform only seen data or not. However, there are many times that it is not possible/not in our interest to know all of the classes that we're fitting at training time. For convenience, I am wondering if there should be another parameter that allows us to ignore the unseen classes by just setting them to 0? Example: Result: array([[1, 0, 0], [0, 1, 0], [0, 0, 0]]) (the current version 0.19.0 would say ) I can open a PR for this if this is a desired behavior. Others also have similar issue:


warnondtype with DataFrame No warning is thrown Linux-4.4.0-116-generic-x8664-with-debian-stretch-sid Python 3.6.3 (default, Nov 3 2017, 19:19:16) [GCC 7.2.0] NumPy 1.13.1 SciPy 0.19.1 Scikit-Learn 0.20.dev0 Pandas 0.21.0 warnondtype with DataFrame No warning is thrown Linux-4.4.0-116-generic-x8664-with-debian-stretch-sid Python 3.6.3 (default, Nov 3 2017, 19:19:16) [GCC 7.2.0] NumPy 1.13.1 SciPy 0.19.1 Scikit-Learn 0.20.dev0 Pandas 0.21.0


[RandomizedSearchCV] Do not enforce that niter is less than or equal to size of search space Instantiating with greater than the size of (i.e. the product of the length of each distribution/array in the grid) will fail with an exception at . This is a bit annoying for me because I have an app where I'm letting the user specify the number of iterations to run from the command line, also I've been fiddling around with the param grid so keeps changing. I don't want to have to work out the exact grid size when it goes below, say, 50; if I specify that should be interpreted as an upper bound on the number of iterations. Would it be possible to add an option (off by default) to the constructor specifying whether to throw in such cases? e.g. By passing (the option would default to )


Warm start bug when fitting a LogisticRegression model on binary outcomes with . <!-- If your issue is a usage question, submit it here instead: StackOverflow with the scikit-learn tag: Mailing List: For more information, see User Questions: http://scikit- --<!-- Instructions For Filing a Bug: --Bug when fitting a LogisticRegression model on binary outcomes with multiclass='multinomial' when using warm start. Note that it is similar to the issue here i.e. only using a 1D object on binary outcomes even when using as opposed to a 2D object. <!-- Example: If the code is too long, feel free to put it in a public gist and link it in the issue: --from sklearn.linearmodel import LogisticRegression import sklearn.metrics import numpy as np # Set up a logistic regression object lr = LogisticRegression(C=, multiclass='multinomial', solver='sag', tol=0.0001, warmstart=True, verbose=0) # Set independent variable values Z = ([ [ 0. , 0. ], [ 1., 0. ], [ 1., -0.], [-0., -0.], [ 1., 1.], [-0., -1.], [-1., -0.], [ 2. , -0.], [-0., -1.], [ 2., -0.], [-1., 2.], [-1., 2. ], [ 2., -1.], [ 0., -0.], [ 1., 0.], [ 1., -0.], [ 0., 1.], [-0., -0.], [-1., -0.], [-1. , 0.]])


# Set dependant variable values Y = ([1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1], dtype=np.int32) # First fit model normally (Z, Y) p = lr.predictproba(Z) print(sklearn.metrics.logloss(Y, p)) # ... print(lr.intercept) print() # Now fit model after a warm start (Z, Y) p = lr.predictproba(Z) print(sklearn.metrics.logloss(Y, p)) # ... print(lr.intercept) print() The predictions should be the same as the model converged the first time it was run. The predictions are different. In fact the more times you re-run the fit the worse it gets. This is actually the only reason I was able to catch the bug. It is caused by the line here w0[:, [1]] = coef As is , but is , this causes the value to be broadcast into the . This some sort of singularity issue when training resulting in worse performance. Note that had it not done exactly this i.e. was simply initialised by some random values, this bug would be very hard to catch because of course each time the model would converge just not as fast as one would hope when warm starting. The fix I believe is very easy, just need to swap the previous line to if nclasses == 1: w0[0, [1]] = -coef # Be careful to get these the right way around w0[1, [1]] = coef else: w0[:, [1]] = coef <!-- Please run the following snippet and paste the output below.


import platform; print(platform.platform()) import sys; print("Python", sys.version) import numpy; print("NumPy", numpy.version) import scipy; print("SciPy", scipy.version) import sklearn; print("Scikit-Learn", sklearn.version) --Linux-4.13.0-37-generic-x86_64-with-Ubuntu-16.04-xenial Python 3.5.2 (default, Nov 23 2017, 16:37:01) NumPy 1.14.2 SciPy 1.0.0 Scikit-Learn 0.20.dev0 (built from latest master) <!-- Thanks for contributing! --


Missing parameter validation in Neighbors estimator for float n_neighbors This should be caught earlier and a more helpful error message should be raised (or we could be lenient and cast to integer, but I think a better error might be better). We need to make sure that also works.


OneHotEncoder does not output scipy sparse matrix of given dtype OneHotEncoder ignores the specified dtype in the construction of the sparse array when mixed input data are passed, i.e with both categorical and real data type Platform: Linux-4.13.0-38-generic-x86_64-with-debian-stretch-sid Python: 3.6.3 (default, Oct 13 2017, 12:02:49) [GCC 7.2.0] NumPy: NumPy SciPy: SciPy 1.0.1 Scikit-Learn: Scikit-Learn 0.19.1


FunctionTransformer should not convert DataFrames to arrays by default I would expect a common use of FunctionTransformer is to apply some function to a Pandas DataFrame, ideally using its own methods or accessors. As noted in , it can be easy for users to miss that they need to set validate=False to pass through a DataFrame without converting it to a NumPy array. I think it would be more user-friendly to have by default, which would pass through DataFrames to the function, but otherwise convert its input to a 2d array. For strict backwards compatibility, the default should be changed through a deprecation cycle, warning whenever using the default validation means a DataFrame is currently converted to an array. Do others agree?


catch more warnings in common tests Right now the output of travis is too large to render, partially because a lot of deprecation warnings and partially because of warnings from the common tests. The common tests should catch all the deprecation warnings and probably also convergence warnings or numerical warnings (we decrease the number of iterations for faster testing).


output options? Is it possible to add output options to http://scikit- It would be really useful to have a output or output. Right now it outputs as a string that must be printed but it's difficult to use the results. I can make a quick helper script if that could be useful? [MRG] Classification report Dict-of-Dicts output <!-- Thanks for contributing a pull request! Please ensure you have taken a look at the contribution guidelines: --<!-- Example: -- This PR adds an option of returning the classification report in the form of a Dictionary of Dictionaries. Will add tests for the code, if the code is approved. <!-- Please be aware that we are a loose team of volunteers so patience is necessary; assistance handling other issues is very welcome. We value all user contributions, no matter how minor they are. If we are slow to review, either the pull request needs some benchmarking, tinkering, convincing, etc. or more likely the reviewers are simply busy. In either case, we ask for your understanding during the review process. For more information, see our FAQ on this topic: http://scikit- Thanks for contributing! --


Consistency issue in StandardScaler There is an issue of consistency with with and between the sparse and dense case. it make sense to support this case. It will return the identity matrix which is not the use case for the . If we wish a transformer to do so, one should use the I assume. we consider this behaviour normal, we need to: In the dense case, force to be after each iteration of . In the sparse case, compute the non-NaNs values and update which is not computed. It leads currently to an error if calling twice (i.e. will fail). IMO, we should make a checking at raise an error. WDYT?


minmaxscale does not ignore NaNs The class ignore NaNs. Its counterpart function does not. The needs to add the option . implement the tests and this fix. However, it should be done in another proper PR.


randomizedsvd is slow for dokmatrix and lilmatrix (and its object-oriented interface, ) is extremely slow for certain types of sparse matrix. Either all sparse matrices should be processed in roughly the same amount of time, or a warning should be printed. silently takes up to 50x longer than necessary. Windows-10-10.0.-SP0 Python 3.6.0 (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)] NumPy 1.14.4 SciPy 1.1.0 Scikit-Learn 0.19.1 Also tested on: Linux-4.16.11-1-ARCH-x8664-with-arch-Arch-Linux Python 3.6.5 (default, May 11 2018, 04:00:52) [GCC 8.1.0] NumPy 1.14.5 SciPy 1.1.0 Scikit-Learn 0.19.1


Should mixture models have a clusterer-compatible interface Mixture models are currently a bit different. They are basically clusterers, except they are probabilistic, and are applied to inductive problems unlike many clusterers. But they are unlike clusterers in API: they have an parameter, with identical purpose to they do not store the of the training data they do not have a method And they are almost entirely documented separately. Should we make the MMs more like clusterers?


Retrieving time to refit the estimator in BaseSearchCV Basically, I'm trying to figure out how much time it takes to refit the best model on the full data after doing grid/random search. What I can so far do is retrieve the time it takes to fit and score each model: In case I run this on a single core, I could time the whole search procedure and subtract the time it took to fit the single folds during hyperparameter optimization. Nevertheless, this isn't possible any more when setting . Thus, it would be great to have an attribute which is simply the time it took to refit the best model. Usecase: for we want to support uploading the results of hyperparameter optimization, including the time it takes to do the hyperparameter optimization.


BaseCompostion.setparams broken where there are no estimators raises an error when the composition has no estimators. This is a marginal case, but it might be interesting to support alongside .


ValueError: assignment destination is read-only, when paralleling with njobs 1 When I run with njobs 1, there is a chance to raise exception . The code is shown as follow: The bigger is, the higher chance get. When is small (lower than 2000, I verified), everything works fine. Once is bigger than 2000, there is a chance to get the exception. When is bigger than 5000, it is 100% raised. My version infor: OS: OS X 10.11.1 python: Python 2.7.10 |Anaconda 2.2.0 numpy: 1.10.1 sklearn: 0.17 The full error information is shown as follow


Cryptic error in imputers due to missing checking in getmask By working on the it seems that there is a missing checking between and dtype: In short, is raised by equal in case of numeric and string mixed dtype. We should put a check in which is shared across classes.


BUG: SimpleImputer gives wrong result on sparse matrix with explicit zeros The current implementation of the can't deal with zeros stored explicitly in sparse matrix. Even when stored explicitly, we'd expect that all zeros are treating equally, right ? See for example the code below: Whereas the expected result would be


IsolationForest contamination deprecation in init not in fit need to move the deprecation and fix the tests.


For probabilistic scorers, LogisticRegressionCV(multiclass='multinomial') uses OvR to calculate scores Description: For scorers such as that use to get probability estimates out of a classifier, the predictions used to generate the scores for do not seem to be the same predictions as those generated by the method of . The former uses a single logistic function and normalises (one-v-rest approach), whereas the latter uses the softmax function (multinomial approach). This appears to be because the instance supplied to the scoring function at line 955 of within the helper function , () , is initialised, () , without a multiclass argument, and so takes the default, which is . It seems like altering L922 to read so that the instance supplied to the scoring function at line 955 inherits the option specified in would be a fix, but I am not a coder and would appreciate some expert insight! Likewise, I do not know whether this issue exists for other classifiers/regressors, as I have only worked with Logistic Regression. Minimal example: Versions: Linux-4.4.0-72-generic-x8664-with-Ubuntu-14.04-trusty Python 2.7.6 NumPy 1.12.0 SciPy 0.18.1 Scikit-learn 0.18.1 [WIP] fixed bug in logregscoringpath <!-- Thanks for contributing a pull request! Please ensure you have taken a look at the contribution guidelines: --<!-- Example: -- In logregscoringpath method, constructor of LogisticRegression accepted only fitintercept as argument, which caused the bug explained in the issue above. As suggested, adding multiclass as argument when creating logistic regression object, solves the problem for multiclass case. After that, it seems like other similar parameters must be passed as arguments to logistic regression constructor. Also, changed interceptscaling default value to float Tested on the code provided in the issue by with various arguments on linearmodel.logistic.logregscoringpath and linearmodel.LogisticRegression, seems ok. Probably needs more testing. <!-- Please be aware that we are a loose team of volunteers so patience is necessary; assistance handling other issues is very welcome. We value all user contributions, no matter how minor they are.


If we are slow to review, either the pull request needs some benchmarking, tinkering, convincing, etc. or more likely the reviewers are simply busy. In either case, we ask for your understanding during the review process. For more information, see our FAQ on this topic: http://scikit- Thanks for contributing! --


Add sklearn.showversions() similar to pandas.showversions (with numpy blas binding info) Some numeric issues are related to the specific blas that numpy is using. I'm wondering if it makes sense to add the relevant ` invocations to the template to make it easier for people to report.


silhouettesamples gives incorrect result from precomputed distance matrix with diagonal entries silhouettesamples gives incorrect result from precomputed distance matrix with diagonal entries. When using silhouettesamples and metric='precomputed', if the input distance matrix has non-zero values along the diagonal then the silhouette scores are incorrect. Suggested Solution Before calculating the scores the diagonal entries of a precomputed distance matrix should be set to zero. Example: [0., 0.952, 0., 0., 0., 0.] [0., 0.552, 0., 0., 0., 0.] Darwin-17.7.0-x8664-i386-64bit Python 3.6.4 (default, Jan 16 2018, 12:04:33) [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] NumPy 1.15.1 SciPy 1.1.0 Scikit-Learn 0.20.0


OPTICS: self.coredistances inconsistent with documentation&R implementation In the doc, we state that `, but it's not the case. Result from scikit-learn: Result from R:


OneHotEncoder throws unhelpful error messages when tranform called prior to fit <!-- If your issue is a usage question, submit it here instead: StackOverflow with the scikit-learn tag: Mailing List: For more information, see User Questions: http://scikit- --<!-- Instructions For Filing a Bug: --<!-- Example: Joblib Error thrown when calling fit on LatentDirichletAllocation with evaluateevery 0--OneHotEncoder throws an instead of a when tranform is called prior to fit if is called prior to being fit an is thrown if includes arrays of of unicode type <!-- Example: If the code is too long, feel free to put it in a public gist and link it in the issue: --<!-- Example: No error is thrown. Please paste or describe the expected results.--<!-- Please paste or specifically describe the actual output or traceback. --<!-- Please run the following snippet and paste the output below. For scikit-learn = 0.20: import sklearn; sklearn.showversions() For scikit-learn < 0.20: import platform; print(platform.platform()) import sys; print("Python", sys.version) import numpy; print("NumPy", numpy.version) import scipy; print("SciPy", scipy.version) import sklearn; print("Scikit-Learn", sklearn.version) --<!-- Thanks for contributing! --


SkLearn method generating error with Dask DataFrames When using Dask Dataframes with SkLearn, I used to be able to just ask SkLearn for the score of any given algorithm. It would spit out a nice answer and I'd move on. After updating to the newest versions, all metrics that compute based on (ytrue, ypredicted) are failing. I've tested , , , and Work-around shown below, but it's not ideal because it requires me to cast from Dask Arrays to numpy arrays which won't work if the data is huge. I've asked Dask about it here: and they've said it's an issue with the SkLearn check, and that they won't be addressing it. It seems like it should be not super complicated to add a that says "if shape doesn't return a tuple revert to pretending shape didn't exist". If others think that sounds correct, I can attempt a pull-request, but I don't want to attempt to solve it on my own only to find out others don't deem that an acceptable solutions. Trace, MWE, versions, and workaround all in-line. MWE: Output of error: Problem occurs after upgrading as follows: Before bug: Update from conda, then bug starts: Work around:


OneHotEncoder ignore unknown error when categories are strings This bug is very specific, but it happens when you set OneHotEncoder to ignore unknown entries. and your labels are strings. The memory of the arrays is not handled safely and it can lead to a ValueError Basically, when you call the transform method it will sets all the unknown strings on your array to OneHotEncoder.categories[i][0] which is the first category alphabetically sorted given for fit If this OneHotEncoder.categories[i][0] is a long string, and the array that you want to transform has small strings, then it is impossible to fit the whole OneHotEncoder.categories[i][0] into the entries of the array we want to transform. So OneHotEncoder.categories[i][0] is truncated and this raise the ValueError. Here we should get an sparse matrix 2x4 false everywhere except at (1,1) the '22' that is known System: python: 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 ] machine: Linux-4.4.0-138-generic-x8664-with-Ubuntu-16.04-xenial executable: /usr/bin/python BLAS: macros: HAVECBLAS=None cblaslibs: openblas, openblas libdirs: /usr/lib Python deps: Cython: 0.25.2 scipy: 0.18.1 setuptools: 36.7.0 pip: 9.0.1 numpy: 1.15.2 pandas: 0.19.1 sklearn: 0.21.dev0 I already implemented a fix for this issue, where I check the size of the elements in the array before, and I cast them into objects if necessary.


ck estimator is classifier & numclasses=2 in <!-- Thanks for contributing a pull request! Please ensure you have taken a look at the contribution guidelines: --<!-- Example: See also . Please use keywords (e.g., Fixes) to create link to the issues or pull requests you resolved, so that they will automatically be closed when your pull request is merged. See --We are fixing this issue: We a test in the file that raises a ValueError if the user is either trying to use a non classifier model for a classification problem, or is using a dataset with only one class. <!-- Please be aware that we are a loose team of volunteers so patience is necessary; assistance handling other issues is very welcome. We value all user contributions, no matter how minor they are. If we are slow to review, either the pull request needs some benchmarking, tinkering, convincing, etc. or more likely the reviewers are simply busy. In either case, we ask for your understanding during the review process. For more information, see our FAQ on this topic: http://scikit- Thanks for contributing! -- BUG: Using GridSearchCV with scoring='rocauc' and GMM as classifier gives IndexError When performing grid search using GridSearchCV using ootb scoring method 'rocauc' and ootb GMM classifier from sklearn.mixture.GMM I get an index error. Code to reproduce: Sorry if the format is incorrect. First time I am posting. ERROR: File "*/python2.7/site-", line 175, in call ypred = y_pred[:, 1] IndexError: index 1 is out of bounds for axis 1 with size 1


addindicator switch in imputers For whatever imputers we have, but especially , we should have an parameter, which simply stacks a transform onto the output of the imputer's .


clone fails for parameters that are estimator types fails when one or more instance parameters are estimator types (i.e. not instances, but classes). I know this is a somewhat unusual use case, but I'm working on a project that provides wrappers for sklearn estimators () and I'd like to store the wrapped estimators as their classes - not their instances - as a parameter inside of a wrapper that behaves like an estimator itself. from sklearn.preprocessing import StandardScaler from import clone clone(StandardScaler(withmean=StandardScaler)) No error. Change , line 51 to: elif not hasattr(estimator, 'getparams') or isinstance(estimator, type): I'm not sure whether this might break stuff in other places, however. I'd happily submit a PR if this change is desired. sklearn: 0.20.0


TypeError: "iteration over a 0-d array" when trying to a pandas.Series <!-- If your issue is a usage question, submit it here instead: StackOverflow with the scikit-learn tag: Mailing List: For more information, see User Questions: http://scikit- --<!-- Instructions For Filing a Bug: --<!-- Example: Joblib Error thrown when calling fit on LatentDirichletAllocation with evaluateevery 0--When trying to call on a instance, an error is thrown with scikit-learn version 0.20.0. Version 0.19.1. works just fine. The states that the input to can be "array-like", and  should fulfill this requirement since it is a "one-dimensional ndarray". <!-- Example: If the code is too long, feel free to put it in a public gist and link it in the issue: --<!-- Example: No error is thrown. Please paste or describe the expected results.--This should be the output (as it is in version 0.19.1): A workaround is replacing with , which also yields this output. <!-- Please paste or specifically describe the actual output or traceback. --<!-- Please run the following snippet and paste the output below. For scikit-learn = 0.20: import sklearn; sklearn.showversions() For scikit-learn < 0.20: import platform; print(platform.platform()) import sys; print("Python", sys.version) import numpy; print("NumPy", numpy.version) import scipy; print("SciPy", scipy.version) import sklearn; print("Scikit-Learn", sklearn.version) --<!-- Thanks for contributing! --


makecolumntransformer has different order of arguments than ColumnTransformer I'm not sure if we discussed this or did this on purpose, but I find this very confusing. `. I guess it's too late to change this? Though we did say it's experimental and subject to change.


Fix Issue <!-- Thanks for contributing a pull request! Please ensure you have taken a look at the contribution guidelines: --<!-- Example: See also . Please use keywords (e.g., Fixes) to create link to the issues or pull requests you resolved, so that they will automatically be closed when your pull request is merged. See -- Removed the labels parameter in hammingloss function. Removed all instances of labels within the method. Since hammingloss is used only with mulitlabel input, changed len(labels) to [1]. First time contributing to open source! Please let me know what I can do to improve! <!-- Please be aware that we are a loose team of volunteers so patience is necessary; assistance handling other issues is very welcome. We value all user contributions, no matter how minor they are. If we are slow to review, either the pull request needs some benchmarking, tinkering, convincing, etc. or more likely the reviewers are simply busy. In either case, we ask for your understanding during the review process. For more information, see our FAQ on this topic: http://scikit- Thanks for contributing! --[MRG] Handling parameter labels removal from hammingloss <!-- Thanks for contributing a pull request! Please ensure you have taken a look at the contribution guidelines: --<!-- Fix Issue Please use keywords (e.g., Fixes) to create link to the issues or pull requests you resolved, so that they will automatically be closed when your pull request is merged. See --<!-- Please be aware that we are a loose team of volunteers so patience is necessary; assistance handling other issues is very welcome. We value all user contributions, no matter how minor they are. If we are slow to review, either the pull request needs some benchmarking, tinkering, convincing, etc. or more likely the reviewers are simply busy. In either case, we ask for your understanding during the review process. For more information, see our FAQ on this topic: http://scikit- Thanks for contributing! --


regression in ColumnTransformer in in 0.20.1 with columns=pd.Index This came up in one of my teaching notebooks actually (and might be in my book as well). This is very natural because columns are of type pd.Index, and so if you take some subset of columns from ` you'll now run into this error. So... 0.20.2?


traintestsplit excepting negative integers and floats The following minimal example doesn't fail: Is it a bug or indented feature? According to the docs neither of the above should make sense. See for reference for example.


Showing micro-average in classification report is confusing This is a follow up on . I don't think it makes sense to include the micro-average for multi-class classification. The three columns will always show the same value, all of which being the same as accuracy. I find that confusing. If you want to show this (I don't see why you'd want to show the same number three times), I would at least make it clear in the report that it's accuracy. IncrementalPCA fails if data size % batch size < ncomponents throws The error occurs because the last batch generated by may be smaller than . I reduced the iris data to 101 instances, so the last batch has only a single data instance, which is less than the number of components. As far as I see, none of the current unit tests run into this. ( could, if the code that raises the exception would compare with - which it should, but doesn't). Skipping the last batch if it is to small, that is, changing to fixes the problem. please confirm that this solution seems OK before I go preparing the PR and tests. No error is thrown.


Davies Bouldin measure: division by zero I'm facing a problem with the davies bouldin measure. This is the warning that I get: .local/lib/python3.7/site- RuntimeWarning: divide by zero encountered in truedivide score = (intradists[:, None] + intradists) / centroiddistances This is the implementation in sklearn: I found on stack overflow: With this implementation I don't get any warnings, but the results differ: Davies Bouldin measure: division by zero I'm facing a problem with the davies bouldin measure. This is the warning that I get: .local/lib/python3.7/site- RuntimeWarning: divide by zero encountered in truedivide score = (intradists[:, None] + intradists) / centroiddistances This is the implementation in sklearn: I found on stack overflow: With this implementation I don't get any warnings, but the results differ:


DOC: add details to QuantileTransformer documentation I think the documentation of should say how it is implemented. There is even a about it and we could take some elements of the answer. Besides I was thinking that to map to a uniform distribution, the implementation was just computing the empirical cdf of the columns but it does not seem to be the case.


fails for multioutput ensemble models with non-numeric DVs <!-- Example: Joblib Error thrown when calling fit on LatentDirichletAllocation with evaluateevery 0--Multioutput forest models assume that the dependent variables are numeric. Passing string DVs returns the following error: I'm going to take a stab at submitting a fix today, but I wanted to file an issue to document the problem in case I'm not able to finish a fix. I wrote a test based on which currently fails: No error is thrown, can run for all ensemble multioutput models <!-- Example: No error is thrown. Please paste or describe the expected results.--<!-- Please paste or specifically describe the actual output or traceback. --I replicated this error using the current master branch of sklearn (0.21.dev0). <!-- Please run the following snippet and paste the output below. For scikit-learn = 0.20: import sklearn; sklearn.showversions() For scikit-learn < 0.20: import platform; print(platform.platform()) import sys; print("Python", sys.version) import numpy; print("NumPy", numpy.version) import scipy; print("SciPy", scipy.version) import sklearn; print("Scikit-Learn", sklearn.version) --<!-- Thanks for contributing! --


Suggestion: Add support for unpenalized logistic regression provides unpenalized OLS, and , which supports , also supports . But if you want plain old unpenalized logistic regression, you have to fake it by setting in to a large number, or use from instead.


AttributeError: 'PrettyPrinter' object has no attribute 'indentat_name' There's a failing example in , and here's a piece of code causing it: With the stack trace:


ValueError not enough values to unpack (expected 5, got 0) I'm using with in sklearn v 0.20.1. MacOS Mojave. The issue traces to these two lines below, with Setting did not work, still hitting the same issue. From the trackback, I suspect that the line below could be returning None. This doesn't always happen, but only sometimes. My param search was able to run for a few rounds, and then hit this issue. The problem could be that lightgbm did not return valid results (have not verified), but either way, this error could be handled better. Does anyone have more insight into the potential cause? Thanks.


LassoLarsIC: unintuitive copyX behaviour Hi, I would like to report what seems to be a bug in the treatment of the parameter of the class. Because it's a simple bug, it's much easier to see in the code directly than in the execution, so I am not posting steps to reproduce it. As you can see here, LassoLarsIC accepts a copyX parameter. However, it also takes a copyX parameter a few lines below, in the definition of . Now there are two values (potentially contradicting each other) for copyX and each one is used once. Therefore can have a mixed behaviour. Even worse, this can be completely invisible to the user, since copyX has a default value of True. Let's assume that I'd like it to be False, and have set it to False in the initialization, . I then call and my choice will be silently overwritten. Ideally I think that copy_X should be removed as an argument in . No other estimator seems to have a duplication in class parameters and fit arguments (I've checked more than ten in the linear models module). However, this would break existing code. Therefore I propose that takes a default value of and only overwrites the existing value if the user has explicitly passed it as an argument to . I will submit a PR to that effect.


and have inconsistent default init <!-- If your issue is a usage question, submit it here instead: StackOverflow with the scikit-learn tag: Mailing List: For more information, see User Questions: http://scikit- --<!-- Instructions For Filing a Bug: --<!-- Example: Joblib Error thrown when calling fit on LatentDirichletAllocation with evaluateevery 0--and have inconsistent default init. has while has . See As suggested, we could change the default in with a deprecation process. <!-- Example: If the code is too long, feel free to put it in a public gist and link it in the issue: --<!-- Example: No error is thrown. Please paste or describe the expected results.--<!-- Please paste or specifically describe the actual output or traceback. --<!-- Please run the following snippet and paste the output below. For scikit-learn = 0.20: import sklearn; sklearn.showversions() For scikit-learn < 0.20: import platform; print(platform.platform()) import sys; print("Python", sys.version) import numpy; print("NumPy", numpy.version) import scipy; print("SciPy", scipy.version) import sklearn; print("Scikit-Learn", sklearn.version) --<!-- Thanks for contributing! --


StandardScaler fit overflows on float16 When using StandardScaler on a large float16 numpy array the mean and std calculation overflows. I can convert the array to a larger precision but when working with a larger dataset the memory saved by using float16 on smaller numbers kind of matter. The error is mostly on numpy. Adding the dtype on the mean/std calculation does it but I'm not sure if that how people here would like to do it. The normalized array


ColumnTransformer behavior for negative column indexes <!-- If your issue is a usage question, submit it here instead: StackOverflow with the scikit-learn tag: Mailing List: For more information, see User Questions: http://scikit- --<!-- Instructions For Filing a Bug: --The behavior of when negative integers are passed as column indexes is not clear. The first transformer should either raise an error or give the same result as the second transformer


MissingIndicator failed with non-numeric inputs fails with string and object type numpy arrays


Feature request: support for arbitrary bin spacing in calibration.calibrationcurve I was using , and it currently accepts an parameter to specify the number of bins to evenly partition the probability space between 0 and 1. However, I am using this in combination with a gradient boosting model in which the probabilities are very uncalibrated, and most of the predictions are close to 0. When I use the calibrated classifier, the result is very noisy because there are many data points in some bins and few, if any, in others (see example below). In the code below, I made a work-around to do what I want and show a plot of my output (in semilog space because of the skewed distribution). I haven't contributed to a large open-source project before, but if there's agreement this would be a useful feature, I would be happy to try to draft up a PR. Notice the large disparity in results between the different bins chosen. For this reason, I think the user should be able to choose the bin edges, as in numpy's or matplotlib's functions. !


sklearn.modelselection.StratifiedKFold either shuffling is wrong or documentation is misleading <!-- If your issue is a usage question, submit it here instead: StackOverflow with the scikit-learn tag: Mailing List: For more information, see User Questions: http://scikit- --<!-- Instructions For Filing a Bug: --Regarding the shuffle parameter, the documentation states: "Whether to shuffle each stratification of the data before splitting into batches". However, instead of shuffling samples within each stratum, the order of batches is shuffled. As you can see in the output below, 1 is always paired with 11, 2 with 12, 3 with 13, etc. regardless whether shuffle parameter is True or False. When shuffle=True, the batches are always the same for any randomstate, but appear in a different order. When cross-validation is performed, the results from each batch are summed and then divided by the number of batches. Changing the order of batches does not change the result. The way shuffle works now is completely useless from cross-validation perspective.


import numpy as np from sklearn.modelselection import StratifiedKFold RANDOMSEED = 1 samplesperclass = 10 X = np.linspace(0, samplesperclass2-1, samplesperclass 2) y = np.concatenate(((samplesperclass), (samplesperclass)), axis=0) print(X, '\n', y, '\n') print('\nshuffle = False\n') kfold = StratifiedKFold(nsplits=10, shuffle=False, randomstate=RANDOMSEED) result = 0 for foldn, (trainidx, testidx) in enumerate((X, y)): print(trainidx, '\n', testidx) print('\nshuffle = True, Random seed =', RANDOMSEED, '\n') kfold = StratifiedKFold(nsplits=10, shuffle=True, randomstate=RANDOMSEED) result = 0 for foldn, (trainidx, testidx) in enumerate((X, y)): print(trainidx, '\n', testidx) RANDOMSEED += 1 print('\nshuffle = True, Random seed =', RANDOMSEED, '\n') kfold = StratifiedKFold(nsplits=10, shuffle=False, randomstate=RANDOMSEED) result = 0 for foldn, (trainidx, testidx) in enumerate((X, y)): print(trainidx, '\n', testidx) <!-- Example: No error is thrown. Please paste or describe the expected results.--I expect batches to be different when Shuffle is turned on for different randomstate seeds. But they are the same <!-- Please paste or specifically describe the actual output or traceback. --[ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 19.] [1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]


shuffle = False [ 1 2 3 4 5 6 7 8 9 11 12 13 14 15 16 17 18 19] [ 0 10] [ 0 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19] [ 1 11] [ 0 1 3 4 5 6 7 8 9 10 11 13 14 15 16 17 18 19] [ 2 12] [ 0 1 2 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19] [ 3 13] [ 0 1 2 3 5 6 7 8 9 10 11 12 13 15 16 17 18 19] [ 4 14] [ 0 1 2 3 4 6 7 8 9 10 11 12 13 14 16 17 18 19] [ 5 15] [ 0 1 2 3 4 5 7 8 9 10 11 12 13 14 15 17 18 19] [ 6 16] [ 0 1 2 3 4 5 6 8 9 10 11 12 13 14 15 16 18 19] [ 7 17] [ 0 1 2 3 4 5 6 7 9 10 11 12 13 14 15 16 17 19] [ 8 18] [ 0 1 2 3 4 5 6 7 8 10 11 12 13 14 15 16 17 18] [ 9 19] shuffle = True,


Random seed = 1 [ 0 1 3 4 5 6 7 8 9 10 11 13 14 15 16 17 18 19] [ 2 12] [ 0 1 2 3 4 5 6 7 8 10 11 12 13 14 15 16 17 18] [ 9 19] [ 0 1 2 3 4 5 7 8 9 10 11 12 13 14 15 17 18 19] [ 6 16] [ 0 1 2 3 5 6 7 8 9 10 11 12 13 15 16 17 18 19] [ 4 14] [ 1 2 3 4 5 6 7 8 9 11 12 13 14 15 16 17 18 19] [ 0 10] [ 0 1 2 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19] [ 3 13] [ 0 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19] [ 1 11] [ 0 1 2 3 4 5 6 8 9 10 11 12 13 14 15 16 18 19] [ 7 17] [ 0 1 2 3 4 5 6 7 9 10 11 12 13 14 15 16 17 19] [ 8 18] [ 0 1 2 3 4 6 7 8 9 10 11 12 13 14 16 17 18 19] [ 5 15] shuffle = True,


Random seed = 2 [ 1 2 3 4 5 6 7 8 9 11 12 13 14 15 16 17 18 19] [ 0 10] [ 0 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19] [ 1 11] [ 0 1 3 4 5 6 7 8 9 10 11 13 14 15 16 17 18 19] [ 2 12] [ 0 1 2 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19] [ 3 13] [ 0 1 2 3 5 6 7 8 9 10 11 12 13 15 16 17 18 19] [ 4 14] [ 0 1 2 3 4 6 7 8 9 10 11 12 13 14 16 17 18 19] [ 5 15] [ 0 1 2 3 4 5 7 8 9 10 11 12 13 14 15 17 18 19] [ 6 16] [ 0 1 2 3 4 5 6 8 9 10 11 12 13 14 15 16 18 19] [ 7 17] [ 0 1 2 3 4 5 6 7 9 10 11 12 13 14 15 16 17 19] [ 8 18] [ 0 1 2 3 4 5 6 7 8 10 11 12 13 14 15 16 17 18] [ 9 19] System: python: 3.7.2 (default, Jan 13 2019, 12:50:01) [Clang 10.0.0 (clang-1000.11.45.


5)] executable: /usr/local/opt/python/bin/python3.7 machine: Darwin-18.2.0-x8664-i386-64bit BLAS: macros: NOATLASINFO=3, HAVECBLAS=None libdirs: cblaslibs: cblas Python deps: pip: 18.1 setuptools: 40.6.3 sklearn: 0.20.2 numpy: 1.15.2 scipy: 1.2.0 Cython: None pandas: 0.23.4 <!-- Thanks for contributing! --


KBinsDiscretizer: kmeans fails due to unsorted binedges with fails in certain situations, due to centers and consequently binedges being unsorted, which is fatal for np.digitize. A very simple way to reproduce this is to set nbins in the existing testnonuniformstrategies from to a higher value (here 5 instead of 3). In this simple example it seems like an edge case to set nbins to almost the number of data points. However I've seen this happen in productive situations with very reasonable number of bins of order log2(number of unique values of X). No error is thrown. <!-- Thanks for contributing! --KBinsDiscretizer: kmeans fails due to unsorted binedges with fails in certain situations, due to centers and consequently binedges being unsorted, which is fatal for np.digitize. A very simple way to reproduce this is to set nbins in the existing testnonuniformstrategies from to a higher value (here 5 instead of 3). In this simple example it seems like an edge case to set nbins to almost the number of data points. However I've seen this happen in productive situations with very reasonable number of bins of order log2(number of unique values of X). No error is thrown. <!-- Thanks for contributing! --


GaussianMixture predict and fitpredict disagree when ninit1 When is specified in GaussianMixture, the results of fitpredict(X) and predict(X) are often different. The unit test doesn't catch this because it does not set . No exceptions.


precisionscore shows incorrect value precisionscore shows incorrect value ([[0,0,1],[0,1,0],[0,0,1]]) B=A precisionscore(A,B, average=None) array([ 0., 1., 1.]) array([ 1., 1., 1.]) array([ 0., 1., 1.]) import platform; print(platform.platform()) Darwin-14.5.0-x8664-i386-64bit import sys; print("Python", sys.version) ('Python', '2.7.10 (default, Jul 14 2015, 19:46:27) \n[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)]') import numpy; print("NumPy", numpy.version) ('NumPy', '1.13.3') import scipy; print("SciPy", scipy.version) ('SciPy', '1.0.0') import sklearn; print("Scikit-Learn", sklearn.version) ('Scikit-Learn', '0.18.1')


Different r2score multioutput default in r2score and base.RegressorMixin We've changed multioutput default in r2score to "uniformaverage" in 0.19, but in base.RegressorMixin, we still use ` (). Also see the strange things below:


Ensure monotonic bin edges for KBinsDiscretizer strategy quantile The percentiles returned from np.percentile are monotonic up to possible numeric instabilities. Monotonicity is enforced by applying a simple maximum on subsequent values to deal with this case and increase robustness. The additional line is a no-op in almost all cases. This is unfortunate, but since there is essentially no performance impact, I guess robustness is worth the effort.