Skip to content

Commit b64548b

Browse files
authored
Merge branch 'main' into feature/46319_locale_strftime_period
2 parents fbfefec + 0b8d8bb commit b64548b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1055
-328
lines changed

.github/ISSUE_TEMPLATE/feature_request.md

-33
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Feature Request
2+
description: Suggest an idea for pandas
3+
title: "ENH: "
4+
labels: [Enhancement, Needs Triage]
5+
6+
body:
7+
- type: checkboxes
8+
id: checks
9+
attributes:
10+
label: Feature Type
11+
description: Please check what type of feature request you would like to propose.
12+
options:
13+
- label: >
14+
Adding new functionality to pandas
15+
- label: >
16+
Changing existing functionality in pandas
17+
- label: >
18+
Removing existing functionality in pandas
19+
- type: textarea
20+
id: description
21+
attributes:
22+
label: Problem Description
23+
description: >
24+
Please describe what problem the feature would solve, e.g. "I wish I could use pandas to ..."
25+
placeholder: >
26+
I wish I could use pandas to return a Series from a DataFrame when possible.
27+
validations:
28+
required: true
29+
- type: textarea
30+
id: feature
31+
attributes:
32+
label: Feature Description
33+
description: >
34+
Please describe how the new feature would be implemented, using psudocode if relevant.
35+
placeholder: >
36+
Add a new parameter to DataFrame, to_series, to return a Series if possible.
37+
38+
def __init__(self, ..., to_series: bool=False):
39+
"""
40+
Parameters
41+
----------
42+
...
43+
44+
to_series : bool, default False
45+
Return a Series if possible
46+
"""
47+
if to_series:
48+
return Series(data)
49+
validations:
50+
required: true
51+
- type: textarea
52+
id: alternative
53+
attributes:
54+
label: Alternative Solutions
55+
description: >
56+
Please describe any alternative solution (existing functionality, 3rd party package, etc.)
57+
that would satisfy the feature request.
58+
placeholder: >
59+
Write a custom function to return a Series when possible.
60+
61+
def to_series(...)
62+
result = pd.DataFrame(...)
63+
...
64+
validations:
65+
required: true
66+
- type: textarea
67+
id: context
68+
attributes:
69+
label: Additional Context
70+
description: >
71+
Please provide any relevant Github issues, code examples or references that help describe and support
72+
the feature request.

CITATION.cff

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cff-version: 1.2.0
2+
title: 'pandas-dev/pandas: Pandas'
3+
message: 'If you use this software, please cite it as below.'
4+
authors:
5+
- name: "The pandas development team"
6+
license: BSD-3-Clause
7+
license-url: "https://github.com/pandas-dev/pandas/blob/main/LICENSE"
8+
repository-code: "https://github.com/pandas-dev/pandas"
9+
type: software
10+
url: "https://github.com/pandas-dev/pandas"

doc/source/development/contributing_codebase.rst

+186-55
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,169 @@ Writing tests
324324

325325
All tests should go into the ``tests`` subdirectory of the specific package.
326326
This folder contains many current examples of tests, and we suggest looking to these for
327-
inspiration. Please reference our :ref:`testing location guide <test_organization>` if you are unsure
328-
where to place a new unit test.
327+
inspiration. Ideally, there should be one, and only one, obvious place for a test to reside.
328+
Until we reach that ideal, these are some rules of thumb for where a test should
329+
be located.
330+
331+
1. Does your test depend only on code in ``pd._libs.tslibs``?
332+
This test likely belongs in one of:
333+
334+
- tests.tslibs
335+
336+
.. note::
337+
338+
No file in ``tests.tslibs`` should import from any pandas modules
339+
outside of ``pd._libs.tslibs``
340+
341+
- tests.scalar
342+
- tests.tseries.offsets
343+
344+
2. Does your test depend only on code in pd._libs?
345+
This test likely belongs in one of:
346+
347+
- tests.libs
348+
- tests.groupby.test_libgroupby
349+
350+
3. Is your test for an arithmetic or comparison method?
351+
This test likely belongs in one of:
352+
353+
- tests.arithmetic
354+
355+
.. note::
356+
357+
These are intended for tests that can be shared to test the behavior
358+
of DataFrame/Series/Index/ExtensionArray using the ``box_with_array``
359+
fixture.
360+
361+
- tests.frame.test_arithmetic
362+
- tests.series.test_arithmetic
363+
364+
4. Is your test for a reduction method (min, max, sum, prod, ...)?
365+
This test likely belongs in one of:
366+
367+
- tests.reductions
368+
369+
.. note::
370+
371+
These are intended for tests that can be shared to test the behavior
372+
of DataFrame/Series/Index/ExtensionArray.
373+
374+
- tests.frame.test_reductions
375+
- tests.series.test_reductions
376+
- tests.test_nanops
377+
378+
5. Is your test for an indexing method?
379+
This is the most difficult case for deciding where a test belongs, because
380+
there are many of these tests, and many of them test more than one method
381+
(e.g. both ``Series.__getitem__`` and ``Series.loc.__getitem__``)
382+
383+
A) Is the test specifically testing an Index method (e.g. ``Index.get_loc``,
384+
``Index.get_indexer``)?
385+
This test likely belongs in one of:
386+
387+
- tests.indexes.test_indexing
388+
- tests.indexes.fooindex.test_indexing
389+
390+
Within that files there should be a method-specific test class e.g.
391+
``TestGetLoc``.
392+
393+
In most cases, neither ``Series`` nor ``DataFrame`` objects should be
394+
needed in these tests.
395+
396+
B) Is the test for a Series or DataFrame indexing method *other* than
397+
``__getitem__`` or ``__setitem__``, e.g. ``xs``, ``where``, ``take``,
398+
``mask``, ``lookup``, or ``insert``?
399+
This test likely belongs in one of:
400+
401+
- tests.frame.indexing.test_methodname
402+
- tests.series.indexing.test_methodname
403+
404+
C) Is the test for any of ``loc``, ``iloc``, ``at``, or ``iat``?
405+
This test likely belongs in one of:
406+
407+
- tests.indexing.test_loc
408+
- tests.indexing.test_iloc
409+
- tests.indexing.test_at
410+
- tests.indexing.test_iat
411+
412+
Within the appropriate file, test classes correspond to either types of
413+
indexers (e.g. ``TestLocBooleanMask``) or major use cases
414+
(e.g. ``TestLocSetitemWithExpansion``).
415+
416+
See the note in section D) about tests that test multiple indexing methods.
417+
418+
D) Is the test for ``Series.__getitem__``, ``Series.__setitem__``,
419+
``DataFrame.__getitem__``, or ``DataFrame.__setitem__``?
420+
This test likely belongs in one of:
421+
422+
- tests.series.test_getitem
423+
- tests.series.test_setitem
424+
- tests.frame.test_getitem
425+
- tests.frame.test_setitem
426+
427+
If many cases such a test may test multiple similar methods, e.g.
428+
429+
.. code-block:: python
430+
431+
import pandas as pd
432+
import pandas._testing as tm
433+
434+
def test_getitem_listlike_of_ints():
435+
ser = pd.Series(range(5))
436+
437+
result = ser[[3, 4]]
438+
expected = pd.Series([2, 3])
439+
tm.assert_series_equal(result, expected)
440+
441+
result = ser.loc[[3, 4]]
442+
tm.assert_series_equal(result, expected)
443+
444+
In cases like this, the test location should be based on the *underlying*
445+
method being tested. Or in the case of a test for a bugfix, the location
446+
of the actual bug. So in this example, we know that ``Series.__getitem__``
447+
calls ``Series.loc.__getitem__``, so this is *really* a test for
448+
``loc.__getitem__``. So this test belongs in ``tests.indexing.test_loc``.
449+
450+
6. Is your test for a DataFrame or Series method?
451+
452+
A) Is the method a plotting method?
453+
This test likely belongs in one of:
454+
455+
- tests.plotting
456+
457+
B) Is the method an IO method?
458+
This test likely belongs in one of:
459+
460+
- tests.io
461+
462+
C) Otherwise
463+
This test likely belongs in one of:
464+
465+
- tests.series.methods.test_mymethod
466+
- tests.frame.methods.test_mymethod
467+
468+
.. note::
469+
470+
If a test can be shared between DataFrame/Series using the
471+
``frame_or_series`` fixture, by convention it goes in the
472+
``tests.frame`` file.
473+
474+
7. Is your test for an Index method, not depending on Series/DataFrame?
475+
This test likely belongs in one of:
476+
477+
- tests.indexes
478+
479+
8) Is your test for one of the pandas-provided ExtensionArrays (``Categorical``,
480+
``DatetimeArray``, ``TimedeltaArray``, ``PeriodArray``, ``IntervalArray``,
481+
``PandasArray``, ``FloatArray``, ``BoolArray``, ``StringArray``)?
482+
This test likely belongs in one of:
483+
484+
- tests.arrays
485+
486+
9) Is your test for *all* ExtensionArray subclasses (the "EA Interface")?
487+
This test likely belongs in one of:
488+
489+
- tests.extension
329490

330491
Using ``pytest``
331492
~~~~~~~~~~~~~~~~
@@ -388,6 +549,8 @@ xfail is not to be used for tests involving failure due to invalid user argument
388549
For these tests, we need to verify the correct exception type and error message
389550
is being raised, using ``pytest.raises`` instead.
390551

552+
.. _contributing.warnings:
553+
391554
Testing a warning
392555
^^^^^^^^^^^^^^^^^
393556

@@ -405,6 +568,27 @@ If a warning should specifically not happen in a block of code, pass ``False`` i
405568
with tm.assert_produces_warning(False):
406569
pd.no_warning_function()
407570
571+
If you have a test that would emit a warning, but you aren't actually testing the
572+
warning itself (say because it's going to be removed in the future, or because we're
573+
matching a 3rd-party library's behavior), then use ``pytest.mark.filterwarnings`` to
574+
ignore the error.
575+
576+
.. code-block:: python
577+
578+
@pytest.mark.filterwarnings("ignore:msg:category")
579+
def test_thing(self):
580+
pass
581+
582+
If you need finer-grained control, you can use Python's
583+
`warnings module <https://docs.python.org/3/library/warnings.html>`__
584+
to control whether a warning is ignored or raised at different places within
585+
a single test.
586+
587+
.. code-block:: python
588+
589+
with warnings.catch_warnings():
590+
warnings.simplefilter("ignore", FutureWarning)
591+
408592
Testing an exception
409593
^^^^^^^^^^^^^^^^^^^^
410594

@@ -570,59 +754,6 @@ preferred if the inputs or logic are simple, with Hypothesis tests reserved
570754
for cases with complex logic or where there are too many combinations of
571755
options or subtle interactions to test (or think of!) all of them.
572756

573-
.. _contributing.warnings:
574-
575-
Testing warnings
576-
~~~~~~~~~~~~~~~~
577-
578-
By default, the :ref:`Continuous Integration <contributing.ci>` will fail if any unhandled warnings are emitted.
579-
580-
If your change involves checking that a warning is actually emitted, use
581-
``tm.assert_produces_warning(ExpectedWarning)``.
582-
583-
584-
.. code-block:: python
585-
586-
import pandas._testing as tm
587-
588-
589-
df = pd.DataFrame()
590-
with tm.assert_produces_warning(FutureWarning):
591-
df.some_operation()
592-
593-
We prefer this to the ``pytest.warns`` context manager because ours checks that the warning's
594-
stacklevel is set correctly. The stacklevel is what ensure the *user's* file name and line number
595-
is printed in the warning, rather than something internal to pandas. It represents the number of
596-
function calls from user code (e.g. ``df.some_operation()``) to the function that actually emits
597-
the warning. Our linter will fail the build if you use ``pytest.warns`` in a test.
598-
599-
If you have a test that would emit a warning, but you aren't actually testing the
600-
warning itself (say because it's going to be removed in the future, or because we're
601-
matching a 3rd-party library's behavior), then use ``pytest.mark.filterwarnings`` to
602-
ignore the error.
603-
604-
.. code-block:: python
605-
606-
@pytest.mark.filterwarnings("ignore:msg:category")
607-
def test_thing(self):
608-
...
609-
610-
If the test generates a warning of class ``category`` whose message starts
611-
with ``msg``, the warning will be ignored and the test will pass.
612-
613-
If you need finer-grained control, you can use Python's usual
614-
`warnings module <https://docs.python.org/3/library/warnings.html>`__
615-
to control whether a warning is ignored / raised at different places within
616-
a single test.
617-
618-
.. code-block:: python
619-
620-
with warnings.catch_warnings():
621-
warnings.simplefilter("ignore", FutureWarning)
622-
# Or use warnings.filterwarnings(...)
623-
624-
Alternatively, consider breaking up the unit test.
625-
626757

627758
Running the test suite
628759
----------------------

doc/source/development/index.rst

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ Development
1818
contributing_codebase
1919
maintaining
2020
internals
21-
test_writing
2221
debugging_extensions
2322
extending
2423
developer

0 commit comments

Comments
 (0)