DEPR: Adding script to detect deprecated features by version (#6581) … · pandas-dev/pandas@1265f66 (original) (raw)

``

1

`+

#!/bin/bash

`

``

2

+

``

3

`+

Check all future warnings in Python files, and report them with the version

`

``

4

`+

where the FutureWarning was added.

`

``

5

`+

`

``

6

`+

This is useful to detect features that have been deprecated, and should be

`

``

7

`+

removed from the code. For example, if a line of code contains:

`

``

8

`+

`

``

9

`+

warning.warn('Method deprecated', FutureWarning, stacklevel=2)

`

``

10

`+

`

``

11

`+

Which is released in Pandas 0.20.0, then it is expected that the method

`

``

12

`+

is removed before releasing Pandas 0.24.0, including the warning. If it

`

``

13

`+

is not, this script will list this line, with the version 0.20.0, which

`

``

14

`+

will make it easy to detect that it had to be removed.

`

``

15

`+

`

``

16

`+

In some cases this script can return false positives, for example in files

`

``

17

`+

where FutureWarning is used to detect deprecations, or similar. The EXCLUDE

`

``

18

`+

variable can be used to ignore files that use FutureWarning, but do not

`

``

19

`+

deprecate functionality.

`

``

20

`+

`

``

21

`+

Usage:

`

``

22

`+

`

``

23

`+

$ ./list_future_warnings.sh

`

``

24

+

``

25

`+

EXCLUDE="^pandas/tests/|" # tests validate that FutureWarnings are raised

`

``

26

`+

EXCLUDE+="^pandas/util/_decorators.py$|" # generic deprecate function that raises warning

`

``

27

`+

EXCLUDE+="^pandas/util/_depr_module.py$|" # generic deprecate module that raises warnings

`

``

28

`+

EXCLUDE+="^pandas/util/testing.py$|" # contains function to evaluate if warning is raised

`

``

29

`+

EXCLUDE+="^pandas/io/parsers.py$" # implements generic deprecation system in io reading

`

``

30

+

``

31

`+

BASE_DIR="$(dirname (dirname(dirname (dirname(realpath $0)))"

`

``

32

`+

cd $BASE_DIR

`

``

33

`` +

FILES=grep -RIl "FutureWarning" pandas/* | grep -vE "$EXCLUDE"

``

``

34

`+

OUTPUT=()

`

``

35

`+

IFS=$'\n'

`

``

36

+

``

37

`+

for FILE in $FILES; do

`

``

38

`` +

FILE_LINES=git blame -sf $FILE | grep FutureWarning | tr -s " " | cut -d " " -f1,3

``

``

39

`+

for FILE_LINE in $FILE_LINES; do

`

``

40

`+

TAG=$(git tag --contains (echo(echo (echoFILE_LINE | cut -d" " -f1) | head -n1)

`

``

41

`` +

OUTPUT_ROW=printf "%-14s %-16s %s" <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>T</mi><mi>A</mi><mi>G</mi><mo>:</mo><mo>−</mo><mi mathvariant="normal">&quot;</mi><mo stretchy="false">(</mo><mi>n</mi><mi>o</mi><mi>t</mi><mi>r</mi><mi>e</mi><mi>l</mi><mi>e</mi><mi>a</mi><mi>s</mi><mi>e</mi><mi>d</mi><mo stretchy="false">)</mo><mi mathvariant="normal">&quot;</mi></mrow><annotation encoding="application/x-tex">{TAG:-&quot;(not released)&quot;} </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="mord mathnormal">A</span><span class="mord mathnormal">G</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">:</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mord">−</span><span class="mord">&quot;</span><span class="mopen">(</span><span class="mord mathnormal">n</span><span class="mord mathnormal">o</span><span class="mord mathnormal">t</span><span class="mord mathnormal">re</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">e</span><span class="mord mathnormal">a</span><span class="mord mathnormal">se</span><span class="mord mathnormal">d</span><span class="mclose">)</span><span class="mord">&quot;</span></span></span></span></span>FILE_LINE $FILE

``

``

42

`+

OUTPUT+=($OUTPUT_ROW)

`

``

43

`+

done

`

``

44

`+

done

`

``

45

+

``

46

`+

printf "%s\n" "${OUTPUT[@]}" | sort -V

`