Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions .github/actions/setup-conda/action.yml

This file was deleted.

102 changes: 57 additions & 45 deletions .github/workflows/code-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,22 @@ on:
- main
- 3.0.x

env:
ENV_FILE: environment.yml
defaults:
run:
shell: bash -euox pipefail {0}

permissions: {}

# pre-commit run by https://pre-commit.ci/
jobs:
docstring_typing_manual_hooks:
name: Docstring validation, typing, and other manual pre-commit hooks
doctest:
name: Doctests
runs-on: ubuntu-24.04
permissions:
contents: read
defaults:
run:
shell: bash -el {0}

concurrency:
# https://github.community/t/concurrecy-not-work-for-push/183068/7
group: ${{ github.event_name == 'push' && github.run_number || github.ref }}-code-checks
group: ${{ github.event_name == 'push' && github.run_number || github.ref }}-doctests
cancel-in-progress: true

steps:
Expand All @@ -37,51 +34,70 @@ jobs:
with:
fetch-depth: 0

- name: Set up Conda
uses: ./.github/actions/setup-conda

- name: Build Pandas
id: build
uses: ./.github/actions/build_pandas
- name: Create virtual environment with Pixi
uses: ./.github/actions/setup-pixi
with:
environment: "doctests"

# The following checks are independent of each other and should still be run if one fails
- name: Extra installs
# https://pytest-qt.readthedocs.io/en/latest/troubleshooting.html#github-actions-azure-pipelines-travis-ci-and-gitlab-ci-cd
run: sudo apt-get update && sudo apt-get install -y libegl1 libopengl0
- name: Build pandas
run: |
pixi run \
--environment doctests \
build-pandas \
--editable \
-Csetup-args="--werror"

- name: Run doctests
run: cd ci && ./code_checks.sh doctests
if: ${{ steps.build.outcome == 'success' && always() }}
run: pixi run --environment doctests ci-doctests

- name: Run checks on imported code
run: ci/code_checks.sh code
if: ${{ steps.build.outcome == 'success' && always() }}
- name: Run scripts tests
run: pixi run --environment doctests ci-scripts-tests

- name: Use existing environment for type checking
run: |
echo $PATH >> $GITHUB_PATH
echo "PYTHONHOME=$PYTHONHOME" >> $GITHUB_ENV
echo "PYTHONPATH=$PYTHONPATH" >> $GITHUB_ENV
if: ${{ steps.build.outcome == 'success' && always() }}
type-checking:
name: Type Checking
runs-on: ubuntu-24.04
permissions:
contents: read

concurrency:
# https://github.community/t/concurrecy-not-work-for-push/183068/7
group: ${{ github.event_name == 'push' && github.run_number || github.ref }}-typechecking
cancel-in-progress: true

- name: Typing
uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
extra_args: --verbose --hook-stage manual --all-files
if: ${{ steps.build.outcome == 'success' && always() }}
fetch-depth: 0

- name: Create virtual environment with Pixi
uses: ./.github/actions/setup-pixi
with:
environment: "typing"

- name: Build pandas
run: |
pixi run \
--environment typing \
build-pandas \
--editable \
-Csetup-args="--werror"

# - name: Use existing environment for type checking
# run: |
# echo $PATH >> $GITHUB_PATH
# echo "PYTHONHOME=$PYTHONHOME" >> $GITHUB_ENV
# echo "PYTHONPATH=$PYTHONPATH" >> $GITHUB_ENV
# if: ${{ steps.build.outcome == 'success' && always() }}

- name: Run docstring validation script tests
run: pytest scripts
if: ${{ steps.build.outcome == 'success' && always() }}
- name: Typing Checks
run: pixi run --environment typing ci-typing

asv-benchmarks:
name: ASV Benchmarks
runs-on: ubuntu-24.04
permissions:
contents: read
defaults:
run:
shell: bash -euox pipefail {0}

concurrency:
# https://github.community/t/concurrecy-not-work-for-push/183068/7
Expand Down Expand Up @@ -124,19 +140,15 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0

- name: Setup Python
id: setup_python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
with:
python-version: '3.11'
cache: 'pip'
pip-install: '-r requirements-dev.txt'
cache-dependency-path: 'requirements-dev.txt'

- name: Install requirements-dev.txt
run: pip install -r requirements-dev.txt

- name: Check Pip Cache Hit
run: echo ${{ steps.setup_python.outputs.cache-hit }}
7 changes: 7 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ jobs:
${{ ! (matrix.name == 'Freethreading' || matrix.name == 'Minimum Versions') && '-Csetup-args="--werror"' || '' }}
shell: bash -euox pipefail {0}

- name: Import check
run: |
pixi run \
--environment ${{ matrix.environment }} \
ci-check-import
shell: bash -euox pipefail {0}

- name: Test (not single_cpu)
uses: ./.github/actions/run-tests
id: test-not-single-cpu
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ repos:
- id: mypy
# note: assumes python env is setup and activated
name: mypy
entry: mypy
entry: python -m mypy
language: system
pass_filenames: false
types: [python]
Expand Down
61 changes: 0 additions & 61 deletions ci/code_checks.sh

This file was deleted.

31 changes: 31 additions & 0 deletions ci/import_pandas_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import sys

import pandas # noqa: F401

blocklist = {
"bs4",
"gcsfs",
"html5lib",
"http",
"ipython",
"jinja2",
"hypothesis",
"lxml",
"matplotlib",
"openpyxl",
"py",
"pytest",
"s3fs",
"scipy",
"tables",
"urllib.request",
"xlrd",
"xlsxwriter",
}

# GH#28227 for some of these check for top-level modules, while others are
# more specific (e.g. urllib.request)
import_mods = {m.split(".")[0] for m in sys.modules} | set(sys.modules)
mods = blocklist & import_mods
if mods:
raise Exception(f"pandas should not import {', '.join(mods)}")
8 changes: 1 addition & 7 deletions doc/source/development/contributing_codebase.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,9 @@ tools will be run to check your code for stylistic errors.
Generating any warnings will cause the test to fail.
Thus, good style is a requirement for submitting code to pandas.

There are a couple of tools in pandas to help contributors verify their changes
``pre-commit``, which we go into detail on in the next section, helps contributors verify their changes
before contributing to the project

- ``./ci/code_checks.sh``: a script validates the doctests, imported modules,
and notebooks. It is possible to run the checks independently by
using the parameters ``code``, ``doctests``, and ``notebooks``
(e.g. ``./ci/code_checks.sh doctests``).
- ``pre-commit``, which we go into detail on in the next section.

In addition, because a lot of people use our library, it is important that we
do not make sudden changes to the code that could have the potential to break
a lot of user code as a result, that is, we need it to be as *backwards compatible*
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1996,8 +1996,8 @@ def to_dict(

>>> from collections import OrderedDict, defaultdict
>>> df.to_dict(into=OrderedDict)
OrderedDict([('col1', OrderedDict([('row1', 1), ('row2', 2)])),
('col2', OrderedDict([('row1', 0.5), ('row2', 0.75)]))])
OrderedDict({'col1': OrderedDict({'row1': 1, 'row2': 2}),
'col2': OrderedDict({'row1': 0.5, 'row2': 0.75})})

If you want a `defaultdict`, you need to initialize it:

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1852,7 +1852,7 @@ def to_dict(
{0: 1, 1: 2, 2: 3, 3: 4}
>>> from collections import OrderedDict, defaultdict
>>> s.to_dict(into=OrderedDict)
OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4)])
OrderedDict({0: 1, 1: 2, 2: 3, 3: 4})
>>> dd = defaultdict(list)
>>> s.to_dict(into=dd)
defaultdict(<class 'list'>, {0: 1, 1: 2, 2: 3, 3: 4})
Expand Down
Loading
Loading