|
| 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 $(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 $FILE_LINE | cut -d" " -f1) | head -n1) |
| 41 | + OUTPUT_ROW=`printf "%-14s %-16s %s" ${TAG:-"(not released)"} $FILE_LINE $FILE` |
| 42 | + OUTPUT+=($OUTPUT_ROW) |
| 43 | + done |
| 44 | +done |
| 45 | + |
| 46 | +printf "%s\n" "${OUTPUT[@]}" | sort -V |
0 commit comments