Instructions to use godlykmathews/BERT-Sentiment_Classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use godlykmathews/BERT-Sentiment_Classifier with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="godlykmathews/BERT-Sentiment_Classifier")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("godlykmathews/BERT-Sentiment_Classifier", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload folder using huggingface_hub (part 10)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/INSTALLER +1 -0
- venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/METADATA +308 -0
- venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/RECORD +0 -0
- venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/WHEEL +6 -0
- venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/entry_points.txt +3 -0
- venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSE +31 -0
- venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/BOTTLENECK_LICENCE +25 -0
- venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/DATEUTIL_LICENSE +54 -0
- venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/HAVEN_LICENSE +21 -0
- venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/HAVEN_MIT +32 -0
- venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/KLIB_LICENSE +23 -0
- venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/MUSL_LICENSE +193 -0
- venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/NUMPY_LICENSE +30 -0
- venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/PACKAGING_LICENSE +202 -0
- venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/PSF_LICENSE +279 -0
- venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/PYPERCLIP_LICENSE +27 -0
- venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/PYUPGRADE_LICENSE +19 -0
- venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/SAS7BDAT_LICENSE +19 -0
- venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/STATSBASE_JL_LICENSE +23 -0
- venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/ULTRAJSON_LICENSE +114 -0
- venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/XSIMD_LICENSE +29 -0
- venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/subprojects/fast_float-8.2.10/LICENSE-APACHE +190 -0
- venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/subprojects/fast_float-8.2.10/LICENSE-BOOST +23 -0
- venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/subprojects/fast_float-8.2.10/LICENSE-MIT +27 -0
- venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_diff.py +304 -0
- venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_dot.py +168 -0
- venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_drop.py +590 -0
- venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_drop_duplicates.py +553 -0
- venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_droplevel.py +32 -0
- venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_dropna.py +319 -0
- venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_dtypes.py +138 -0
- venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_duplicated.py +145 -0
- venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_equals.py +109 -0
- venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_explode.py +307 -0
- venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_fillna.py +935 -0
- venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_filter.py +510 -0
- venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_first_valid_index.py +103 -0
- venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_get_numeric_data.py +101 -0
- venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_head_tail.py +57 -0
- venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_infer_objects.py +42 -0
- venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_info.py +619 -0
- venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_interpolate.py +492 -0
- venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_is_homogeneous_dtype.py +54 -0
- venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_isetitem.py +64 -0
- venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_isin.py +222 -0
- venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_iterrows.py +13 -0
- venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_join.py +599 -0
- venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_map.py +202 -0
- venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_matmul.py +94 -0
- venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_nlargest.py +231 -0
venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/METADATA
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.4
|
| 2 |
+
Name: pandas
|
| 3 |
+
Version: 3.1.1
|
| 4 |
+
Summary: Powerful data structures for data analysis, time series, and statistics
|
| 5 |
+
Author-Email: The Pandas Development Team <pandas-dev@python.org>
|
| 6 |
+
License-Expression: BSD-3-Clause
|
| 7 |
+
License-File: LICENSE
|
| 8 |
+
License-File: LICENSES/BOTTLENECK_LICENCE
|
| 9 |
+
License-File: LICENSES/DATEUTIL_LICENSE
|
| 10 |
+
License-File: LICENSES/HAVEN_LICENSE
|
| 11 |
+
License-File: LICENSES/HAVEN_MIT
|
| 12 |
+
License-File: LICENSES/KLIB_LICENSE
|
| 13 |
+
License-File: LICENSES/MUSL_LICENSE
|
| 14 |
+
License-File: LICENSES/NUMPY_LICENSE
|
| 15 |
+
License-File: LICENSES/PACKAGING_LICENSE
|
| 16 |
+
License-File: LICENSES/PSF_LICENSE
|
| 17 |
+
License-File: LICENSES/PYPERCLIP_LICENSE
|
| 18 |
+
License-File: LICENSES/PYUPGRADE_LICENSE
|
| 19 |
+
License-File: LICENSES/SAS7BDAT_LICENSE
|
| 20 |
+
License-File: LICENSES/STATSBASE_JL_LICENSE
|
| 21 |
+
License-File: LICENSES/ULTRAJSON_LICENSE
|
| 22 |
+
License-File: LICENSES/XSIMD_LICENSE
|
| 23 |
+
License-File: subprojects/fast_float-8.2.10/LICENSE-APACHE
|
| 24 |
+
License-File: subprojects/fast_float-8.2.10/LICENSE-BOOST
|
| 25 |
+
License-File: subprojects/fast_float-8.2.10/LICENSE-MIT
|
| 26 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 27 |
+
Classifier: Environment :: Console
|
| 28 |
+
Classifier: Intended Audience :: Science/Research
|
| 29 |
+
Classifier: Operating System :: OS Independent
|
| 30 |
+
Classifier: Programming Language :: Cython
|
| 31 |
+
Classifier: Programming Language :: Python
|
| 32 |
+
Classifier: Programming Language :: Python :: 3
|
| 33 |
+
Classifier: Programming Language :: Python :: 3 :: Only
|
| 34 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 35 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 36 |
+
Classifier: Programming Language :: Python :: 3.13
|
| 37 |
+
Classifier: Programming Language :: Python :: 3.14
|
| 38 |
+
Classifier: Programming Language :: Python :: 3.15
|
| 39 |
+
Classifier: Topic :: Scientific/Engineering
|
| 40 |
+
Project-URL: homepage, https://pandas.pydata.org
|
| 41 |
+
Project-URL: source, https://github.com/pandas-dev/pandas
|
| 42 |
+
Project-URL: documentation, https://pandas.pydata.org/docs/
|
| 43 |
+
Project-URL: changelog, https://pandas.pydata.org/docs/whatsnew/index.html
|
| 44 |
+
Project-URL: issues, https://github.com/pandas-dev/pandas/issues
|
| 45 |
+
Project-URL: funding, https://opencollective.com/pandas
|
| 46 |
+
Requires-Python: >=3.11
|
| 47 |
+
Requires-Dist: numpy>=2.0.2; python_version < "3.14"
|
| 48 |
+
Requires-Dist: numpy>=2.3.3; python_version >= "3.14"
|
| 49 |
+
Requires-Dist: python-dateutil>=2.9.0
|
| 50 |
+
Requires-Dist: tzdata; sys_platform == "win32"
|
| 51 |
+
Requires-Dist: tzdata; sys_platform == "emscripten"
|
| 52 |
+
Provides-Extra: test
|
| 53 |
+
Requires-Dist: pytest>=8.3.4; extra == "test"
|
| 54 |
+
Requires-Dist: pytest-xdist>=3.6.1; extra == "test"
|
| 55 |
+
Provides-Extra: pyarrow
|
| 56 |
+
Requires-Dist: pyarrow>=16.0.0; extra == "pyarrow"
|
| 57 |
+
Provides-Extra: performance
|
| 58 |
+
Requires-Dist: bottleneck>=1.5.0; extra == "performance"
|
| 59 |
+
Requires-Dist: numba>=0.61.2; extra == "performance"
|
| 60 |
+
Requires-Dist: numexpr!=2.14.1,>=2.11.0; extra == "performance"
|
| 61 |
+
Provides-Extra: computation
|
| 62 |
+
Requires-Dist: scipy>=1.16.1; extra == "computation"
|
| 63 |
+
Requires-Dist: xarray>=2025.7.1; extra == "computation"
|
| 64 |
+
Provides-Extra: fss
|
| 65 |
+
Requires-Dist: fsspec>=2025.7.0; extra == "fss"
|
| 66 |
+
Provides-Extra: aws
|
| 67 |
+
Requires-Dist: s3fs>=2025.7.0; extra == "aws"
|
| 68 |
+
Provides-Extra: gcp
|
| 69 |
+
Requires-Dist: gcsfs>=2025.7.0; extra == "gcp"
|
| 70 |
+
Provides-Extra: excel
|
| 71 |
+
Requires-Dist: odfpy>=1.4.1; extra == "excel"
|
| 72 |
+
Requires-Dist: openpyxl>=3.1.5; extra == "excel"
|
| 73 |
+
Requires-Dist: python-calamine>=0.4.0; extra == "excel"
|
| 74 |
+
Requires-Dist: pyxlsb>=1.0.10; extra == "excel"
|
| 75 |
+
Requires-Dist: xlrd>=2.0.2; extra == "excel"
|
| 76 |
+
Requires-Dist: xlsxwriter>=3.2.5; extra == "excel"
|
| 77 |
+
Provides-Extra: parquet
|
| 78 |
+
Requires-Dist: pandas[pyarrow]; extra == "parquet"
|
| 79 |
+
Provides-Extra: feather
|
| 80 |
+
Requires-Dist: pandas[pyarrow]; extra == "feather"
|
| 81 |
+
Provides-Extra: iceberg
|
| 82 |
+
Requires-Dist: pyiceberg>=0.9.1; extra == "iceberg"
|
| 83 |
+
Provides-Extra: hdf5
|
| 84 |
+
Requires-Dist: tables>=3.10.2; extra == "hdf5"
|
| 85 |
+
Provides-Extra: spss
|
| 86 |
+
Requires-Dist: pyreadstat>=1.3.0; extra == "spss"
|
| 87 |
+
Provides-Extra: postgresql
|
| 88 |
+
Requires-Dist: SQLAlchemy>=2.0.42; extra == "postgresql"
|
| 89 |
+
Requires-Dist: psycopg2>=2.9.10; extra == "postgresql"
|
| 90 |
+
Requires-Dist: adbc-driver-postgresql>=1.7.0; extra == "postgresql"
|
| 91 |
+
Provides-Extra: mysql
|
| 92 |
+
Requires-Dist: SQLAlchemy>=2.0.42; extra == "mysql"
|
| 93 |
+
Requires-Dist: pymysql>=1.1.1; extra == "mysql"
|
| 94 |
+
Provides-Extra: sql-other
|
| 95 |
+
Requires-Dist: SQLAlchemy>=2.0.42; extra == "sql-other"
|
| 96 |
+
Requires-Dist: adbc-driver-postgresql>=1.7.0; extra == "sql-other"
|
| 97 |
+
Requires-Dist: adbc-driver-sqlite>=1.7.0; extra == "sql-other"
|
| 98 |
+
Provides-Extra: html
|
| 99 |
+
Requires-Dist: beautifulsoup4>=4.13.4; extra == "html"
|
| 100 |
+
Requires-Dist: html5lib>=1.1; extra == "html"
|
| 101 |
+
Requires-Dist: lxml>=6.0.0; extra == "html"
|
| 102 |
+
Provides-Extra: xml
|
| 103 |
+
Requires-Dist: lxml>=6.0.0; extra == "xml"
|
| 104 |
+
Provides-Extra: plot
|
| 105 |
+
Requires-Dist: matplotlib>=3.10.5; extra == "plot"
|
| 106 |
+
Provides-Extra: output-formatting
|
| 107 |
+
Requires-Dist: jinja2>=3.1.6; extra == "output-formatting"
|
| 108 |
+
Requires-Dist: tabulate>=0.9.0; extra == "output-formatting"
|
| 109 |
+
Provides-Extra: clipboard
|
| 110 |
+
Requires-Dist: PyQt5>=5.15.11; extra == "clipboard"
|
| 111 |
+
Requires-Dist: qtpy>=2.4.3; extra == "clipboard"
|
| 112 |
+
Provides-Extra: compression
|
| 113 |
+
Requires-Dist: zstandard>=0.23.0; extra == "compression"
|
| 114 |
+
Provides-Extra: timezone
|
| 115 |
+
Requires-Dist: pytz>=2020.1; extra == "timezone"
|
| 116 |
+
Provides-Extra: all
|
| 117 |
+
Requires-Dist: pandas[aws,clipboard,compression,computation,excel,feather,fss,gcp,hdf5,html,iceberg,mysql,output-formatting,parquet,performance,plot,postgresql,pyarrow,spss,sql-other,test,timezone,xml]; extra == "all"
|
| 118 |
+
Requires-Dist: fastparquet>=2024.11.0; extra == "all"
|
| 119 |
+
Description-Content-Type: text/markdown
|
| 120 |
+
|
| 121 |
+
<picture align="center">
|
| 122 |
+
<source media="(prefers-color-scheme: dark)" srcset="https://pandas.pydata.org/static/img/pandas_white.svg">
|
| 123 |
+
<img alt="Pandas Logo" src="https://pandas.pydata.org/static/img/pandas.svg">
|
| 124 |
+
</picture>
|
| 125 |
+
|
| 126 |
+
-----------------
|
| 127 |
+
|
| 128 |
+
# pandas: A Powerful Python Data Analysis Toolkit
|
| 129 |
+
|
| 130 |
+
| | |
|
| 131 |
+
| --- | --- |
|
| 132 |
+
| Testing | [](https://github.com/pandas-dev/pandas/actions/workflows/unit-tests.yml) [](https://codecov.io/gh/pandas-dev/pandas) |
|
| 133 |
+
| Package | [](https://pypi.org/project/pandas/) [](https://pypi.org/project/pandas/) [](https://anaconda.org/conda-forge/pandas) [](https://anaconda.org/conda-forge/pandas) |
|
| 134 |
+
| Meta | [](https://numfocus.org) [](https://doi.org/10.5281/zenodo.3509134) [](https://github.com/pandas-dev/pandas/blob/main/LICENSE) [](https://pandas.pydata.org/docs/dev/development/community.html?highlight=slack#community-slack) [](https://insights.linuxfoundation.org/project/pandas-dev-pandas) |
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
## What is it?
|
| 138 |
+
|
| 139 |
+
**pandas** is a Python package that provides fast, flexible, and expressive data
|
| 140 |
+
structures designed to make working with "relational" or "labeled" data both
|
| 141 |
+
easy and intuitive. It aims to be the fundamental high-level building block for
|
| 142 |
+
doing practical, **real-world** data analysis in Python. Additionally, it has
|
| 143 |
+
the broader goal of becoming **the most powerful and flexible open-source data
|
| 144 |
+
analysis/manipulation tool available in any language**. It is already well on
|
| 145 |
+
its way towards this goal.
|
| 146 |
+
|
| 147 |
+
## Table of Contents
|
| 148 |
+
|
| 149 |
+
- [Main Features](#main-features)
|
| 150 |
+
- [Where to get it](#where-to-get-it)
|
| 151 |
+
- [Dependencies](#dependencies)
|
| 152 |
+
- [Installation from sources](#installation-from-sources)
|
| 153 |
+
- [License](#license)
|
| 154 |
+
- [Documentation](#documentation)
|
| 155 |
+
- [Background](#background)
|
| 156 |
+
- [Getting Help](#getting-help)
|
| 157 |
+
- [Discussion and Development](#discussion-and-development)
|
| 158 |
+
- [Contributing to pandas](#contributing-to-pandas)
|
| 159 |
+
|
| 160 |
+
## Main Features
|
| 161 |
+
Here are just a few of the things that pandas does well:
|
| 162 |
+
|
| 163 |
+
- Easy handling of [**missing data**][missing-data] (represented as
|
| 164 |
+
`NaN`, `NA`, or `NaT`) in floating point as well as non-floating point data
|
| 165 |
+
- Size mutability: columns can be [**inserted and
|
| 166 |
+
deleted**][insertion-deletion] from DataFrame and higher dimensional
|
| 167 |
+
objects
|
| 168 |
+
- Automatic and explicit [**data alignment**][alignment]: objects can
|
| 169 |
+
be explicitly aligned to a set of labels, or the user can simply
|
| 170 |
+
ignore the labels and let `Series`, `DataFrame`, etc. automatically
|
| 171 |
+
align the data for you in computations
|
| 172 |
+
- Powerful, flexible [**group by**][groupby] functionality to perform
|
| 173 |
+
split-apply-combine operations on data sets, for both aggregating
|
| 174 |
+
and transforming data
|
| 175 |
+
- Make it [**easy to convert**][conversion] ragged,
|
| 176 |
+
differently-indexed data in other Python and NumPy data structures
|
| 177 |
+
into DataFrame objects
|
| 178 |
+
- Intelligent label-based [**slicing**][slicing], [**fancy
|
| 179 |
+
indexing**][fancy-indexing], and [**subsetting**][subsetting] of
|
| 180 |
+
large data sets
|
| 181 |
+
- Intuitive [**merging**][merging] and [**joining**][joining] data
|
| 182 |
+
sets
|
| 183 |
+
- Flexible [**reshaping**][reshape] and [**pivoting**][pivot-table] of
|
| 184 |
+
data sets
|
| 185 |
+
- [**Hierarchical**][mi] labeling of axes (possible to have multiple
|
| 186 |
+
labels per tick)
|
| 187 |
+
- Robust I/O tools for loading data from [**flat files**][flat-files]
|
| 188 |
+
(CSV and delimited), [**Excel files**][excel], [**databases**][db],
|
| 189 |
+
and saving/loading data from the ultrafast [**HDF5 format**][hdfstore]
|
| 190 |
+
- [**Time series**][timeseries]-specific functionality: date range
|
| 191 |
+
generation and frequency conversion, moving window statistics,
|
| 192 |
+
date shifting and lagging
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
[missing-data]: https://pandas.pydata.org/pandas-docs/stable/user_guide/missing_data.html
|
| 196 |
+
[insertion-deletion]: https://pandas.pydata.org/pandas-docs/stable/user_guide/dsintro.html#column-selection-addition-deletion
|
| 197 |
+
[alignment]: https://pandas.pydata.org/pandas-docs/stable/user_guide/dsintro.html?highlight=alignment#intro-to-data-structures
|
| 198 |
+
[groupby]: https://pandas.pydata.org/pandas-docs/stable/user_guide/groupby.html#group-by-split-apply-combine
|
| 199 |
+
[conversion]: https://pandas.pydata.org/pandas-docs/stable/user_guide/dsintro.html#dataframe
|
| 200 |
+
[slicing]: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#slicing-ranges
|
| 201 |
+
[fancy-indexing]: https://pandas.pydata.org/pandas-docs/stable/user_guide/advanced.html#advanced
|
| 202 |
+
[subsetting]: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#boolean-indexing
|
| 203 |
+
[merging]: https://pandas.pydata.org/pandas-docs/stable/user_guide/merging.html#database-style-dataframe-or-named-series-joining-merging
|
| 204 |
+
[joining]: https://pandas.pydata.org/pandas-docs/stable/user_guide/merging.html#joining-on-index
|
| 205 |
+
[reshape]: https://pandas.pydata.org/pandas-docs/stable/user_guide/reshaping.html
|
| 206 |
+
[pivot-table]: https://pandas.pydata.org/pandas-docs/stable/user_guide/reshaping.html
|
| 207 |
+
[mi]: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#hierarchical-indexing-multiindex
|
| 208 |
+
[flat-files]: https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#csv-text-files
|
| 209 |
+
[excel]: https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#excel-files
|
| 210 |
+
[db]: https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#sql-queries
|
| 211 |
+
[hdfstore]: https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#hdf5-pytables
|
| 212 |
+
[timeseries]: https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#time-series-date-functionality
|
| 213 |
+
|
| 214 |
+
## Where to get it
|
| 215 |
+
The source code is currently hosted on GitHub at:
|
| 216 |
+
https://github.com/pandas-dev/pandas
|
| 217 |
+
|
| 218 |
+
Binary installers for the latest released version are available at the [Python
|
| 219 |
+
Package Index (PyPI)](https://pypi.org/project/pandas) and on [Conda](https://anaconda.org/conda-forge/pandas).
|
| 220 |
+
|
| 221 |
+
```sh
|
| 222 |
+
# conda
|
| 223 |
+
conda install -c conda-forge pandas
|
| 224 |
+
```
|
| 225 |
+
|
| 226 |
+
```sh
|
| 227 |
+
# or PyPI
|
| 228 |
+
pip install pandas
|
| 229 |
+
```
|
| 230 |
+
|
| 231 |
+
The list of changes to pandas between each release can be found
|
| 232 |
+
[here](https://pandas.pydata.org/pandas-docs/stable/whatsnew/index.html). For full
|
| 233 |
+
details, see the commit logs at https://github.com/pandas-dev/pandas.
|
| 234 |
+
|
| 235 |
+
## Dependencies
|
| 236 |
+
- [NumPy - Adds support for large, multi-dimensional arrays, matrices and high-level mathematical functions to operate on these arrays](https://www.numpy.org)
|
| 237 |
+
- [python-dateutil - Provides powerful extensions to the standard datetime module](https://dateutil.readthedocs.io/en/stable/index.html)
|
| 238 |
+
- [tzdata - Provides an IANA time zone database](https://tzdata.python.org) (Only required on Windows/Emscripten)
|
| 239 |
+
|
| 240 |
+
See the [full installation instructions](https://pandas.pydata.org/pandas-docs/stable/install.html#dependencies) for minimum supported versions of required, recommended and optional dependencies.
|
| 241 |
+
|
| 242 |
+
## Installation from sources
|
| 243 |
+
To install pandas from source you need [Cython](https://cython.org/) in addition to the normal
|
| 244 |
+
dependencies above. Cython can be installed from PyPI:
|
| 245 |
+
|
| 246 |
+
```sh
|
| 247 |
+
pip install cython
|
| 248 |
+
```
|
| 249 |
+
|
| 250 |
+
In the `pandas` directory (same one where you found this file after
|
| 251 |
+
cloning the git repo), execute:
|
| 252 |
+
|
| 253 |
+
```sh
|
| 254 |
+
pip install .
|
| 255 |
+
```
|
| 256 |
+
|
| 257 |
+
or for installing in [development mode](https://pip.pypa.io/en/latest/cli/pip_install/#install-editable):
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
```sh
|
| 261 |
+
python -m pip install -ve . --no-build-isolation --config-settings editable-verbose=true
|
| 262 |
+
```
|
| 263 |
+
|
| 264 |
+
See the full instructions for [installing from source](https://pandas.pydata.org/docs/dev/development/contributing_environment.html).
|
| 265 |
+
|
| 266 |
+
## License
|
| 267 |
+
[BSD 3](LICENSE)
|
| 268 |
+
|
| 269 |
+
## Documentation
|
| 270 |
+
The official documentation is hosted on [PyData.org](https://pandas.pydata.org/pandas-docs/stable/).
|
| 271 |
+
|
| 272 |
+
## Background
|
| 273 |
+
Work on ``pandas`` started at [AQR](https://www.aqr.com/) (a quantitative hedge fund) in 2008 and
|
| 274 |
+
has been under active development since then.
|
| 275 |
+
|
| 276 |
+
## Getting Help
|
| 277 |
+
|
| 278 |
+
For usage questions, the best place to go to is [Stack Overflow](https://stackoverflow.com/questions/tagged/pandas).
|
| 279 |
+
Further, general questions and discussions can also take place on the [pydata mailing list](https://groups.google.com/forum/?fromgroups#!forum/pydata).
|
| 280 |
+
|
| 281 |
+
## Discussion and Development
|
| 282 |
+
Most development discussions take place on GitHub in this repo, via the [GitHub issue tracker](https://github.com/pandas-dev/pandas/issues).
|
| 283 |
+
|
| 284 |
+
Further, the [pandas-dev mailing list](https://mail.python.org/mailman/listinfo/pandas-dev) can also be used for specialized discussions or design issues, and a [Slack channel](https://pandas.pydata.org/docs/dev/development/community.html?highlight=slack#community-slack) is available for quick development related questions.
|
| 285 |
+
|
| 286 |
+
There are also frequent [community meetings](https://pandas.pydata.org/docs/dev/development/community.html#community-meeting) for project maintainers open to the community as well as monthly [new contributor meetings](https://pandas.pydata.org/docs/dev/development/community.html#new-contributor-meeting) to help support new contributors.
|
| 287 |
+
|
| 288 |
+
Additional information on the communication channels can be found on the [contributor community](https://pandas.pydata.org/docs/development/community.html) page.
|
| 289 |
+
|
| 290 |
+
## Contributing to pandas
|
| 291 |
+
|
| 292 |
+
[](https://www.codetriage.com/pandas-dev/pandas)
|
| 293 |
+
|
| 294 |
+
All contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome.
|
| 295 |
+
|
| 296 |
+
A detailed overview on how to contribute can be found in the **[contributing guide](https://pandas.pydata.org/docs/dev/development/contributing.html)**.
|
| 297 |
+
|
| 298 |
+
You can also triage issues which may include reproducing bug reports, or asking for vital information such as version numbers or reproduction instructions. If you would like to start triaging issues, one easy way to get started is to [subscribe to pandas on CodeTriage](https://www.codetriage.com/pandas-dev/pandas).
|
| 299 |
+
|
| 300 |
+
Or maybe through using pandas you have an idea of your own or are looking for something in the documentation and thinking ‘this can be improved’... you can do something about it!
|
| 301 |
+
|
| 302 |
+
Feel free to ask questions on the [mailing list](https://groups.google.com/forum/?fromgroups#!forum/pydata) or on [Slack](https://pandas.pydata.org/docs/dev/development/community.html?highlight=slack#community-slack).
|
| 303 |
+
|
| 304 |
+
As contributors and maintainers to this project, you are expected to abide by pandas' code of conduct. More information can be found at: [Contributor Code of Conduct](https://github.com/pandas-dev/.github/blob/master/CODE_OF_CONDUCT.md)
|
| 305 |
+
|
| 306 |
+
<hr>
|
| 307 |
+
|
| 308 |
+
[Go to Top](#table-of-contents)
|
venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/RECORD
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: meson
|
| 3 |
+
Root-Is-Purelib: false
|
| 4 |
+
Tag: cp314-cp314-macosx_11_0_arm64
|
| 5 |
+
Generator: delocate 0.13.0
|
| 6 |
+
|
venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/entry_points.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[pandas_plotting_backends]
|
| 2 |
+
matplotlib = pandas:plotting._matplotlib
|
| 3 |
+
|
venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSE
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
BSD 3-Clause License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2008-2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
|
| 4 |
+
All rights reserved.
|
| 5 |
+
|
| 6 |
+
Copyright (c) 2011-2026, Open source contributors.
|
| 7 |
+
|
| 8 |
+
Redistribution and use in source and binary forms, with or without
|
| 9 |
+
modification, are permitted provided that the following conditions are met:
|
| 10 |
+
|
| 11 |
+
* Redistributions of source code must retain the above copyright notice, this
|
| 12 |
+
list of conditions and the following disclaimer.
|
| 13 |
+
|
| 14 |
+
* Redistributions in binary form must reproduce the above copyright notice,
|
| 15 |
+
this list of conditions and the following disclaimer in the documentation
|
| 16 |
+
and/or other materials provided with the distribution.
|
| 17 |
+
|
| 18 |
+
* Neither the name of the copyright holder nor the names of its
|
| 19 |
+
contributors may be used to endorse or promote products derived from
|
| 20 |
+
this software without specific prior written permission.
|
| 21 |
+
|
| 22 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 23 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 24 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 25 |
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
| 26 |
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 27 |
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 28 |
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 29 |
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
| 30 |
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 31 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/BOTTLENECK_LICENCE
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright (c) 2010-2019 Keith Goodman
|
| 2 |
+
Copyright (c) 2019 Bottleneck Developers
|
| 3 |
+
All rights reserved.
|
| 4 |
+
|
| 5 |
+
Redistribution and use in source and binary forms, with or without
|
| 6 |
+
modification, are permitted provided that the following conditions are met:
|
| 7 |
+
|
| 8 |
+
* Redistributions of source code must retain the above copyright notice,
|
| 9 |
+
this list of conditions and the following disclaimer.
|
| 10 |
+
|
| 11 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 12 |
+
notice, this list of conditions and the following disclaimer in the
|
| 13 |
+
documentation and/or other materials provided with the distribution.
|
| 14 |
+
|
| 15 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 16 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 17 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 18 |
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
| 19 |
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
| 20 |
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
| 21 |
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
| 22 |
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
| 23 |
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
| 24 |
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
| 25 |
+
POSSIBILITY OF SUCH DAMAGE.
|
venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/DATEUTIL_LICENSE
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright 2017- Paul Ganssle <paul@ganssle.io>
|
| 2 |
+
Copyright 2017- dateutil contributors (see AUTHORS file)
|
| 3 |
+
|
| 4 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
you may not use this file except in compliance with the License.
|
| 6 |
+
You may obtain a copy of the License at
|
| 7 |
+
|
| 8 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
|
| 10 |
+
Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
See the License for the specific language governing permissions and
|
| 14 |
+
limitations under the License.
|
| 15 |
+
|
| 16 |
+
The above license applies to all contributions after 2017-12-01, as well as
|
| 17 |
+
all contributions that have been re-licensed (see AUTHORS file for the list of
|
| 18 |
+
contributors who have re-licensed their code).
|
| 19 |
+
--------------------------------------------------------------------------------
|
| 20 |
+
dateutil - Extensions to the standard Python datetime module.
|
| 21 |
+
|
| 22 |
+
Copyright (c) 2003-2011 - Gustavo Niemeyer <gustavo@niemeyer.net>
|
| 23 |
+
Copyright (c) 2012-2014 - Tomi Pieviläinen <tomi.pievilainen@iki.fi>
|
| 24 |
+
Copyright (c) 2014-2016 - Yaron de Leeuw <me@jarondl.net>
|
| 25 |
+
Copyright (c) 2015- - Paul Ganssle <paul@ganssle.io>
|
| 26 |
+
Copyright (c) 2015- - dateutil contributors (see AUTHORS file)
|
| 27 |
+
|
| 28 |
+
All rights reserved.
|
| 29 |
+
|
| 30 |
+
Redistribution and use in source and binary forms, with or without
|
| 31 |
+
modification, are permitted provided that the following conditions are met:
|
| 32 |
+
|
| 33 |
+
* Redistributions of source code must retain the above copyright notice,
|
| 34 |
+
this list of conditions and the following disclaimer.
|
| 35 |
+
* Redistributions in binary form must reproduce the above copyright notice,
|
| 36 |
+
this list of conditions and the following disclaimer in the documentation
|
| 37 |
+
and/or other materials provided with the distribution.
|
| 38 |
+
* Neither the name of the copyright holder nor the names of its
|
| 39 |
+
contributors may be used to endorse or promote products derived from
|
| 40 |
+
this software without specific prior written permission.
|
| 41 |
+
|
| 42 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 43 |
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 44 |
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 45 |
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
| 46 |
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
| 47 |
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
| 48 |
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
| 49 |
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
| 50 |
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
| 51 |
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 52 |
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 53 |
+
|
| 54 |
+
The above BSD License Applies to all code, even that also covered by Apache 2.0.
|
venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/HAVEN_LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2019 Hadley Wickham; RStudio; and Evan Miller
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/HAVEN_MIT
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Based on http://opensource.org/licenses/MIT
|
| 2 |
+
|
| 3 |
+
This is a template. Complete and ship as file LICENSE the following 2
|
| 4 |
+
lines (only)
|
| 5 |
+
|
| 6 |
+
YEAR:
|
| 7 |
+
COPYRIGHT HOLDER:
|
| 8 |
+
|
| 9 |
+
and specify as
|
| 10 |
+
|
| 11 |
+
License: MIT + file LICENSE
|
| 12 |
+
|
| 13 |
+
Copyright (c) <YEAR>, <COPYRIGHT HOLDER>
|
| 14 |
+
|
| 15 |
+
Permission is hereby granted, free of charge, to any person obtaining
|
| 16 |
+
a copy of this software and associated documentation files (the
|
| 17 |
+
"Software"), to deal in the Software without restriction, including
|
| 18 |
+
without limitation the rights to use, copy, modify, merge, publish,
|
| 19 |
+
distribute, sublicense, and/or sell copies of the Software, and to
|
| 20 |
+
permit persons to whom the Software is furnished to do so, subject to
|
| 21 |
+
the following conditions:
|
| 22 |
+
|
| 23 |
+
The above copyright notice and this permission notice shall be
|
| 24 |
+
included in all copies or substantial portions of the Software.
|
| 25 |
+
|
| 26 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 27 |
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
| 28 |
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
| 29 |
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
| 30 |
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
| 31 |
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
| 32 |
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/KLIB_LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2008- Attractive Chaos <attractor@live.co.uk>
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining
|
| 6 |
+
a copy of this software and associated documentation files (the
|
| 7 |
+
"Software"), to deal in the Software without restriction, including
|
| 8 |
+
without limitation the rights to use, copy, modify, merge, publish,
|
| 9 |
+
distribute, sublicense, and/or sell copies of the Software, and to
|
| 10 |
+
permit persons to whom the Software is furnished to do so, subject to
|
| 11 |
+
the following conditions:
|
| 12 |
+
|
| 13 |
+
The above copyright notice and this permission notice shall be
|
| 14 |
+
included in all copies or substantial portions of the Software.
|
| 15 |
+
|
| 16 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 17 |
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
| 18 |
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
| 19 |
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
| 20 |
+
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
| 21 |
+
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 22 |
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 23 |
+
SOFTWARE.
|
venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/MUSL_LICENSE
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
musl as a whole is licensed under the following standard MIT license:
|
| 2 |
+
|
| 3 |
+
----------------------------------------------------------------------
|
| 4 |
+
Copyright © 2005-2020 Rich Felker, et al.
|
| 5 |
+
|
| 6 |
+
Permission is hereby granted, free of charge, to any person obtaining
|
| 7 |
+
a copy of this software and associated documentation files (the
|
| 8 |
+
"Software"), to deal in the Software without restriction, including
|
| 9 |
+
without limitation the rights to use, copy, modify, merge, publish,
|
| 10 |
+
distribute, sublicense, and/or sell copies of the Software, and to
|
| 11 |
+
permit persons to whom the Software is furnished to do so, subject to
|
| 12 |
+
the following conditions:
|
| 13 |
+
|
| 14 |
+
The above copyright notice and this permission notice shall be
|
| 15 |
+
included in all copies or substantial portions of the Software.
|
| 16 |
+
|
| 17 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 18 |
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
| 19 |
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
| 20 |
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
| 21 |
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
| 22 |
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
| 23 |
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 24 |
+
----------------------------------------------------------------------
|
| 25 |
+
|
| 26 |
+
Authors/contributors include:
|
| 27 |
+
|
| 28 |
+
A. Wilcox
|
| 29 |
+
Ada Worcester
|
| 30 |
+
Alex Dowad
|
| 31 |
+
Alex Suykov
|
| 32 |
+
Alexander Monakov
|
| 33 |
+
Andre McCurdy
|
| 34 |
+
Andrew Kelley
|
| 35 |
+
Anthony G. Basile
|
| 36 |
+
Aric Belsito
|
| 37 |
+
Arvid Picciani
|
| 38 |
+
Bartosz Brachaczek
|
| 39 |
+
Benjamin Peterson
|
| 40 |
+
Bobby Bingham
|
| 41 |
+
Boris Brezillon
|
| 42 |
+
Brent Cook
|
| 43 |
+
Chris Spiegel
|
| 44 |
+
Clément Vasseur
|
| 45 |
+
Daniel Micay
|
| 46 |
+
Daniel Sabogal
|
| 47 |
+
Daurnimator
|
| 48 |
+
David Carlier
|
| 49 |
+
David Edelsohn
|
| 50 |
+
Denys Vlasenko
|
| 51 |
+
Dmitry Ivanov
|
| 52 |
+
Dmitry V. Levin
|
| 53 |
+
Drew DeVault
|
| 54 |
+
Emil Renner Berthing
|
| 55 |
+
Fangrui Song
|
| 56 |
+
Felix Fietkau
|
| 57 |
+
Felix Janda
|
| 58 |
+
Gianluca Anzolin
|
| 59 |
+
Hauke Mehrtens
|
| 60 |
+
He X
|
| 61 |
+
Hiltjo Posthuma
|
| 62 |
+
Isaac Dunham
|
| 63 |
+
Jaydeep Patil
|
| 64 |
+
Jens Gustedt
|
| 65 |
+
Jeremy Huntwork
|
| 66 |
+
Jo-Philipp Wich
|
| 67 |
+
Joakim Sindholt
|
| 68 |
+
John Spencer
|
| 69 |
+
Julien Ramseier
|
| 70 |
+
Justin Cormack
|
| 71 |
+
Kaarle Ritvanen
|
| 72 |
+
Khem Raj
|
| 73 |
+
Kylie McClain
|
| 74 |
+
Leah Neukirchen
|
| 75 |
+
Luca Barbato
|
| 76 |
+
Luka Perkov
|
| 77 |
+
M Farkas-Dyck (Strake)
|
| 78 |
+
Mahesh Bodapati
|
| 79 |
+
Markus Wichmann
|
| 80 |
+
Masanori Ogino
|
| 81 |
+
Michael Clark
|
| 82 |
+
Michael Forney
|
| 83 |
+
Mikhail Kremnyov
|
| 84 |
+
Natanael Copa
|
| 85 |
+
Nicholas J. Kain
|
| 86 |
+
orc
|
| 87 |
+
Pascal Cuoq
|
| 88 |
+
Patrick Oppenlander
|
| 89 |
+
Petr Hosek
|
| 90 |
+
Petr Skocik
|
| 91 |
+
Pierre Carrier
|
| 92 |
+
Reini Urban
|
| 93 |
+
Rich Felker
|
| 94 |
+
Richard Pennington
|
| 95 |
+
Ryan Fairfax
|
| 96 |
+
Samuel Holland
|
| 97 |
+
Segev Finer
|
| 98 |
+
Shiz
|
| 99 |
+
sin
|
| 100 |
+
Solar Designer
|
| 101 |
+
Stefan Kristiansson
|
| 102 |
+
Stefan O'Rear
|
| 103 |
+
Szabolcs Nagy
|
| 104 |
+
Timo Teräs
|
| 105 |
+
Trutz Behn
|
| 106 |
+
Valentin Ochs
|
| 107 |
+
Will Dietz
|
| 108 |
+
William Haddon
|
| 109 |
+
William Pitcock
|
| 110 |
+
|
| 111 |
+
Portions of this software are derived from third-party works licensed
|
| 112 |
+
under terms compatible with the above MIT license:
|
| 113 |
+
|
| 114 |
+
The TRE regular expression implementation (src/regex/reg* and
|
| 115 |
+
src/regex/tre*) is Copyright © 2001-2008 Ville Laurikari and licensed
|
| 116 |
+
under a 2-clause BSD license (license text in the source files). The
|
| 117 |
+
included version has been heavily modified by Rich Felker in 2012, in
|
| 118 |
+
the interests of size, simplicity, and namespace cleanliness.
|
| 119 |
+
|
| 120 |
+
Much of the math library code (src/math/* and src/complex/*) is
|
| 121 |
+
Copyright © 1993,2004 Sun Microsystems or
|
| 122 |
+
Copyright © 2003-2011 David Schultz or
|
| 123 |
+
Copyright © 2003-2009 Steven G. Kargl or
|
| 124 |
+
Copyright © 2003-2009 Bruce D. Evans or
|
| 125 |
+
Copyright © 2008 Stephen L. Moshier or
|
| 126 |
+
Copyright © 2017-2018 Arm Limited
|
| 127 |
+
and labelled as such in comments in the individual source files. All
|
| 128 |
+
have been licensed under extremely permissive terms.
|
| 129 |
+
|
| 130 |
+
The ARM memcpy code (src/string/arm/memcpy.S) is Copyright © 2008
|
| 131 |
+
The Android Open Source Project and is licensed under a two-clause BSD
|
| 132 |
+
license. It was taken from Bionic libc, used on Android.
|
| 133 |
+
|
| 134 |
+
The AArch64 memcpy and memset code (src/string/aarch64/*) are
|
| 135 |
+
Copyright © 1999-2019, Arm Limited.
|
| 136 |
+
|
| 137 |
+
The implementation of DES for crypt (src/crypt/crypt_des.c) is
|
| 138 |
+
Copyright © 1994 David Burren. It is licensed under a BSD license.
|
| 139 |
+
|
| 140 |
+
The implementation of blowfish crypt (src/crypt/crypt_blowfish.c) was
|
| 141 |
+
originally written by Solar Designer and placed into the public
|
| 142 |
+
domain. The code also comes with a fallback permissive license for use
|
| 143 |
+
in jurisdictions that may not recognize the public domain.
|
| 144 |
+
|
| 145 |
+
The smoothsort implementation (src/stdlib/qsort.c) is Copyright © 2011
|
| 146 |
+
Valentin Ochs and is licensed under an MIT-style license.
|
| 147 |
+
|
| 148 |
+
The x86_64 port was written by Nicholas J. Kain and is licensed under
|
| 149 |
+
the standard MIT terms.
|
| 150 |
+
|
| 151 |
+
The mips and microblaze ports were originally written by Richard
|
| 152 |
+
Pennington for use in the ellcc project. The original code was adapted
|
| 153 |
+
by Rich Felker for build system and code conventions during upstream
|
| 154 |
+
integration. It is licensed under the standard MIT terms.
|
| 155 |
+
|
| 156 |
+
The mips64 port was contributed by Imagination Technologies and is
|
| 157 |
+
licensed under the standard MIT terms.
|
| 158 |
+
|
| 159 |
+
The powerpc port was also originally written by Richard Pennington,
|
| 160 |
+
and later supplemented and integrated by John Spencer. It is licensed
|
| 161 |
+
under the standard MIT terms.
|
| 162 |
+
|
| 163 |
+
All other files which have no copyright comments are original works
|
| 164 |
+
produced specifically for use as part of this library, written either
|
| 165 |
+
by Rich Felker, the main author of the library, or by one or more
|
| 166 |
+
contibutors listed above. Details on authorship of individual files
|
| 167 |
+
can be found in the git version control history of the project. The
|
| 168 |
+
omission of copyright and license comments in each file is in the
|
| 169 |
+
interest of source tree size.
|
| 170 |
+
|
| 171 |
+
In addition, permission is hereby granted for all public header files
|
| 172 |
+
(include/* and arch/*/bits/*) and crt files intended to be linked into
|
| 173 |
+
applications (crt/*, ldso/dlstart.c, and arch/*/crt_arch.h) to omit
|
| 174 |
+
the copyright notice and permission notice otherwise required by the
|
| 175 |
+
license, and to use these files without any requirement of
|
| 176 |
+
attribution. These files include substantial contributions from:
|
| 177 |
+
|
| 178 |
+
Bobby Bingham
|
| 179 |
+
John Spencer
|
| 180 |
+
Nicholas J. Kain
|
| 181 |
+
Rich Felker
|
| 182 |
+
Richard Pennington
|
| 183 |
+
Stefan Kristiansson
|
| 184 |
+
Szabolcs Nagy
|
| 185 |
+
|
| 186 |
+
all of whom have explicitly granted such permission.
|
| 187 |
+
|
| 188 |
+
This file previously contained text expressing a belief that most of
|
| 189 |
+
the files covered by the above exception were sufficiently trivial not
|
| 190 |
+
to be subject to copyright, resulting in confusion over whether it
|
| 191 |
+
negated the permissions granted in the license. In the spirit of
|
| 192 |
+
permissive licensing, and of not having licensing issues being an
|
| 193 |
+
obstacle to adoption, that text has been removed.
|
venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/NUMPY_LICENSE
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright (c) 2005-2023, NumPy Developers.
|
| 2 |
+
All rights reserved.
|
| 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without
|
| 5 |
+
modification, are permitted provided that the following conditions are
|
| 6 |
+
met:
|
| 7 |
+
|
| 8 |
+
* Redistributions of source code must retain the above copyright
|
| 9 |
+
notice, this list of conditions and the following disclaimer.
|
| 10 |
+
|
| 11 |
+
* Redistributions in binary form must reproduce the above
|
| 12 |
+
copyright notice, this list of conditions and the following
|
| 13 |
+
disclaimer in the documentation and/or other materials provided
|
| 14 |
+
with the distribution.
|
| 15 |
+
|
| 16 |
+
* Neither the name of the NumPy Developers nor the names of any
|
| 17 |
+
contributors may be used to endorse or promote products derived
|
| 18 |
+
from this software without specific prior written permission.
|
| 19 |
+
|
| 20 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 21 |
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 22 |
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 23 |
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 24 |
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 25 |
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 26 |
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 27 |
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 28 |
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 29 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 30 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/PACKAGING_LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
Apache License
|
| 3 |
+
Version 2.0, January 2004
|
| 4 |
+
http://www.apache.org/licenses/
|
| 5 |
+
|
| 6 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 7 |
+
|
| 8 |
+
1. Definitions.
|
| 9 |
+
|
| 10 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 11 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 12 |
+
|
| 13 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 14 |
+
the copyright owner that is granting the License.
|
| 15 |
+
|
| 16 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 17 |
+
other entities that control, are controlled by, or are under common
|
| 18 |
+
control with that entity. For the purposes of this definition,
|
| 19 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 20 |
+
direction or management of such entity, whether by contract or
|
| 21 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 22 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 23 |
+
|
| 24 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 25 |
+
exercising permissions granted by this License.
|
| 26 |
+
|
| 27 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 28 |
+
including but not limited to software source code, documentation
|
| 29 |
+
source, and configuration files.
|
| 30 |
+
|
| 31 |
+
"Object" form shall mean any form resulting from mechanical
|
| 32 |
+
transformation or translation of a Source form, including but
|
| 33 |
+
not limited to compiled object code, generated documentation,
|
| 34 |
+
and conversions to other media types.
|
| 35 |
+
|
| 36 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 37 |
+
Object form, made available under the License, as indicated by a
|
| 38 |
+
copyright notice that is included in or attached to the work
|
| 39 |
+
(an example is provided in the Appendix below).
|
| 40 |
+
|
| 41 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 42 |
+
form, that is based on (or derived from) the Work and for which the
|
| 43 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 44 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 45 |
+
of this License, Derivative Works shall not include works that remain
|
| 46 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 47 |
+
the Work and Derivative Works thereof.
|
| 48 |
+
|
| 49 |
+
"Contribution" shall mean any work of authorship, including
|
| 50 |
+
the original version of the Work and any modifications or additions
|
| 51 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 52 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 53 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 54 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 55 |
+
means any form of electronic, verbal, or written communication sent
|
| 56 |
+
to the Licensor or its representatives, including but not limited to
|
| 57 |
+
communication on electronic mailing lists, source code control systems,
|
| 58 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 59 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 60 |
+
excluding communication that is conspicuously marked or otherwise
|
| 61 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 62 |
+
|
| 63 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 64 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 65 |
+
subsequently incorporated within the Work.
|
| 66 |
+
|
| 67 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 68 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 69 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 70 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 71 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 72 |
+
Work and such Derivative Works in Source or Object form.
|
| 73 |
+
|
| 74 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 75 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 76 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 77 |
+
(except as stated in this section) patent license to make, have made,
|
| 78 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 79 |
+
where such license applies only to those patent claims licensable
|
| 80 |
+
by such Contributor that are necessarily infringed by their
|
| 81 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 82 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 83 |
+
institute patent litigation against any entity (including a
|
| 84 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 85 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 86 |
+
or contributory patent infringement, then any patent licenses
|
| 87 |
+
granted to You under this License for that Work shall terminate
|
| 88 |
+
as of the date such litigation is filed.
|
| 89 |
+
|
| 90 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 91 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 92 |
+
modifications, and in Source or Object form, provided that You
|
| 93 |
+
meet the following conditions:
|
| 94 |
+
|
| 95 |
+
(a) You must give any other recipients of the Work or
|
| 96 |
+
Derivative Works a copy of this License; and
|
| 97 |
+
|
| 98 |
+
(b) You must cause any modified files to carry prominent notices
|
| 99 |
+
stating that You changed the files; and
|
| 100 |
+
|
| 101 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 102 |
+
that You distribute, all copyright, patent, trademark, and
|
| 103 |
+
attribution notices from the Source form of the Work,
|
| 104 |
+
excluding those notices that do not pertain to any part of
|
| 105 |
+
the Derivative Works; and
|
| 106 |
+
|
| 107 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 108 |
+
distribution, then any Derivative Works that You distribute must
|
| 109 |
+
include a readable copy of the attribution notices contained
|
| 110 |
+
within such NOTICE file, excluding those notices that do not
|
| 111 |
+
pertain to any part of the Derivative Works, in at least one
|
| 112 |
+
of the following places: within a NOTICE text file distributed
|
| 113 |
+
as part of the Derivative Works; within the Source form or
|
| 114 |
+
documentation, if provided along with the Derivative Works; or,
|
| 115 |
+
within a display generated by the Derivative Works, if and
|
| 116 |
+
wherever such third-party notices normally appear. The contents
|
| 117 |
+
of the NOTICE file are for informational purposes only and
|
| 118 |
+
do not modify the License. You may add Your own attribution
|
| 119 |
+
notices within Derivative Works that You distribute, alongside
|
| 120 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 121 |
+
that such additional attribution notices cannot be construed
|
| 122 |
+
as modifying the License.
|
| 123 |
+
|
| 124 |
+
You may add Your own copyright statement to Your modifications and
|
| 125 |
+
may provide additional or different license terms and conditions
|
| 126 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 127 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 128 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 129 |
+
the conditions stated in this License.
|
| 130 |
+
|
| 131 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 132 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 133 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 134 |
+
this License, without any additional terms or conditions.
|
| 135 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 136 |
+
the terms of any separate license agreement you may have executed
|
| 137 |
+
with Licensor regarding such Contributions.
|
| 138 |
+
|
| 139 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 140 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 141 |
+
except as required for reasonable and customary use in describing the
|
| 142 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 143 |
+
|
| 144 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 145 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 146 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 147 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 148 |
+
implied, including, without limitation, any warranties or conditions
|
| 149 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 150 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 151 |
+
appropriateness of using or redistributing the Work and assume any
|
| 152 |
+
risks associated with Your exercise of permissions under this License.
|
| 153 |
+
|
| 154 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 155 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 156 |
+
unless required by applicable law (such as deliberate and grossly
|
| 157 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 158 |
+
liable to You for damages, including any direct, indirect, special,
|
| 159 |
+
incidental, or consequential damages of any character arising as a
|
| 160 |
+
result of this License or out of the use or inability to use the
|
| 161 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 162 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 163 |
+
other commercial damages or losses), even if such Contributor
|
| 164 |
+
has been advised of the possibility of such damages.
|
| 165 |
+
|
| 166 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 167 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 168 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 169 |
+
or other liability obligations and/or rights consistent with this
|
| 170 |
+
License. However, in accepting such obligations, You may act only
|
| 171 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 172 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 173 |
+
defend, and hold each Contributor harmless for any liability
|
| 174 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 175 |
+
of your accepting any such warranty or additional liability.
|
| 176 |
+
|
| 177 |
+
END OF TERMS AND CONDITIONS
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
Copyright (c) Donald Stufft and individual contributors.
|
| 181 |
+
All rights reserved.
|
| 182 |
+
|
| 183 |
+
Redistribution and use in source and binary forms, with or without
|
| 184 |
+
modification, are permitted provided that the following conditions are met:
|
| 185 |
+
|
| 186 |
+
1. Redistributions of source code must retain the above copyright notice,
|
| 187 |
+
this list of conditions and the following disclaimer.
|
| 188 |
+
|
| 189 |
+
2. Redistributions in binary form must reproduce the above copyright
|
| 190 |
+
notice, this list of conditions and the following disclaimer in the
|
| 191 |
+
documentation and/or other materials provided with the distribution.
|
| 192 |
+
|
| 193 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
| 194 |
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
| 195 |
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 196 |
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
| 197 |
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 198 |
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 199 |
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 200 |
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
| 201 |
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 202 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/PSF_LICENSE
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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ematisch Centrum (CWI, see https://www.cwi.nl) in the Netherlands
|
| 6 |
+
as a successor of a language called ABC. Guido remains Python's
|
| 7 |
+
principal author, although it includes many contributions from others.
|
| 8 |
+
|
| 9 |
+
In 1995, Guido continued his work on Python at the Corporation for
|
| 10 |
+
National Research Initiatives (CNRI, see https://www.cnri.reston.va.us)
|
| 11 |
+
in Reston, Virginia where he released several versions of the
|
| 12 |
+
software.
|
| 13 |
+
|
| 14 |
+
In May 2000, Guido and the Python core development team moved to
|
| 15 |
+
BeOpen.com to form the BeOpen PythonLabs team. In October of the same
|
| 16 |
+
year, the PythonLabs team moved to Digital Creations, which became
|
| 17 |
+
Zope Corporation. In 2001, the Python Software Foundation (PSF, see
|
| 18 |
+
https://www.python.org/psf/) was formed, a non-profit organization
|
| 19 |
+
created specifically to own Python-related Intellectual Property.
|
| 20 |
+
Zope Corporation was a sponsoring member of the PSF.
|
| 21 |
+
|
| 22 |
+
All Python releases are Open Source (see https://opensource.org for
|
| 23 |
+
the Open Source Definition). Historically, most, but not all, Python
|
| 24 |
+
releases have also been GPL-compatible; the table below summarizes
|
| 25 |
+
the various releases.
|
| 26 |
+
|
| 27 |
+
Release Derived Year Owner GPL-
|
| 28 |
+
from compatible? (1)
|
| 29 |
+
|
| 30 |
+
0.9.0 thru 1.2 1991-1995 CWI yes
|
| 31 |
+
1.3 thru 1.5.2 1.2 1995-1999 CNRI yes
|
| 32 |
+
1.6 1.5.2 2000 CNRI no
|
| 33 |
+
2.0 1.6 2000 BeOpen.com no
|
| 34 |
+
1.6.1 1.6 2001 CNRI yes (2)
|
| 35 |
+
2.1 2.0+1.6.1 2001 PSF no
|
| 36 |
+
2.0.1 2.0+1.6.1 2001 PSF yes
|
| 37 |
+
2.1.1 2.1+2.0.1 2001 PSF yes
|
| 38 |
+
2.1.2 2.1.1 2002 PSF yes
|
| 39 |
+
2.1.3 2.1.2 2002 PSF yes
|
| 40 |
+
2.2 and above 2.1.1 2001-now PSF yes
|
| 41 |
+
|
| 42 |
+
Footnotes:
|
| 43 |
+
|
| 44 |
+
(1) GPL-compatible doesn't mean that we're distributing Python under
|
| 45 |
+
the GPL. All Python licenses, unlike the GPL, let you distribute
|
| 46 |
+
a modified version without making your changes open source. The
|
| 47 |
+
GPL-compatible licenses make it possible to combine Python with
|
| 48 |
+
other software that is released under the GPL; the others don't.
|
| 49 |
+
|
| 50 |
+
(2) According to Richard Stallman, 1.6.1 is not GPL-compatible,
|
| 51 |
+
because its license has a choice of law clause. According to
|
| 52 |
+
CNRI, however, Stallman's lawyer has told CNRI's lawyer that 1.6.1
|
| 53 |
+
is "not incompatible" with the GPL.
|
| 54 |
+
|
| 55 |
+
Thanks to the many outside volunteers who have worked under Guido's
|
| 56 |
+
direction to make these releases possible.
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
B. TERMS AND CONDITIONS FOR ACCESSING OR OTHERWISE USING PYTHON
|
| 60 |
+
===============================================================
|
| 61 |
+
|
| 62 |
+
Python software and documentation are licensed under the
|
| 63 |
+
Python Software Foundation License Version 2.
|
| 64 |
+
|
| 65 |
+
Starting with Python 3.8.6, examples, recipes, and other code in
|
| 66 |
+
the documentation are dual licensed under the PSF License Version 2
|
| 67 |
+
and the Zero-Clause BSD license.
|
| 68 |
+
|
| 69 |
+
Some software incorporated into Python is under different licenses.
|
| 70 |
+
The licenses are listed with code falling under that license.
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
|
| 74 |
+
--------------------------------------------
|
| 75 |
+
|
| 76 |
+
1. This LICENSE AGREEMENT is between the Python Software Foundation
|
| 77 |
+
("PSF"), and the Individual or Organization ("Licensee") accessing and
|
| 78 |
+
otherwise using this software ("Python") in source or binary form and
|
| 79 |
+
its associated documentation.
|
| 80 |
+
|
| 81 |
+
2. Subject to the terms and conditions of this License Agreement, PSF hereby
|
| 82 |
+
grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce,
|
| 83 |
+
analyze, test, perform and/or display publicly, prepare derivative works,
|
| 84 |
+
distribute, and otherwise use Python alone or in any derivative version,
|
| 85 |
+
provided, however, that PSF's License Agreement and PSF's notice of copyright,
|
| 86 |
+
i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
|
| 87 |
+
2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Python Software Foundation;
|
| 88 |
+
All Rights Reserved" are retained in Python alone or in any derivative version
|
| 89 |
+
prepared by Licensee.
|
| 90 |
+
|
| 91 |
+
3. In the event Licensee prepares a derivative work that is based on
|
| 92 |
+
or incorporates Python or any part thereof, and wants to make
|
| 93 |
+
the derivative work available to others as provided herein, then
|
| 94 |
+
Licensee hereby agrees to include in any such work a brief summary of
|
| 95 |
+
the changes made to Python.
|
| 96 |
+
|
| 97 |
+
4. PSF is making Python available to Licensee on an "AS IS"
|
| 98 |
+
basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
|
| 99 |
+
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
|
| 100 |
+
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
|
| 101 |
+
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
|
| 102 |
+
INFRINGE ANY THIRD PARTY RIGHTS.
|
| 103 |
+
|
| 104 |
+
5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
|
| 105 |
+
FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
|
| 106 |
+
A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON,
|
| 107 |
+
OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
|
| 108 |
+
|
| 109 |
+
6. This License Agreement will automatically terminate upon a material
|
| 110 |
+
breach of its terms and conditions.
|
| 111 |
+
|
| 112 |
+
7. Nothing in this License Agreement shall be deemed to create any
|
| 113 |
+
relationship of agency, partnership, or joint venture between PSF and
|
| 114 |
+
Licensee. This License Agreement does not grant permission to use PSF
|
| 115 |
+
trademarks or trade name in a trademark sense to endorse or promote
|
| 116 |
+
products or services of Licensee, or any third party.
|
| 117 |
+
|
| 118 |
+
8. By copying, installing or otherwise using Python, Licensee
|
| 119 |
+
agrees to be bound by the terms and conditions of this License
|
| 120 |
+
Agreement.
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
BEOPEN.COM LICENSE AGREEMENT FOR PYTHON 2.0
|
| 124 |
+
-------------------------------------------
|
| 125 |
+
|
| 126 |
+
BEOPEN PYTHON OPEN SOURCE LICENSE AGREEMENT VERSION 1
|
| 127 |
+
|
| 128 |
+
1. This LICENSE AGREEMENT is between BeOpen.com ("BeOpen"), having an
|
| 129 |
+
office at 160 Saratoga Avenue, Santa Clara, CA 95051, and the
|
| 130 |
+
Individual or Organization ("Licensee") accessing and otherwise using
|
| 131 |
+
this software in source or binary form and its associated
|
| 132 |
+
documentation ("the Software").
|
| 133 |
+
|
| 134 |
+
2. Subject to the terms and conditions of this BeOpen Python License
|
| 135 |
+
Agreement, BeOpen hereby grants Licensee a non-exclusive,
|
| 136 |
+
royalty-free, world-wide license to reproduce, analyze, test, perform
|
| 137 |
+
and/or display publicly, prepare derivative works, distribute, and
|
| 138 |
+
otherwise use the Software alone or in any derivative version,
|
| 139 |
+
provided, however, that the BeOpen Python License is retained in the
|
| 140 |
+
Software, alone or in any derivative version prepared by Licensee.
|
| 141 |
+
|
| 142 |
+
3. BeOpen is making the Software available to Licensee on an "AS IS"
|
| 143 |
+
basis. BEOPEN MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
|
| 144 |
+
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, BEOPEN MAKES NO AND
|
| 145 |
+
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
|
| 146 |
+
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE WILL NOT
|
| 147 |
+
INFRINGE ANY THIRD PARTY RIGHTS.
|
| 148 |
+
|
| 149 |
+
4. BEOPEN SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF THE
|
| 150 |
+
SOFTWARE FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS
|
| 151 |
+
AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE SOFTWARE, OR ANY
|
| 152 |
+
DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
|
| 153 |
+
|
| 154 |
+
5. This License Agreement will automatically terminate upon a material
|
| 155 |
+
breach of its terms and conditions.
|
| 156 |
+
|
| 157 |
+
6. This License Agreement shall be governed by and interpreted in all
|
| 158 |
+
respects by the law of the State of California, excluding conflict of
|
| 159 |
+
law provisions. Nothing in this License Agreement shall be deemed to
|
| 160 |
+
create any relationship of agency, partnership, or joint venture
|
| 161 |
+
between BeOpen and Licensee. This License Agreement does not grant
|
| 162 |
+
permission to use BeOpen trademarks or trade names in a trademark
|
| 163 |
+
sense to endorse or promote products or services of Licensee, or any
|
| 164 |
+
third party. As an exception, the "BeOpen Python" logos available at
|
| 165 |
+
http://www.pythonlabs.com/logos.html may be used according to the
|
| 166 |
+
permissions granted on that web page.
|
| 167 |
+
|
| 168 |
+
7. By copying, installing or otherwise using the software, Licensee
|
| 169 |
+
agrees to be bound by the terms and conditions of this License
|
| 170 |
+
Agreement.
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
CNRI LICENSE AGREEMENT FOR PYTHON 1.6.1
|
| 174 |
+
---------------------------------------
|
| 175 |
+
|
| 176 |
+
1. This LICENSE AGREEMENT is between the Corporation for National
|
| 177 |
+
Research Initiatives, having an office at 1895 Preston White Drive,
|
| 178 |
+
Reston, VA 20191 ("CNRI"), and the Individual or Organization
|
| 179 |
+
("Licensee") accessing and otherwise using Python 1.6.1 software in
|
| 180 |
+
source or binary form and its associated documentation.
|
| 181 |
+
|
| 182 |
+
2. Subject to the terms and conditions of this License Agreement, CNRI
|
| 183 |
+
hereby grants Licensee a nonexclusive, royalty-free, world-wide
|
| 184 |
+
license to reproduce, analyze, test, perform and/or display publicly,
|
| 185 |
+
prepare derivative works, distribute, and otherwise use Python 1.6.1
|
| 186 |
+
alone or in any derivative version, provided, however, that CNRI's
|
| 187 |
+
License Agreement and CNRI's notice of copyright, i.e., "Copyright (c)
|
| 188 |
+
1995-2001 Corporation for National Research Initiatives; All Rights
|
| 189 |
+
Reserved" are retained in Python 1.6.1 alone or in any derivative
|
| 190 |
+
version prepared by Licensee. Alternately, in lieu of CNRI's License
|
| 191 |
+
Agreement, Licensee may substitute the following text (omitting the
|
| 192 |
+
quotes): "Python 1.6.1 is made available subject to the terms and
|
| 193 |
+
conditions in CNRI's License Agreement. This Agreement together with
|
| 194 |
+
Python 1.6.1 may be located on the internet using the following
|
| 195 |
+
unique, persistent identifier (known as a handle): 1895.22/1013. This
|
| 196 |
+
Agreement may also be obtained from a proxy server on the internet
|
| 197 |
+
using the following URL: http://hdl.handle.net/1895.22/1013".
|
| 198 |
+
|
| 199 |
+
3. In the event Licensee prepares a derivative work that is based on
|
| 200 |
+
or incorporates Python 1.6.1 or any part thereof, and wants to make
|
| 201 |
+
the derivative work available to others as provided herein, then
|
| 202 |
+
Licensee hereby agrees to include in any such work a brief summary of
|
| 203 |
+
the changes made to Python 1.6.1.
|
| 204 |
+
|
| 205 |
+
4. CNRI is making Python 1.6.1 available to Licensee on an "AS IS"
|
| 206 |
+
basis. CNRI MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
|
| 207 |
+
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, CNRI MAKES NO AND
|
| 208 |
+
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
|
| 209 |
+
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON 1.6.1 WILL NOT
|
| 210 |
+
INFRINGE ANY THIRD PARTY RIGHTS.
|
| 211 |
+
|
| 212 |
+
5. CNRI SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
|
| 213 |
+
1.6.1 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
|
| 214 |
+
A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 1.6.1,
|
| 215 |
+
OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
|
| 216 |
+
|
| 217 |
+
6. This License Agreement will automatically terminate upon a material
|
| 218 |
+
breach of its terms and conditions.
|
| 219 |
+
|
| 220 |
+
7. This License Agreement shall be governed by the federal
|
| 221 |
+
intellectual property law of the United States, including without
|
| 222 |
+
limitation the federal copyright law, and, to the extent such
|
| 223 |
+
U.S. federal law does not apply, by the law of the Commonwealth of
|
| 224 |
+
Virginia, excluding Virginia's conflict of law provisions.
|
| 225 |
+
Notwithstanding the foregoing, with regard to derivative works based
|
| 226 |
+
on Python 1.6.1 that incorporate non-separable material that was
|
| 227 |
+
previously distributed under the GNU General Public License (GPL), the
|
| 228 |
+
law of the Commonwealth of Virginia shall govern this License
|
| 229 |
+
Agreement only as to issues arising under or with respect to
|
| 230 |
+
Paragraphs 4, 5, and 7 of this License Agreement. Nothing in this
|
| 231 |
+
License Agreement shall be deemed to create any relationship of
|
| 232 |
+
agency, partnership, or joint venture between CNRI and Licensee. This
|
| 233 |
+
License Agreement does not grant permission to use CNRI trademarks or
|
| 234 |
+
trade name in a trademark sense to endorse or promote products or
|
| 235 |
+
services of Licensee, or any third party.
|
| 236 |
+
|
| 237 |
+
8. By clicking on the "ACCEPT" button where indicated, or by copying,
|
| 238 |
+
installing or otherwise using Python 1.6.1, Licensee agrees to be
|
| 239 |
+
bound by the terms and conditions of this License Agreement.
|
| 240 |
+
|
| 241 |
+
ACCEPT
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
CWI LICENSE AGREEMENT FOR PYTHON 0.9.0 THROUGH 1.2
|
| 245 |
+
--------------------------------------------------
|
| 246 |
+
|
| 247 |
+
Copyright (c) 1991 - 1995, Stichting Mathematisch Centrum Amsterdam,
|
| 248 |
+
The Netherlands. All rights reserved.
|
| 249 |
+
|
| 250 |
+
Permission to use, copy, modify, and distribute this software and its
|
| 251 |
+
documentation for any purpose and without fee is hereby granted,
|
| 252 |
+
provided that the above copyright notice appear in all copies and that
|
| 253 |
+
both that copyright notice and this permission notice appear in
|
| 254 |
+
supporting documentation, and that the name of Stichting Mathematisch
|
| 255 |
+
Centrum or CWI not be used in advertising or publicity pertaining to
|
| 256 |
+
distribution of the software without specific, written prior
|
| 257 |
+
permission.
|
| 258 |
+
|
| 259 |
+
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
|
| 260 |
+
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
| 261 |
+
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
|
| 262 |
+
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
| 263 |
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
| 264 |
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
| 265 |
+
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
| 266 |
+
|
| 267 |
+
ZERO-CLAUSE BSD LICENSE FOR CODE IN THE PYTHON DOCUMENTATION
|
| 268 |
+
----------------------------------------------------------------------
|
| 269 |
+
|
| 270 |
+
Permission to use, copy, modify, and/or distribute this software for any
|
| 271 |
+
purpose with or without fee is hereby granted.
|
| 272 |
+
|
| 273 |
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
| 274 |
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
| 275 |
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
| 276 |
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
| 277 |
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
| 278 |
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
| 279 |
+
PERFORMANCE OF THIS SOFTWARE.
|
venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/PYPERCLIP_LICENSE
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright (c) 2014, Al Sweigart
|
| 2 |
+
All rights reserved.
|
| 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without
|
| 5 |
+
modification, are permitted provided that the following conditions are met:
|
| 6 |
+
|
| 7 |
+
* Redistributions of source code must retain the above copyright notice, this
|
| 8 |
+
list of conditions and the following disclaimer.
|
| 9 |
+
|
| 10 |
+
* Redistributions in binary form must reproduce the above copyright notice,
|
| 11 |
+
this list of conditions and the following disclaimer in the documentation
|
| 12 |
+
and/or other materials provided with the distribution.
|
| 13 |
+
|
| 14 |
+
* Neither the name of the {organization} nor the names of its
|
| 15 |
+
contributors may be used to endorse or promote products derived from
|
| 16 |
+
this software without specific prior written permission.
|
| 17 |
+
|
| 18 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 19 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 20 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 21 |
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
| 22 |
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 23 |
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 24 |
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 25 |
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
| 26 |
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 27 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/PYUPGRADE_LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright (c) 2017 Anthony Sottile
|
| 2 |
+
|
| 3 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 4 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 5 |
+
in the Software without restriction, including without limitation the rights
|
| 6 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 7 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 8 |
+
furnished to do so, subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
The above copyright notice and this permission notice shall be included in
|
| 11 |
+
all copies or substantial portions of the Software.
|
| 12 |
+
|
| 13 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 14 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 15 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 16 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 17 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 18 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 19 |
+
THE SOFTWARE.
|
venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/SAS7BDAT_LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright (c) 2015-2019 Jared Hobbs
|
| 2 |
+
|
| 3 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
| 4 |
+
this software and associated documentation files (the "Software"), to deal in
|
| 5 |
+
the Software without restriction, including without limitation the rights to
|
| 6 |
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
| 7 |
+
of the Software, and to permit persons to whom the Software is furnished to do
|
| 8 |
+
so, subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
The above copyright notice and this permission notice shall be included in all
|
| 11 |
+
copies or substantial portions of the Software.
|
| 12 |
+
|
| 13 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 14 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 15 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 16 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 17 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 18 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 19 |
+
SOFTWARE.
|
venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/STATSBASE_JL_LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
StatsBase.jl is licensed under the MIT License:
|
| 2 |
+
|
| 3 |
+
> Copyright (c) 2012-2016: Dahua Lin, Simon Byrne, Andreas Noack,
|
| 4 |
+
> Douglas Bates, John Myles White, Simon Kornblith, and other contributors.
|
| 5 |
+
|
| 6 |
+
> Permission is hereby granted, free of charge, to any person obtaining
|
| 7 |
+
> a copy of this software and associated documentation files (the
|
| 8 |
+
> "Software"), to deal in the Software without restriction, including
|
| 9 |
+
> without limitation the rights to use, copy, modify, merge, publish,
|
| 10 |
+
> distribute, sublicense, and/or sell copies of the Software, and to
|
| 11 |
+
> permit persons to whom the Software is furnished to do so, subject to
|
| 12 |
+
> the following conditions:
|
| 13 |
+
>
|
| 14 |
+
> The above copyright notice and this permission notice shall be
|
| 15 |
+
> included in all copies or substantial portions of the Software.
|
| 16 |
+
>
|
| 17 |
+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 18 |
+
> EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
| 19 |
+
> MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
| 20 |
+
> NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
| 21 |
+
> LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
| 22 |
+
> OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
| 23 |
+
> WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/ULTRAJSON_LICENSE
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Developed by ESN, an Electronic Arts Inc. studio.
|
| 2 |
+
Copyright (c) 2014, Electronic Arts Inc.
|
| 3 |
+
All rights reserved.
|
| 4 |
+
|
| 5 |
+
Redistribution and use in source and binary forms, with or without
|
| 6 |
+
modification, are permitted provided that the following conditions are met:
|
| 7 |
+
* Redistributions of source code must retain the above copyright
|
| 8 |
+
notice, this list of conditions and the following disclaimer.
|
| 9 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 10 |
+
notice, this list of conditions and the following disclaimer in the
|
| 11 |
+
documentation and/or other materials provided with the distribution.
|
| 12 |
+
* Neither the name of ESN, Electronic Arts Inc. nor the
|
| 13 |
+
names of its contributors may be used to endorse or promote products
|
| 14 |
+
derived from this software without specific prior written permission.
|
| 15 |
+
|
| 16 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
| 17 |
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
| 18 |
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 19 |
+
DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS INC. BE LIABLE
|
| 20 |
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 21 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 22 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 23 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 24 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 25 |
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 26 |
+
|
| 27 |
+
----
|
| 28 |
+
|
| 29 |
+
Portions of code from MODP_ASCII - Ascii transformations (upper/lower, etc)
|
| 30 |
+
https://github.com/client9/stringencoders
|
| 31 |
+
|
| 32 |
+
Copyright 2005, 2006, 2007
|
| 33 |
+
Nick Galbreath -- nickg [at] modp [dot] com
|
| 34 |
+
All rights reserved.
|
| 35 |
+
|
| 36 |
+
Redistribution and use in source and binary forms, with or without
|
| 37 |
+
modification, are permitted provided that the following conditions are
|
| 38 |
+
met:
|
| 39 |
+
|
| 40 |
+
Redistributions of source code must retain the above copyright
|
| 41 |
+
notice, this list of conditions and the following disclaimer.
|
| 42 |
+
|
| 43 |
+
Redistributions in binary form must reproduce the above copyright
|
| 44 |
+
notice, this list of conditions and the following disclaimer in the
|
| 45 |
+
documentation and/or other materials provided with the distribution.
|
| 46 |
+
|
| 47 |
+
Neither the name of the modp.com nor the names of its
|
| 48 |
+
contributors may be used to endorse or promote products derived from
|
| 49 |
+
this software without specific prior written permission.
|
| 50 |
+
|
| 51 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 52 |
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 53 |
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 54 |
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 55 |
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 56 |
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 57 |
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 58 |
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 59 |
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 60 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 61 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 62 |
+
|
| 63 |
+
This is the standard "new" BSD license:
|
| 64 |
+
http://www.opensource.org/licenses/bsd-license.php
|
| 65 |
+
|
| 66 |
+
https://github.com/client9/stringencoders/blob/cfd5c1507325ae497ea9bacdacba12c0ffd79d30/COPYING
|
| 67 |
+
|
| 68 |
+
----
|
| 69 |
+
|
| 70 |
+
Numeric decoder derived from from TCL library
|
| 71 |
+
https://opensource.apple.com/source/tcl/tcl-14/tcl/license.terms
|
| 72 |
+
* Copyright (c) 1988-1993 The Regents of the University of California.
|
| 73 |
+
* Copyright (c) 1994 Sun Microsystems, Inc.
|
| 74 |
+
|
| 75 |
+
This software is copyrighted by the Regents of the University of
|
| 76 |
+
California, Sun Microsystems, Inc., Scriptics Corporation, ActiveState
|
| 77 |
+
Corporation and other parties. The following terms apply to all files
|
| 78 |
+
associated with the software unless explicitly disclaimed in
|
| 79 |
+
individual files.
|
| 80 |
+
|
| 81 |
+
The authors hereby grant permission to use, copy, modify, distribute,
|
| 82 |
+
and license this software and its documentation for any purpose, provided
|
| 83 |
+
that existing copyright notices are retained in all copies and that this
|
| 84 |
+
notice is included verbatim in any distributions. No written agreement,
|
| 85 |
+
license, or royalty fee is required for any of the authorized uses.
|
| 86 |
+
Modifications to this software may be copyrighted by their authors
|
| 87 |
+
and need not follow the licensing terms described here, provided that
|
| 88 |
+
the new terms are clearly indicated on the first page of each file where
|
| 89 |
+
they apply.
|
| 90 |
+
|
| 91 |
+
IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
|
| 92 |
+
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
| 93 |
+
ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
|
| 94 |
+
DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
|
| 95 |
+
POSSIBILITY OF SUCH DAMAGE.
|
| 96 |
+
|
| 97 |
+
THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
|
| 98 |
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
| 99 |
+
FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE
|
| 100 |
+
IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
|
| 101 |
+
NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
|
| 102 |
+
MODIFICATIONS.
|
| 103 |
+
|
| 104 |
+
GOVERNMENT USE: If you are acquiring this software on behalf of the
|
| 105 |
+
U.S. government, the Government shall have only "Restricted Rights"
|
| 106 |
+
in the software and related documentation as defined in the Federal
|
| 107 |
+
Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you
|
| 108 |
+
are acquiring the software on behalf of the Department of Defense, the
|
| 109 |
+
software shall be classified as "Commercial Computer Software" and the
|
| 110 |
+
Government shall have only "Restricted Rights" as defined in Clause
|
| 111 |
+
252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the
|
| 112 |
+
authors grant the U.S. Government and others acting in its behalf
|
| 113 |
+
permission to use and distribute the software in accordance with the
|
| 114 |
+
terms specified in this license.
|
venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/LICENSES/XSIMD_LICENSE
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright (c) 2016, Johan Mabille, Sylvain Corlay, Wolf Vollprecht and Martin Renou
|
| 2 |
+
Copyright (c) 2016, QuantStack
|
| 3 |
+
Copyright (c) 2018, Serge Guelton
|
| 4 |
+
All rights reserved.
|
| 5 |
+
|
| 6 |
+
Redistribution and use in source and binary forms, with or without
|
| 7 |
+
modification, are permitted provided that the following conditions are met:
|
| 8 |
+
|
| 9 |
+
* Redistributions of source code must retain the above copyright notice, this
|
| 10 |
+
list of conditions and the following disclaimer.
|
| 11 |
+
|
| 12 |
+
* Redistributions in binary form must reproduce the above copyright notice,
|
| 13 |
+
this list of conditions and the following disclaimer in the documentation
|
| 14 |
+
and/or other materials provided with the distribution.
|
| 15 |
+
|
| 16 |
+
* Neither the name of the copyright holder nor the names of its
|
| 17 |
+
contributors may be used to endorse or promote products derived from
|
| 18 |
+
this software without specific prior written permission.
|
| 19 |
+
|
| 20 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 21 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 22 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 23 |
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
| 24 |
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 25 |
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 26 |
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 27 |
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
| 28 |
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 29 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/subprojects/fast_float-8.2.10/LICENSE-APACHE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Apache License
|
| 2 |
+
Version 2.0, January 2004
|
| 3 |
+
http://www.apache.org/licenses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 13 |
+
the copyright owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 16 |
+
other entities that control, are controlled by, or are under common
|
| 17 |
+
control with that entity. For the purposes of this definition,
|
| 18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 19 |
+
direction or management of such entity, whether by contract or
|
| 20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 22 |
+
|
| 23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 24 |
+
exercising permissions granted by this License.
|
| 25 |
+
|
| 26 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 27 |
+
including but not limited to software source code, documentation
|
| 28 |
+
source, and configuration files.
|
| 29 |
+
|
| 30 |
+
"Object" form shall mean any form resulting from mechanical
|
| 31 |
+
transformation or translation of a Source form, including but
|
| 32 |
+
not limited to compiled object code, generated documentation,
|
| 33 |
+
and conversions to other media types.
|
| 34 |
+
|
| 35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 36 |
+
Object form, made available under the License, as indicated by a
|
| 37 |
+
copyright notice that is included in or attached to the work
|
| 38 |
+
(an example is provided in the Appendix below).
|
| 39 |
+
|
| 40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 41 |
+
form, that is based on (or derived from) the Work and for which the
|
| 42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 44 |
+
of this License, Derivative Works shall not include works that remain
|
| 45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 46 |
+
the Work and Derivative Works thereof.
|
| 47 |
+
|
| 48 |
+
"Contribution" shall mean any work of authorship, including
|
| 49 |
+
the original version of the Work and any modifications or additions
|
| 50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 54 |
+
means any form of electronic, verbal, or written communication sent
|
| 55 |
+
to the Licensor or its representatives, including but not limited to
|
| 56 |
+
communication on electronic mailing lists, source code control systems,
|
| 57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 59 |
+
excluding communication that is conspicuously marked or otherwise
|
| 60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 61 |
+
|
| 62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 64 |
+
subsequently incorporated within the Work.
|
| 65 |
+
|
| 66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 71 |
+
Work and such Derivative Works in Source or Object form.
|
| 72 |
+
|
| 73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 76 |
+
(except as stated in this section) patent license to make, have made,
|
| 77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 78 |
+
where such license applies only to those patent claims licensable
|
| 79 |
+
by such Contributor that are necessarily infringed by their
|
| 80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 82 |
+
institute patent litigation against any entity (including a
|
| 83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 84 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 85 |
+
or contributory patent infringement, then any patent licenses
|
| 86 |
+
granted to You under this License for that Work shall terminate
|
| 87 |
+
as of the date such litigation is filed.
|
| 88 |
+
|
| 89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 90 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 91 |
+
modifications, and in Source or Object form, provided that You
|
| 92 |
+
meet the following conditions:
|
| 93 |
+
|
| 94 |
+
(a) You must give any other recipients of the Work or
|
| 95 |
+
Derivative Works a copy of this License; and
|
| 96 |
+
|
| 97 |
+
(b) You must cause any modified files to carry prominent notices
|
| 98 |
+
stating that You changed the files; and
|
| 99 |
+
|
| 100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 101 |
+
that You distribute, all copyright, patent, trademark, and
|
| 102 |
+
attribution notices from the Source form of the Work,
|
| 103 |
+
excluding those notices that do not pertain to any part of
|
| 104 |
+
the Derivative Works; and
|
| 105 |
+
|
| 106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 107 |
+
distribution, then any Derivative Works that You distribute must
|
| 108 |
+
include a readable copy of the attribution notices contained
|
| 109 |
+
within such NOTICE file, excluding those notices that do not
|
| 110 |
+
pertain to any part of the Derivative Works, in at least one
|
| 111 |
+
of the following places: within a NOTICE text file distributed
|
| 112 |
+
as part of the Derivative Works; within the Source form or
|
| 113 |
+
documentation, if provided along with the Derivative Works; or,
|
| 114 |
+
within a display generated by the Derivative Works, if and
|
| 115 |
+
wherever such third-party notices normally appear. The contents
|
| 116 |
+
of the NOTICE file are for informational purposes only and
|
| 117 |
+
do not modify the License. You may add Your own attribution
|
| 118 |
+
notices within Derivative Works that You distribute, alongside
|
| 119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 120 |
+
that such additional attribution notices cannot be construed
|
| 121 |
+
as modifying the License.
|
| 122 |
+
|
| 123 |
+
You may add Your own copyright statement to Your modifications and
|
| 124 |
+
may provide additional or different license terms and conditions
|
| 125 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 126 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 127 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 128 |
+
the conditions stated in this License.
|
| 129 |
+
|
| 130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 132 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 133 |
+
this License, without any additional terms or conditions.
|
| 134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 135 |
+
the terms of any separate license agreement you may have executed
|
| 136 |
+
with Licensor regarding such Contributions.
|
| 137 |
+
|
| 138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 140 |
+
except as required for reasonable and customary use in describing the
|
| 141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 142 |
+
|
| 143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 144 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 147 |
+
implied, including, without limitation, any warranties or conditions
|
| 148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 150 |
+
appropriateness of using or redistributing the Work and assume any
|
| 151 |
+
risks associated with Your exercise of permissions under this License.
|
| 152 |
+
|
| 153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 154 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 155 |
+
unless required by applicable law (such as deliberate and grossly
|
| 156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 157 |
+
liable to You for damages, including any direct, indirect, special,
|
| 158 |
+
incidental, or consequential damages of any character arising as a
|
| 159 |
+
result of this License or out of the use or inability to use the
|
| 160 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 161 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 162 |
+
other commercial damages or losses), even if such Contributor
|
| 163 |
+
has been advised of the possibility of such damages.
|
| 164 |
+
|
| 165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 168 |
+
or other liability obligations and/or rights consistent with this
|
| 169 |
+
License. However, in accepting such obligations, You may act only
|
| 170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 171 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 172 |
+
defend, and hold each Contributor harmless for any liability
|
| 173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 174 |
+
of your accepting any such warranty or additional liability.
|
| 175 |
+
|
| 176 |
+
END OF TERMS AND CONDITIONS
|
| 177 |
+
|
| 178 |
+
Copyright 2021 The fast_float authors
|
| 179 |
+
|
| 180 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 181 |
+
you may not use this file except in compliance with the License.
|
| 182 |
+
You may obtain a copy of the License at
|
| 183 |
+
|
| 184 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 185 |
+
|
| 186 |
+
Unless required by applicable law or agreed to in writing, software
|
| 187 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 188 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 189 |
+
See the License for the specific language governing permissions and
|
| 190 |
+
limitations under the License.
|
venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/subprojects/fast_float-8.2.10/LICENSE-BOOST
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Boost Software License - Version 1.0 - August 17th, 2003
|
| 2 |
+
|
| 3 |
+
Permission is hereby granted, free of charge, to any person or organization
|
| 4 |
+
obtaining a copy of the software and accompanying documentation covered by
|
| 5 |
+
this license (the "Software") to use, reproduce, display, distribute,
|
| 6 |
+
execute, and transmit the Software, and to prepare derivative works of the
|
| 7 |
+
Software, and to permit third-parties to whom the Software is furnished to
|
| 8 |
+
do so, all subject to the following:
|
| 9 |
+
|
| 10 |
+
The copyright notices in the Software and this entire statement, including
|
| 11 |
+
the above license grant, this restriction and the following disclaimer,
|
| 12 |
+
must be included in all copies of the Software, in whole or in part, and
|
| 13 |
+
all derivative works of the Software, unless such copies or derivative
|
| 14 |
+
works are solely in the form of machine-executable object code generated by
|
| 15 |
+
a source language processor.
|
| 16 |
+
|
| 17 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 18 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 19 |
+
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
| 20 |
+
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
| 21 |
+
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
| 22 |
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
| 23 |
+
DEALINGS IN THE SOFTWARE.
|
venv/lib/python3.14/site-packages/pandas-3.1.1.dist-info/licenses/subprojects/fast_float-8.2.10/LICENSE-MIT
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2021 The fast_float authors
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any
|
| 6 |
+
person obtaining a copy of this software and associated
|
| 7 |
+
documentation files (the "Software"), to deal in the
|
| 8 |
+
Software without restriction, including without
|
| 9 |
+
limitation the rights to use, copy, modify, merge,
|
| 10 |
+
publish, distribute, sublicense, and/or sell copies of
|
| 11 |
+
the Software, and to permit persons to whom the Software
|
| 12 |
+
is furnished to do so, subject to the following
|
| 13 |
+
conditions:
|
| 14 |
+
|
| 15 |
+
The above copyright notice and this permission notice
|
| 16 |
+
shall be included in all copies or substantial portions
|
| 17 |
+
of the Software.
|
| 18 |
+
|
| 19 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
| 20 |
+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
| 21 |
+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
| 22 |
+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
| 23 |
+
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
| 24 |
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
| 25 |
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
| 26 |
+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
| 27 |
+
DEALINGS IN THE SOFTWARE.
|
venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_diff.py
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import pytest
|
| 3 |
+
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import pandas._testing as tm
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class TestDataFrameDiff:
|
| 9 |
+
def test_diff_requires_integer(self):
|
| 10 |
+
df = pd.DataFrame(np.random.default_rng(2).standard_normal((2, 2)))
|
| 11 |
+
with pytest.raises(ValueError, match="periods must be an integer"):
|
| 12 |
+
df.diff(1.5)
|
| 13 |
+
|
| 14 |
+
# GH#44572 np.int64 is accepted
|
| 15 |
+
@pytest.mark.parametrize("num", [1, np.int64(1)])
|
| 16 |
+
def test_diff(self, datetime_frame, num):
|
| 17 |
+
df = datetime_frame
|
| 18 |
+
the_diff = df.diff(num)
|
| 19 |
+
|
| 20 |
+
expected = df["A"] - df["A"].shift(num)
|
| 21 |
+
tm.assert_series_equal(the_diff["A"], expected)
|
| 22 |
+
|
| 23 |
+
def test_diff_int_dtype(self):
|
| 24 |
+
# int dtype
|
| 25 |
+
a = 10_000_000_000_000_000
|
| 26 |
+
b = a + 1
|
| 27 |
+
ser = pd.Series([a, b])
|
| 28 |
+
|
| 29 |
+
rs = pd.DataFrame({"s": ser}).diff()
|
| 30 |
+
assert rs.s[1] == 1
|
| 31 |
+
|
| 32 |
+
def test_diff_mixed_numeric(self, datetime_frame):
|
| 33 |
+
# mixed numeric
|
| 34 |
+
tf = datetime_frame.astype("float32")
|
| 35 |
+
the_diff = tf.diff(1)
|
| 36 |
+
tm.assert_series_equal(the_diff["A"], tf["A"] - tf["A"].shift(1))
|
| 37 |
+
|
| 38 |
+
def test_diff_axis1_nonconsolidated(self):
|
| 39 |
+
# GH#10907
|
| 40 |
+
df = pd.DataFrame({"y": pd.Series([2]), "z": pd.Series([3])})
|
| 41 |
+
df.insert(0, "x", 1)
|
| 42 |
+
result = df.diff(axis=1)
|
| 43 |
+
expected = pd.DataFrame({"x": np.nan, "y": pd.Series(1), "z": pd.Series(1)})
|
| 44 |
+
tm.assert_frame_equal(result, expected)
|
| 45 |
+
|
| 46 |
+
def test_diff_timedelta64_with_nat(self):
|
| 47 |
+
# GH#32441
|
| 48 |
+
arr = np.arange(6).reshape(3, 2).astype("timedelta64[ns]")
|
| 49 |
+
arr[:, 0] = np.timedelta64("NaT", "ns")
|
| 50 |
+
|
| 51 |
+
df = pd.DataFrame(arr)
|
| 52 |
+
result = df.diff(1, axis=0)
|
| 53 |
+
|
| 54 |
+
expected = pd.DataFrame(
|
| 55 |
+
{0: df[0], 1: [pd.NaT, pd.Timedelta(2), pd.Timedelta(2)]}
|
| 56 |
+
)
|
| 57 |
+
tm.assert_equal(result, expected)
|
| 58 |
+
|
| 59 |
+
result = df.diff(0)
|
| 60 |
+
expected = df - df
|
| 61 |
+
assert expected[0].isna().all()
|
| 62 |
+
tm.assert_equal(result, expected)
|
| 63 |
+
|
| 64 |
+
result = df.diff(-1, axis=1)
|
| 65 |
+
expected = df * np.nan
|
| 66 |
+
tm.assert_equal(result, expected)
|
| 67 |
+
|
| 68 |
+
@pytest.mark.parametrize("tz", [None, "UTC"])
|
| 69 |
+
def test_diff_datetime_axis0_with_nat(self, tz, unit):
|
| 70 |
+
# GH#32441
|
| 71 |
+
dti = pd.DatetimeIndex(["NaT", "2019-01-01", "2019-01-02"], tz=tz).as_unit(unit)
|
| 72 |
+
ser = pd.Series(dti)
|
| 73 |
+
|
| 74 |
+
df = ser.to_frame()
|
| 75 |
+
|
| 76 |
+
result = df.diff()
|
| 77 |
+
ex_index = pd.TimedeltaIndex([pd.NaT, pd.NaT, pd.Timedelta(days=1)]).as_unit(
|
| 78 |
+
unit
|
| 79 |
+
)
|
| 80 |
+
expected = pd.Series(ex_index).to_frame()
|
| 81 |
+
tm.assert_frame_equal(result, expected)
|
| 82 |
+
|
| 83 |
+
@pytest.mark.parametrize("tz", [None, "UTC"])
|
| 84 |
+
def test_diff_datetime_with_nat_zero_periods(self, tz):
|
| 85 |
+
# diff on NaT values should give NaT, not timedelta64(0)
|
| 86 |
+
dti = pd.date_range("2016-01-01", periods=4, tz=tz)
|
| 87 |
+
ser = pd.Series(dti)
|
| 88 |
+
df = ser.to_frame().copy()
|
| 89 |
+
|
| 90 |
+
df[1] = ser.copy()
|
| 91 |
+
|
| 92 |
+
df.iloc[:, 0] = pd.NaT
|
| 93 |
+
|
| 94 |
+
expected = df - df
|
| 95 |
+
assert expected[0].isna().all()
|
| 96 |
+
|
| 97 |
+
result = df.diff(0, axis=0)
|
| 98 |
+
tm.assert_frame_equal(result, expected)
|
| 99 |
+
|
| 100 |
+
result = df.diff(0, axis=1)
|
| 101 |
+
tm.assert_frame_equal(result, expected)
|
| 102 |
+
|
| 103 |
+
@pytest.mark.parametrize("tz", [None, "UTC"])
|
| 104 |
+
def test_diff_datetime_axis0(self, tz):
|
| 105 |
+
# GH#18578
|
| 106 |
+
df = pd.DataFrame(
|
| 107 |
+
{
|
| 108 |
+
0: pd.date_range("2010", freq="D", periods=2, tz=tz),
|
| 109 |
+
1: pd.date_range("2010", freq="D", periods=2, tz=tz),
|
| 110 |
+
}
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
result = df.diff(axis=0)
|
| 114 |
+
expected = pd.DataFrame(
|
| 115 |
+
{
|
| 116 |
+
0: pd.TimedeltaIndex(["NaT", "1 days"]),
|
| 117 |
+
1: pd.TimedeltaIndex(["NaT", "1 days"]),
|
| 118 |
+
}
|
| 119 |
+
)
|
| 120 |
+
tm.assert_frame_equal(result, expected)
|
| 121 |
+
|
| 122 |
+
@pytest.mark.parametrize("tz", [None, "UTC"])
|
| 123 |
+
def test_diff_datetime_axis1(self, tz):
|
| 124 |
+
# GH#18578
|
| 125 |
+
df = pd.DataFrame(
|
| 126 |
+
{
|
| 127 |
+
0: pd.date_range("2010", freq="D", periods=2, tz=tz),
|
| 128 |
+
1: pd.date_range("2010", freq="D", periods=2, tz=tz),
|
| 129 |
+
}
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
result = df.diff(axis=1)
|
| 133 |
+
expected = pd.DataFrame(
|
| 134 |
+
{
|
| 135 |
+
0: pd.TimedeltaIndex(["NaT", "NaT"], dtype="m8[us]"),
|
| 136 |
+
1: pd.TimedeltaIndex(["0 days", "0 days"]),
|
| 137 |
+
}
|
| 138 |
+
)
|
| 139 |
+
tm.assert_frame_equal(result, expected)
|
| 140 |
+
|
| 141 |
+
def test_diff_timedelta(self, unit):
|
| 142 |
+
# GH#4533
|
| 143 |
+
df = pd.DataFrame(
|
| 144 |
+
{
|
| 145 |
+
"time": [pd.Timestamp("20130101 9:01"), pd.Timestamp("20130101 9:02")],
|
| 146 |
+
"value": [1.0, 2.0],
|
| 147 |
+
}
|
| 148 |
+
)
|
| 149 |
+
df["time"] = df["time"].dt.as_unit(unit)
|
| 150 |
+
|
| 151 |
+
res = df.diff()
|
| 152 |
+
exp = pd.DataFrame(
|
| 153 |
+
[[pd.NaT, np.nan], [pd.Timedelta("00:01:00"), 1]], columns=["time", "value"]
|
| 154 |
+
)
|
| 155 |
+
exp["time"] = exp["time"].dt.as_unit(unit)
|
| 156 |
+
tm.assert_frame_equal(res, exp)
|
| 157 |
+
|
| 158 |
+
def test_diff_mixed_dtype(self):
|
| 159 |
+
df = pd.DataFrame(np.random.default_rng(2).standard_normal((5, 3)))
|
| 160 |
+
df["A"] = np.array([1, 2, 3, 4, 5], dtype=object)
|
| 161 |
+
|
| 162 |
+
result = df.diff()
|
| 163 |
+
assert result[0].dtype == np.float64
|
| 164 |
+
|
| 165 |
+
def test_diff_neg_n(self, datetime_frame):
|
| 166 |
+
rs = datetime_frame.diff(-1)
|
| 167 |
+
xp = datetime_frame - datetime_frame.shift(-1)
|
| 168 |
+
tm.assert_frame_equal(rs, xp)
|
| 169 |
+
|
| 170 |
+
def test_diff_float_n(self, datetime_frame):
|
| 171 |
+
rs = datetime_frame.diff(1.0)
|
| 172 |
+
xp = datetime_frame.diff(1)
|
| 173 |
+
tm.assert_frame_equal(rs, xp)
|
| 174 |
+
|
| 175 |
+
def test_diff_axis(self):
|
| 176 |
+
# GH#9727
|
| 177 |
+
df = pd.DataFrame([[1.0, 2.0], [3.0, 4.0]])
|
| 178 |
+
tm.assert_frame_equal(
|
| 179 |
+
df.diff(axis=1), pd.DataFrame([[np.nan, 1.0], [np.nan, 1.0]])
|
| 180 |
+
)
|
| 181 |
+
tm.assert_frame_equal(
|
| 182 |
+
df.diff(axis=0), pd.DataFrame([[np.nan, np.nan], [2.0, 2.0]])
|
| 183 |
+
)
|
| 184 |
+
|
| 185 |
+
def test_diff_period(self):
|
| 186 |
+
# GH#32995 Don't pass an incorrect axis
|
| 187 |
+
pi = pd.date_range("2016-01-01", periods=3).to_period("D")
|
| 188 |
+
df = pd.DataFrame({"A": pi})
|
| 189 |
+
|
| 190 |
+
result = df.diff(1, axis=1)
|
| 191 |
+
|
| 192 |
+
expected = (df - pd.NaT).astype(object)
|
| 193 |
+
tm.assert_frame_equal(result, expected)
|
| 194 |
+
|
| 195 |
+
def test_diff_axis1_mixed_dtypes(self):
|
| 196 |
+
# GH#32995 operate column-wise when we have mixed dtypes and axis=1
|
| 197 |
+
df = pd.DataFrame({"A": range(3), "B": 2 * np.arange(3, dtype=np.float64)})
|
| 198 |
+
|
| 199 |
+
expected = pd.DataFrame({"A": [np.nan, np.nan, np.nan], "B": df["B"] / 2})
|
| 200 |
+
|
| 201 |
+
result = df.diff(axis=1)
|
| 202 |
+
tm.assert_frame_equal(result, expected)
|
| 203 |
+
|
| 204 |
+
# GH#21437 mixed-float-dtypes
|
| 205 |
+
df = pd.DataFrame(
|
| 206 |
+
{"a": np.arange(3, dtype="float32"), "b": np.arange(3, dtype="float64")}
|
| 207 |
+
)
|
| 208 |
+
result = df.diff(axis=1)
|
| 209 |
+
expected = pd.DataFrame({"a": df["a"] * np.nan, "b": df["b"] * 0})
|
| 210 |
+
tm.assert_frame_equal(result, expected)
|
| 211 |
+
|
| 212 |
+
def test_diff_axis1_mixed_dtypes_large_periods(self):
|
| 213 |
+
# GH#32995 operate column-wise when we have mixed dtypes and axis=1
|
| 214 |
+
df = pd.DataFrame({"A": range(3), "B": 2 * np.arange(3, dtype=np.float64)})
|
| 215 |
+
|
| 216 |
+
expected = df * np.nan
|
| 217 |
+
|
| 218 |
+
result = df.diff(axis=1, periods=3)
|
| 219 |
+
tm.assert_frame_equal(result, expected)
|
| 220 |
+
|
| 221 |
+
def test_diff_axis1_mixed_dtypes_negative_periods(self):
|
| 222 |
+
# GH#32995 operate column-wise when we have mixed dtypes and axis=1
|
| 223 |
+
df = pd.DataFrame({"A": range(3), "B": 2 * np.arange(3, dtype=np.float64)})
|
| 224 |
+
|
| 225 |
+
expected = pd.DataFrame({"A": -1.0 * df["A"], "B": df["B"] * np.nan})
|
| 226 |
+
|
| 227 |
+
result = df.diff(axis=1, periods=-1)
|
| 228 |
+
tm.assert_frame_equal(result, expected)
|
| 229 |
+
|
| 230 |
+
def test_diff_sparse(self):
|
| 231 |
+
# GH#28813 .diff() should work for sparse dataframes as well
|
| 232 |
+
sparse_df = pd.DataFrame([[0, 1], [1, 0]], dtype="Sparse[int]")
|
| 233 |
+
|
| 234 |
+
result = sparse_df.diff()
|
| 235 |
+
expected = pd.DataFrame(
|
| 236 |
+
[[np.nan, np.nan], [1.0, -1.0]], dtype=pd.SparseDtype("float", 0.0)
|
| 237 |
+
)
|
| 238 |
+
|
| 239 |
+
tm.assert_frame_equal(result, expected)
|
| 240 |
+
|
| 241 |
+
@pytest.mark.parametrize(
|
| 242 |
+
"axis,expected",
|
| 243 |
+
[
|
| 244 |
+
(
|
| 245 |
+
0,
|
| 246 |
+
pd.DataFrame(
|
| 247 |
+
{
|
| 248 |
+
"a": [pd.NA, 0, 1, 0, pd.NA, pd.NA, pd.NA, 0],
|
| 249 |
+
"b": [pd.NA, 1, pd.NA, pd.NA, -2, 1, pd.NA, pd.NA],
|
| 250 |
+
"c": np.repeat(pd.NA, 8), # type: ignore[call-overload]
|
| 251 |
+
"d": [pd.NA, 3, 5, 7, 9, 11, 13, 15],
|
| 252 |
+
},
|
| 253 |
+
dtype="Int64",
|
| 254 |
+
),
|
| 255 |
+
),
|
| 256 |
+
(
|
| 257 |
+
1,
|
| 258 |
+
pd.DataFrame(
|
| 259 |
+
{
|
| 260 |
+
"a": np.repeat(pd.NA, 8), # type: ignore[call-overload]
|
| 261 |
+
"b": [0, 1, pd.NA, 1, pd.NA, pd.NA, pd.NA, 0],
|
| 262 |
+
"c": np.repeat(pd.NA, 8), # type: ignore[call-overload]
|
| 263 |
+
"d": np.repeat(pd.NA, 8), # type: ignore[call-overload]
|
| 264 |
+
},
|
| 265 |
+
dtype="Int64",
|
| 266 |
+
),
|
| 267 |
+
),
|
| 268 |
+
],
|
| 269 |
+
)
|
| 270 |
+
def test_diff_integer_na(self, axis, expected):
|
| 271 |
+
# GH#24171 IntegerNA Support for DataFrame.diff()
|
| 272 |
+
df = pd.DataFrame(
|
| 273 |
+
{
|
| 274 |
+
"a": np.repeat([0, 1, pd.NA, 2], 2),
|
| 275 |
+
"b": np.tile([0, 1, pd.NA, 2], 2),
|
| 276 |
+
"c": np.repeat(pd.NA, 8),
|
| 277 |
+
"d": np.arange(1, 9) ** 2,
|
| 278 |
+
},
|
| 279 |
+
dtype="Int64",
|
| 280 |
+
)
|
| 281 |
+
|
| 282 |
+
# Test case for default behaviour of diff
|
| 283 |
+
result = df.diff(axis=axis)
|
| 284 |
+
tm.assert_frame_equal(result, expected)
|
| 285 |
+
|
| 286 |
+
def test_diff_readonly(self):
|
| 287 |
+
# https://github.com/pandas-dev/pandas/issues/35559
|
| 288 |
+
arr = np.random.default_rng(2).standard_normal((5, 2))
|
| 289 |
+
arr.flags.writeable = False
|
| 290 |
+
df = pd.DataFrame(arr)
|
| 291 |
+
result = df.diff()
|
| 292 |
+
expected = pd.DataFrame(np.array(df)).diff()
|
| 293 |
+
tm.assert_frame_equal(result, expected)
|
| 294 |
+
|
| 295 |
+
def test_diff_all_int_dtype(self, any_int_numpy_dtype):
|
| 296 |
+
# GH 14773
|
| 297 |
+
df = pd.DataFrame(range(5))
|
| 298 |
+
df = df.astype(any_int_numpy_dtype)
|
| 299 |
+
result = df.diff()
|
| 300 |
+
expected_dtype = (
|
| 301 |
+
"float32" if any_int_numpy_dtype in ("int8", "int16") else "float64"
|
| 302 |
+
)
|
| 303 |
+
expected = pd.DataFrame([np.nan, 1.0, 1.0, 1.0, 1.0], dtype=expected_dtype)
|
| 304 |
+
tm.assert_frame_equal(result, expected)
|
venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_dot.py
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import pytest
|
| 3 |
+
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import pandas._testing as tm
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class DotSharedTests:
|
| 9 |
+
@pytest.fixture
|
| 10 |
+
def obj(self):
|
| 11 |
+
raise NotImplementedError
|
| 12 |
+
|
| 13 |
+
@pytest.fixture
|
| 14 |
+
def other(self) -> pd.DataFrame:
|
| 15 |
+
"""
|
| 16 |
+
other is a DataFrame that is indexed so that obj.dot(other) is valid
|
| 17 |
+
"""
|
| 18 |
+
raise NotImplementedError
|
| 19 |
+
|
| 20 |
+
@pytest.fixture
|
| 21 |
+
def expected(self, obj, other) -> pd.DataFrame:
|
| 22 |
+
"""
|
| 23 |
+
The expected result of obj.dot(other)
|
| 24 |
+
"""
|
| 25 |
+
raise NotImplementedError
|
| 26 |
+
|
| 27 |
+
@classmethod
|
| 28 |
+
def reduced_dim_assert(cls, result, expected):
|
| 29 |
+
"""
|
| 30 |
+
Assertion about results with 1 fewer dimension that self.obj
|
| 31 |
+
"""
|
| 32 |
+
raise NotImplementedError
|
| 33 |
+
|
| 34 |
+
def test_dot_equiv_values_dot(self, obj, other, expected):
|
| 35 |
+
# `expected` is constructed from obj.values.dot(other.values)
|
| 36 |
+
result = obj.dot(other)
|
| 37 |
+
tm.assert_equal(result, expected)
|
| 38 |
+
|
| 39 |
+
def test_dot_2d_ndarray(self, obj, other, expected):
|
| 40 |
+
# Check ndarray argument; in this case we get matching values,
|
| 41 |
+
# but index/columns may not match
|
| 42 |
+
result = obj.dot(other.values)
|
| 43 |
+
assert np.all(result == expected.values)
|
| 44 |
+
|
| 45 |
+
def test_dot_1d_ndarray(self, obj, expected):
|
| 46 |
+
# can pass correct-length array
|
| 47 |
+
row = obj.iloc[0] if obj.ndim == 2 else obj
|
| 48 |
+
|
| 49 |
+
result = obj.dot(row.values)
|
| 50 |
+
expected = obj.dot(row)
|
| 51 |
+
self.reduced_dim_assert(result, expected)
|
| 52 |
+
|
| 53 |
+
def test_dot_series(self, obj, other, expected):
|
| 54 |
+
# Check series argument
|
| 55 |
+
result = obj.dot(other["1"])
|
| 56 |
+
self.reduced_dim_assert(result, expected["1"])
|
| 57 |
+
|
| 58 |
+
def test_dot_series_alignment(self, obj, other, expected):
|
| 59 |
+
result = obj.dot(other.iloc[::-1]["1"])
|
| 60 |
+
self.reduced_dim_assert(result, expected["1"])
|
| 61 |
+
|
| 62 |
+
def test_dot_aligns(self, obj, other, expected):
|
| 63 |
+
# Check index alignment
|
| 64 |
+
other2 = other.iloc[::-1]
|
| 65 |
+
result = obj.dot(other2)
|
| 66 |
+
tm.assert_equal(result, expected)
|
| 67 |
+
|
| 68 |
+
def test_dot_shape_mismatch(self, obj):
|
| 69 |
+
msg = "Dot product shape mismatch"
|
| 70 |
+
# exception raised is of type Exception
|
| 71 |
+
with pytest.raises(Exception, match=msg):
|
| 72 |
+
obj.dot(obj.values[:3])
|
| 73 |
+
|
| 74 |
+
def test_dot_misaligned(self, obj, other):
|
| 75 |
+
msg = "matrices are not aligned"
|
| 76 |
+
with pytest.raises(ValueError, match=msg):
|
| 77 |
+
obj.dot(other.T)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
class TestSeriesDot(DotSharedTests):
|
| 81 |
+
@pytest.fixture
|
| 82 |
+
def obj(self):
|
| 83 |
+
return pd.Series(
|
| 84 |
+
np.random.default_rng(2).standard_normal(4), index=["p", "q", "r", "s"]
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
@pytest.fixture
|
| 88 |
+
def other(self):
|
| 89 |
+
return pd.DataFrame(
|
| 90 |
+
np.random.default_rng(2).standard_normal((3, 4)),
|
| 91 |
+
index=["1", "2", "3"],
|
| 92 |
+
columns=["p", "q", "r", "s"],
|
| 93 |
+
).T
|
| 94 |
+
|
| 95 |
+
@pytest.fixture
|
| 96 |
+
def expected(self, obj, other):
|
| 97 |
+
return pd.Series(np.dot(obj.values, other.values), index=other.columns)
|
| 98 |
+
|
| 99 |
+
@classmethod
|
| 100 |
+
def reduced_dim_assert(cls, result, expected):
|
| 101 |
+
"""
|
| 102 |
+
Assertion about results with 1 fewer dimension that self.obj
|
| 103 |
+
"""
|
| 104 |
+
tm.assert_almost_equal(result, expected)
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
class TestDataFrameDot(DotSharedTests):
|
| 108 |
+
@pytest.fixture
|
| 109 |
+
def obj(self):
|
| 110 |
+
return pd.DataFrame(
|
| 111 |
+
np.random.default_rng(2).standard_normal((3, 4)),
|
| 112 |
+
index=["a", "b", "c"],
|
| 113 |
+
columns=["p", "q", "r", "s"],
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
@pytest.fixture
|
| 117 |
+
def other(self):
|
| 118 |
+
return pd.DataFrame(
|
| 119 |
+
np.random.default_rng(2).standard_normal((4, 2)),
|
| 120 |
+
index=["p", "q", "r", "s"],
|
| 121 |
+
columns=["1", "2"],
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
@pytest.fixture
|
| 125 |
+
def expected(self, obj, other):
|
| 126 |
+
return pd.DataFrame(
|
| 127 |
+
np.dot(obj.values, other.values), index=obj.index, columns=other.columns
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
@classmethod
|
| 131 |
+
def reduced_dim_assert(cls, result, expected):
|
| 132 |
+
"""
|
| 133 |
+
Assertion about results with 1 fewer dimension that self.obj
|
| 134 |
+
"""
|
| 135 |
+
tm.assert_series_equal(result, expected, check_names=False)
|
| 136 |
+
assert result.name is None
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
@pytest.mark.parametrize(
|
| 140 |
+
"dtype,exp_dtype",
|
| 141 |
+
[("Float32", "Float64"), ("Int16", "Int32"), ("float[pyarrow]", "double[pyarrow]")],
|
| 142 |
+
)
|
| 143 |
+
def test_arrow_dtype(dtype, exp_dtype):
|
| 144 |
+
pytest.importorskip("pyarrow")
|
| 145 |
+
|
| 146 |
+
cols = ["a", "b"]
|
| 147 |
+
df_a = pd.DataFrame([[1, 2], [3, 4], [5, 6]], columns=cols, dtype="int32")
|
| 148 |
+
df_b = pd.DataFrame([[1, 0], [0, 1]], index=cols, dtype=dtype)
|
| 149 |
+
result = df_a.dot(df_b)
|
| 150 |
+
expected = pd.DataFrame([[1, 2], [3, 4], [5, 6]], dtype=exp_dtype)
|
| 151 |
+
|
| 152 |
+
tm.assert_frame_equal(result, expected)
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
@pytest.mark.parametrize(
|
| 156 |
+
"dtype,exp_dtype",
|
| 157 |
+
[("Float32", "Float64"), ("Int16", "Int32"), ("float[pyarrow]", "double[pyarrow]")],
|
| 158 |
+
)
|
| 159 |
+
def test_arrow_dtype_series(dtype, exp_dtype):
|
| 160 |
+
pytest.importorskip("pyarrow")
|
| 161 |
+
|
| 162 |
+
cols = ["a", "b"]
|
| 163 |
+
series_a = pd.Series([1, 2], index=cols, dtype="int32")
|
| 164 |
+
df_b = pd.DataFrame([[1, 0], [0, 1]], index=cols, dtype=dtype)
|
| 165 |
+
result = series_a.dot(df_b)
|
| 166 |
+
expected = pd.Series([1, 2], dtype=exp_dtype)
|
| 167 |
+
|
| 168 |
+
tm.assert_series_equal(result, expected)
|
venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_drop.py
ADDED
|
@@ -0,0 +1,590 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
from pandas.errors import Pandas4Warning
|
| 7 |
+
|
| 8 |
+
import pandas as pd
|
| 9 |
+
import pandas._testing as tm
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
@pytest.mark.parametrize(
|
| 13 |
+
"msg,labels,level",
|
| 14 |
+
[
|
| 15 |
+
(r"labels \[4\] not found in level", 4, "a"),
|
| 16 |
+
(r"labels \[7\] not found in level", 7, "b"),
|
| 17 |
+
],
|
| 18 |
+
)
|
| 19 |
+
def test_drop_raise_exception_if_labels_not_in_level(msg, labels, level):
|
| 20 |
+
# GH 8594
|
| 21 |
+
mi = pd.MultiIndex.from_arrays([[1, 2, 3], [4, 5, 6]], names=["a", "b"])
|
| 22 |
+
s = pd.Series([10, 20, 30], index=mi)
|
| 23 |
+
df = pd.DataFrame([10, 20, 30], index=mi)
|
| 24 |
+
|
| 25 |
+
with pytest.raises(KeyError, match=msg):
|
| 26 |
+
s.drop(labels, level=level)
|
| 27 |
+
with pytest.raises(KeyError, match=msg):
|
| 28 |
+
df.drop(labels, level=level)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
@pytest.mark.parametrize("labels,level", [(4, "a"), (7, "b")])
|
| 32 |
+
def test_drop_errors_ignore(labels, level):
|
| 33 |
+
# GH 8594
|
| 34 |
+
mi = pd.MultiIndex.from_arrays([[1, 2, 3], [4, 5, 6]], names=["a", "b"])
|
| 35 |
+
s = pd.Series([10, 20, 30], index=mi)
|
| 36 |
+
df = pd.DataFrame([10, 20, 30], index=mi)
|
| 37 |
+
|
| 38 |
+
expected_s = s.drop(labels, level=level, errors="ignore")
|
| 39 |
+
tm.assert_series_equal(s, expected_s)
|
| 40 |
+
|
| 41 |
+
expected_df = df.drop(labels, level=level, errors="ignore")
|
| 42 |
+
tm.assert_frame_equal(df, expected_df)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def test_drop_with_non_unique_datetime_index_and_invalid_keys():
|
| 46 |
+
# GH 30399
|
| 47 |
+
|
| 48 |
+
# define dataframe with unique datetime index
|
| 49 |
+
df = pd.DataFrame(
|
| 50 |
+
np.random.default_rng(2).standard_normal((5, 3)),
|
| 51 |
+
columns=["a", "b", "c"],
|
| 52 |
+
index=pd.date_range("2012", freq="h", periods=5),
|
| 53 |
+
)
|
| 54 |
+
# create dataframe with non-unique datetime index
|
| 55 |
+
df = df.iloc[[0, 2, 2, 3]].copy()
|
| 56 |
+
|
| 57 |
+
with pytest.raises(KeyError, match="not found in axis"):
|
| 58 |
+
df.drop(["a", "b"]) # Dropping with labels not exist in the index
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
class TestDataFrameDrop:
|
| 62 |
+
@pytest.mark.filterwarnings("ignore:The inplace keyword in DataFrame.drop is")
|
| 63 |
+
def test_drop_names(self):
|
| 64 |
+
df = pd.DataFrame(
|
| 65 |
+
[[1, 2, 3], [3, 4, 5], [5, 6, 7]],
|
| 66 |
+
index=["a", "b", "c"],
|
| 67 |
+
columns=["d", "e", "f"],
|
| 68 |
+
)
|
| 69 |
+
df.index.name, df.columns.name = "first", "second"
|
| 70 |
+
df_dropped_b = df.drop("b")
|
| 71 |
+
df_dropped_e = df.drop("e", axis=1)
|
| 72 |
+
df_inplace_b, df_inplace_e = df.copy(), df.copy()
|
| 73 |
+
return_value = df_inplace_b.drop("b", inplace=True)
|
| 74 |
+
assert return_value is None
|
| 75 |
+
return_value = df_inplace_e.drop("e", axis=1, inplace=True)
|
| 76 |
+
assert return_value is None
|
| 77 |
+
for obj in (df_dropped_b, df_dropped_e, df_inplace_b, df_inplace_e):
|
| 78 |
+
assert obj.index.name == "first"
|
| 79 |
+
assert obj.columns.name == "second"
|
| 80 |
+
assert list(df.columns) == ["d", "e", "f"]
|
| 81 |
+
|
| 82 |
+
msg = r"\['g'\] not found in axis"
|
| 83 |
+
with pytest.raises(KeyError, match=msg):
|
| 84 |
+
df.drop(["g"])
|
| 85 |
+
with pytest.raises(KeyError, match=msg):
|
| 86 |
+
df.drop(["g"], axis=1)
|
| 87 |
+
|
| 88 |
+
# errors = 'ignore'
|
| 89 |
+
dropped = df.drop(["g"], errors="ignore")
|
| 90 |
+
expected = pd.Index(["a", "b", "c"], name="first")
|
| 91 |
+
tm.assert_index_equal(dropped.index, expected)
|
| 92 |
+
|
| 93 |
+
dropped = df.drop(["b", "g"], errors="ignore")
|
| 94 |
+
expected = pd.Index(["a", "c"], name="first")
|
| 95 |
+
tm.assert_index_equal(dropped.index, expected)
|
| 96 |
+
|
| 97 |
+
dropped = df.drop(["g"], axis=1, errors="ignore")
|
| 98 |
+
expected = pd.Index(["d", "e", "f"], name="second")
|
| 99 |
+
tm.assert_index_equal(dropped.columns, expected)
|
| 100 |
+
|
| 101 |
+
dropped = df.drop(["d", "g"], axis=1, errors="ignore")
|
| 102 |
+
expected = pd.Index(["e", "f"], name="second")
|
| 103 |
+
tm.assert_index_equal(dropped.columns, expected)
|
| 104 |
+
|
| 105 |
+
# GH 16398
|
| 106 |
+
dropped = df.drop([], errors="ignore")
|
| 107 |
+
expected = pd.Index(["a", "b", "c"], name="first")
|
| 108 |
+
tm.assert_index_equal(dropped.index, expected)
|
| 109 |
+
|
| 110 |
+
@pytest.mark.filterwarnings("ignore:The inplace keyword in DataFrame.drop is")
|
| 111 |
+
def test_drop(self):
|
| 112 |
+
simple = pd.DataFrame({"A": [1, 2, 3, 4], "B": [0, 1, 2, 3]})
|
| 113 |
+
tm.assert_frame_equal(simple.drop("A", axis=1), simple[["B"]])
|
| 114 |
+
tm.assert_frame_equal(simple.drop(["A", "B"], axis="columns"), simple[[]])
|
| 115 |
+
tm.assert_frame_equal(simple.drop([0, 1, 3], axis=0), simple.loc[[2], :])
|
| 116 |
+
tm.assert_frame_equal(simple.drop([0, 3], axis="index"), simple.loc[[1, 2], :])
|
| 117 |
+
|
| 118 |
+
with pytest.raises(KeyError, match=r"\[5\] not found in axis"):
|
| 119 |
+
simple.drop(5)
|
| 120 |
+
with pytest.raises(KeyError, match=r"\['C'\] not found in axis"):
|
| 121 |
+
simple.drop("C", axis=1)
|
| 122 |
+
with pytest.raises(KeyError, match=r"\[5\] not found in axis"):
|
| 123 |
+
simple.drop([1, 5])
|
| 124 |
+
with pytest.raises(KeyError, match=r"\['C'\] not found in axis"):
|
| 125 |
+
simple.drop(["A", "C"], axis=1)
|
| 126 |
+
|
| 127 |
+
# GH 42881
|
| 128 |
+
with pytest.raises(KeyError, match=r"\['C', 'D', 'F'\] not found in axis"):
|
| 129 |
+
simple.drop(["C", "D", "F"], axis=1)
|
| 130 |
+
|
| 131 |
+
# errors = 'ignore'
|
| 132 |
+
tm.assert_frame_equal(simple.drop(5, errors="ignore"), simple)
|
| 133 |
+
tm.assert_frame_equal(
|
| 134 |
+
simple.drop([0, 5], errors="ignore"), simple.loc[[1, 2, 3], :]
|
| 135 |
+
)
|
| 136 |
+
tm.assert_frame_equal(simple.drop("C", axis=1, errors="ignore"), simple)
|
| 137 |
+
tm.assert_frame_equal(
|
| 138 |
+
simple.drop(["A", "C"], axis=1, errors="ignore"), simple[["B"]]
|
| 139 |
+
)
|
| 140 |
+
|
| 141 |
+
# non-unique - wheee!
|
| 142 |
+
nu_df = pd.DataFrame(
|
| 143 |
+
list(zip(range(3), range(-3, 0), list("abc"), strict=True)),
|
| 144 |
+
columns=["a", "a", "b"],
|
| 145 |
+
)
|
| 146 |
+
tm.assert_frame_equal(nu_df.drop("a", axis=1), nu_df[["b"]])
|
| 147 |
+
tm.assert_frame_equal(nu_df.drop("b", axis="columns"), nu_df["a"])
|
| 148 |
+
tm.assert_frame_equal(nu_df.drop([]), nu_df) # GH 16398
|
| 149 |
+
|
| 150 |
+
nu_df = nu_df.set_index(pd.Index(["X", "Y", "X"]))
|
| 151 |
+
nu_df.columns = list("abc")
|
| 152 |
+
tm.assert_frame_equal(nu_df.drop("X", axis="rows"), nu_df.loc[["Y"], :])
|
| 153 |
+
tm.assert_frame_equal(nu_df.drop(["X", "Y"], axis=0), nu_df.loc[[], :])
|
| 154 |
+
|
| 155 |
+
# inplace cache issue
|
| 156 |
+
# GH#5628
|
| 157 |
+
df = pd.DataFrame(
|
| 158 |
+
np.random.default_rng(2).standard_normal((10, 3)), columns=list("abc")
|
| 159 |
+
)
|
| 160 |
+
expected = df[~(df.b > 0)]
|
| 161 |
+
return_value = df.drop(labels=df[df.b > 0].index, inplace=True)
|
| 162 |
+
assert return_value is None
|
| 163 |
+
tm.assert_frame_equal(df, expected)
|
| 164 |
+
|
| 165 |
+
def test_drop_multiindex_not_lexsorted(self, performance_warning):
|
| 166 |
+
# GH#11640
|
| 167 |
+
|
| 168 |
+
# define the lexsorted version
|
| 169 |
+
lexsorted_mi = pd.MultiIndex.from_tuples(
|
| 170 |
+
[("a", ""), ("b1", "c1"), ("b2", "c2")], names=["b", "c"]
|
| 171 |
+
)
|
| 172 |
+
lexsorted_df = pd.DataFrame([[1, 3, 4]], columns=lexsorted_mi)
|
| 173 |
+
assert lexsorted_df.columns._is_lexsorted()
|
| 174 |
+
|
| 175 |
+
# define the non-lexsorted version
|
| 176 |
+
not_lexsorted_df = pd.DataFrame(
|
| 177 |
+
columns=["a", "b", "c", "d"], data=[[1, "b1", "c1", 3], [1, "b2", "c2", 4]]
|
| 178 |
+
)
|
| 179 |
+
not_lexsorted_df = not_lexsorted_df.pivot_table(
|
| 180 |
+
index="a", columns=["b", "c"], values="d"
|
| 181 |
+
)
|
| 182 |
+
not_lexsorted_df = not_lexsorted_df.reset_index()
|
| 183 |
+
assert not not_lexsorted_df.columns._is_lexsorted()
|
| 184 |
+
|
| 185 |
+
expected = lexsorted_df.drop("a", axis=1).astype(float)
|
| 186 |
+
msg = "dropping on a non-lexsorted multi-index without a level parameter"
|
| 187 |
+
with tm.assert_produces_warning(performance_warning, match=msg):
|
| 188 |
+
result = not_lexsorted_df.drop("a", axis=1)
|
| 189 |
+
|
| 190 |
+
tm.assert_frame_equal(result, expected)
|
| 191 |
+
|
| 192 |
+
def test_drop_api_equivalence(self):
|
| 193 |
+
# equivalence of the labels/axis and index/columns API's (GH#12392)
|
| 194 |
+
df = pd.DataFrame(
|
| 195 |
+
[[1, 2, 3], [3, 4, 5], [5, 6, 7]],
|
| 196 |
+
index=["a", "b", "c"],
|
| 197 |
+
columns=["d", "e", "f"],
|
| 198 |
+
)
|
| 199 |
+
|
| 200 |
+
res1 = df.drop("a")
|
| 201 |
+
res2 = df.drop(index="a")
|
| 202 |
+
tm.assert_frame_equal(res1, res2)
|
| 203 |
+
|
| 204 |
+
res1 = df.drop("d", axis=1)
|
| 205 |
+
res2 = df.drop(columns="d")
|
| 206 |
+
tm.assert_frame_equal(res1, res2)
|
| 207 |
+
|
| 208 |
+
res1 = df.drop(labels="e", axis=1)
|
| 209 |
+
res2 = df.drop(columns="e")
|
| 210 |
+
tm.assert_frame_equal(res1, res2)
|
| 211 |
+
|
| 212 |
+
res1 = df.drop(["a"], axis=0)
|
| 213 |
+
res2 = df.drop(index=["a"])
|
| 214 |
+
tm.assert_frame_equal(res1, res2)
|
| 215 |
+
|
| 216 |
+
res1 = df.drop(["a"], axis=0).drop(["d"], axis=1)
|
| 217 |
+
res2 = df.drop(index=["a"], columns=["d"])
|
| 218 |
+
tm.assert_frame_equal(res1, res2)
|
| 219 |
+
|
| 220 |
+
msg = "Cannot specify both 'labels' and 'index'/'columns'"
|
| 221 |
+
with pytest.raises(ValueError, match=msg):
|
| 222 |
+
df.drop(labels="a", index="b")
|
| 223 |
+
|
| 224 |
+
with pytest.raises(ValueError, match=msg):
|
| 225 |
+
df.drop(labels="a", columns="b")
|
| 226 |
+
|
| 227 |
+
msg = "Need to specify at least one of 'labels', 'index' or 'columns'"
|
| 228 |
+
with pytest.raises(ValueError, match=msg):
|
| 229 |
+
df.drop(axis=1)
|
| 230 |
+
|
| 231 |
+
@pytest.mark.parametrize(
|
| 232 |
+
"actual",
|
| 233 |
+
[
|
| 234 |
+
pd.DataFrame([[1, 2, 3], [1, 2, 3]], index=["a", "a"]),
|
| 235 |
+
pd.DataFrame([[1, 2, 3], [1, 2, 3]], index=["a", "b"]),
|
| 236 |
+
pd.DataFrame([[1, 2, 3], [1, 2, 3]], index=["a", "b"]).set_index([0, 1]),
|
| 237 |
+
pd.DataFrame([[1, 2, 3], [1, 2, 3]], index=["a", "a"]).set_index([0, 1]),
|
| 238 |
+
],
|
| 239 |
+
)
|
| 240 |
+
def test_raise_on_drop_duplicate_index(self, actual):
|
| 241 |
+
# GH#19186
|
| 242 |
+
level = 0 if isinstance(actual.index, pd.MultiIndex) else None
|
| 243 |
+
msg = re.escape("\"['c'] not found in axis\"")
|
| 244 |
+
with pytest.raises(KeyError, match=msg):
|
| 245 |
+
actual.drop("c", level=level, axis=0)
|
| 246 |
+
with pytest.raises(KeyError, match=msg):
|
| 247 |
+
actual.T.drop("c", level=level, axis=1)
|
| 248 |
+
expected_no_err = actual.drop("c", axis=0, level=level, errors="ignore")
|
| 249 |
+
tm.assert_frame_equal(expected_no_err, actual)
|
| 250 |
+
expected_no_err = actual.T.drop("c", axis=1, level=level, errors="ignore")
|
| 251 |
+
tm.assert_frame_equal(expected_no_err.T, actual)
|
| 252 |
+
|
| 253 |
+
@pytest.mark.parametrize("index", [[1, 2, 3], [1, 1, 2]])
|
| 254 |
+
@pytest.mark.parametrize("drop_labels", [[], [1], [2]])
|
| 255 |
+
def test_drop_empty_list(self, index, drop_labels):
|
| 256 |
+
# GH#21494
|
| 257 |
+
expected_index = [i for i in index if i not in drop_labels]
|
| 258 |
+
frame = pd.DataFrame(index=index).drop(drop_labels)
|
| 259 |
+
tm.assert_frame_equal(frame, pd.DataFrame(index=expected_index))
|
| 260 |
+
|
| 261 |
+
@pytest.mark.parametrize("index", [[1, 2, 3], [1, 2, 2]])
|
| 262 |
+
@pytest.mark.parametrize("drop_labels", [[1, 4], [4, 5]])
|
| 263 |
+
def test_drop_non_empty_list(self, index, drop_labels):
|
| 264 |
+
# GH# 21494
|
| 265 |
+
with pytest.raises(KeyError, match="not found in axis"):
|
| 266 |
+
pd.DataFrame(index=index).drop(drop_labels)
|
| 267 |
+
|
| 268 |
+
@pytest.mark.parametrize(
|
| 269 |
+
"empty_listlike",
|
| 270 |
+
[
|
| 271 |
+
[],
|
| 272 |
+
{},
|
| 273 |
+
np.array([]),
|
| 274 |
+
pd.Series([], dtype="datetime64[ns]"),
|
| 275 |
+
pd.Index([]),
|
| 276 |
+
pd.DatetimeIndex([]),
|
| 277 |
+
],
|
| 278 |
+
)
|
| 279 |
+
def test_drop_empty_listlike_non_unique_datetime_index(self, empty_listlike):
|
| 280 |
+
# GH#27994
|
| 281 |
+
data = {"column_a": [5, 10], "column_b": ["one", "two"]}
|
| 282 |
+
index = [pd.Timestamp("2021-01-01"), pd.Timestamp("2021-01-01")]
|
| 283 |
+
df = pd.DataFrame(data, index=index)
|
| 284 |
+
|
| 285 |
+
# Passing empty list-like should return the same DataFrame.
|
| 286 |
+
expected = df.copy()
|
| 287 |
+
result = df.drop(empty_listlike)
|
| 288 |
+
tm.assert_frame_equal(result, expected)
|
| 289 |
+
|
| 290 |
+
def test_mixed_depth_drop(self):
|
| 291 |
+
arrays = [
|
| 292 |
+
["a", "top", "top", "routine1", "routine1", "routine2"],
|
| 293 |
+
["", "OD", "OD", "result1", "result2", "result1"],
|
| 294 |
+
["", "wx", "wy", "", "", ""],
|
| 295 |
+
]
|
| 296 |
+
|
| 297 |
+
tuples = sorted(zip(*arrays, strict=True))
|
| 298 |
+
index = pd.MultiIndex.from_tuples(tuples)
|
| 299 |
+
df = pd.DataFrame(
|
| 300 |
+
np.random.default_rng(2).standard_normal((4, 6)), columns=index
|
| 301 |
+
)
|
| 302 |
+
|
| 303 |
+
result = df.drop("a", axis=1)
|
| 304 |
+
expected = df.drop([("a", "", "")], axis=1)
|
| 305 |
+
tm.assert_frame_equal(expected, result)
|
| 306 |
+
|
| 307 |
+
result = df.drop(["top"], axis=1)
|
| 308 |
+
expected = df.drop([("top", "OD", "wx")], axis=1)
|
| 309 |
+
expected = expected.drop([("top", "OD", "wy")], axis=1)
|
| 310 |
+
tm.assert_frame_equal(expected, result)
|
| 311 |
+
|
| 312 |
+
result = df.drop(("top", "OD", "wx"), axis=1)
|
| 313 |
+
expected = df.drop([("top", "OD", "wx")], axis=1)
|
| 314 |
+
tm.assert_frame_equal(expected, result)
|
| 315 |
+
|
| 316 |
+
expected = df.drop([("top", "OD", "wy")], axis=1)
|
| 317 |
+
expected = df.drop("top", axis=1)
|
| 318 |
+
|
| 319 |
+
result = df.drop("result1", level=1, axis=1)
|
| 320 |
+
expected = df.drop(
|
| 321 |
+
[("routine1", "result1", ""), ("routine2", "result1", "")], axis=1
|
| 322 |
+
)
|
| 323 |
+
tm.assert_frame_equal(expected, result)
|
| 324 |
+
|
| 325 |
+
def test_drop_multiindex_other_level_nan(self):
|
| 326 |
+
# GH#12754
|
| 327 |
+
df = (
|
| 328 |
+
pd.DataFrame(
|
| 329 |
+
{
|
| 330 |
+
"A": ["one", "one", "two", "two"],
|
| 331 |
+
"B": [np.nan, 0.0, 1.0, 2.0],
|
| 332 |
+
"C": ["a", "b", "c", "c"],
|
| 333 |
+
"D": [1, 2, 3, 4],
|
| 334 |
+
}
|
| 335 |
+
)
|
| 336 |
+
.set_index(["A", "B", "C"])
|
| 337 |
+
.sort_index()
|
| 338 |
+
)
|
| 339 |
+
result = df.drop("c", level="C")
|
| 340 |
+
expected = pd.DataFrame(
|
| 341 |
+
[2, 1],
|
| 342 |
+
columns=["D"],
|
| 343 |
+
index=pd.MultiIndex.from_tuples(
|
| 344 |
+
[("one", 0.0, "b"), ("one", np.nan, "a")], names=["A", "B", "C"]
|
| 345 |
+
),
|
| 346 |
+
)
|
| 347 |
+
tm.assert_frame_equal(result, expected)
|
| 348 |
+
|
| 349 |
+
def test_drop_raise_with_both_axis_and_index(self):
|
| 350 |
+
# GH#61823
|
| 351 |
+
df = pd.DataFrame(
|
| 352 |
+
[[1, 2, 3], [3, 4, 5], [5, 6, 7]],
|
| 353 |
+
index=["a", "b", "c"],
|
| 354 |
+
columns=["d", "e", "f"],
|
| 355 |
+
)
|
| 356 |
+
|
| 357 |
+
msg = "Cannot specify both 'axis' and 'index'/'columns'"
|
| 358 |
+
with pytest.raises(ValueError, match=msg):
|
| 359 |
+
df.drop(index="b", axis=1)
|
| 360 |
+
|
| 361 |
+
def test_drop_nonunique(self):
|
| 362 |
+
df = pd.DataFrame(
|
| 363 |
+
[
|
| 364 |
+
["x-a", "x", "a", 1.5],
|
| 365 |
+
["x-a", "x", "a", 1.2],
|
| 366 |
+
["z-c", "z", "c", 3.1],
|
| 367 |
+
["x-a", "x", "a", 4.1],
|
| 368 |
+
["x-b", "x", "b", 5.1],
|
| 369 |
+
["x-b", "x", "b", 4.1],
|
| 370 |
+
["x-b", "x", "b", 2.2],
|
| 371 |
+
["y-a", "y", "a", 1.2],
|
| 372 |
+
["z-b", "z", "b", 2.1],
|
| 373 |
+
],
|
| 374 |
+
columns=["var1", "var2", "var3", "var4"],
|
| 375 |
+
)
|
| 376 |
+
|
| 377 |
+
grp_size = df.groupby("var1").size()
|
| 378 |
+
drop_idx = grp_size.loc[grp_size == 1]
|
| 379 |
+
|
| 380 |
+
idf = df.set_index(["var1", "var2", "var3"])
|
| 381 |
+
|
| 382 |
+
# it works! GH#2101
|
| 383 |
+
result = idf.drop(drop_idx.index, level=0).reset_index()
|
| 384 |
+
expected = df[-df.var1.isin(drop_idx.index)]
|
| 385 |
+
|
| 386 |
+
result.index = expected.index
|
| 387 |
+
|
| 388 |
+
tm.assert_frame_equal(result, expected)
|
| 389 |
+
|
| 390 |
+
def test_drop_level(self, multiindex_dataframe_random_data):
|
| 391 |
+
frame = multiindex_dataframe_random_data
|
| 392 |
+
|
| 393 |
+
result = frame.drop(["bar", "qux"], level="first")
|
| 394 |
+
expected = frame.iloc[[0, 1, 2, 5, 6]]
|
| 395 |
+
tm.assert_frame_equal(result, expected)
|
| 396 |
+
|
| 397 |
+
result = frame.drop(["two"], level="second")
|
| 398 |
+
expected = frame.iloc[[0, 2, 3, 6, 7, 9]]
|
| 399 |
+
tm.assert_frame_equal(result, expected)
|
| 400 |
+
|
| 401 |
+
result = frame.T.drop(["bar", "qux"], axis=1, level="first")
|
| 402 |
+
expected = frame.iloc[[0, 1, 2, 5, 6]].T
|
| 403 |
+
tm.assert_frame_equal(result, expected)
|
| 404 |
+
|
| 405 |
+
result = frame.T.drop(["two"], axis=1, level="second")
|
| 406 |
+
expected = frame.iloc[[0, 2, 3, 6, 7, 9]].T
|
| 407 |
+
tm.assert_frame_equal(result, expected)
|
| 408 |
+
|
| 409 |
+
def test_drop_level_nonunique_datetime(self):
|
| 410 |
+
# GH#12701
|
| 411 |
+
idx = pd.Index([2, 3, 4, 4, 5], name="id")
|
| 412 |
+
idxdt = pd.to_datetime(
|
| 413 |
+
[
|
| 414 |
+
"2016-03-23 14:00",
|
| 415 |
+
"2016-03-23 15:00",
|
| 416 |
+
"2016-03-23 16:00",
|
| 417 |
+
"2016-03-23 16:00",
|
| 418 |
+
"2016-03-23 17:00",
|
| 419 |
+
]
|
| 420 |
+
)
|
| 421 |
+
df = pd.DataFrame(np.arange(10).reshape(5, 2), columns=list("ab"), index=idx)
|
| 422 |
+
df["tstamp"] = idxdt
|
| 423 |
+
df = df.set_index("tstamp", append=True)
|
| 424 |
+
ts = pd.Timestamp("201603231600")
|
| 425 |
+
assert df.index.is_unique is False
|
| 426 |
+
|
| 427 |
+
result = df.drop(ts, level="tstamp")
|
| 428 |
+
expected = df.loc[idx != 4]
|
| 429 |
+
tm.assert_frame_equal(result, expected)
|
| 430 |
+
|
| 431 |
+
def test_drop_tz_aware_timestamp_across_dst(self, frame_or_series):
|
| 432 |
+
# GH#21761
|
| 433 |
+
start = pd.Timestamp("2017-10-29", tz="Europe/Berlin")
|
| 434 |
+
end = pd.Timestamp("2017-10-29 04:00:00", tz="Europe/Berlin")
|
| 435 |
+
index = pd.date_range(start, end, freq="15min")
|
| 436 |
+
data = frame_or_series(data=[1] * len(index), index=index)
|
| 437 |
+
result = data.drop(start)
|
| 438 |
+
expected_start = pd.Timestamp("2017-10-29 00:15:00", tz="Europe/Berlin")
|
| 439 |
+
expected_idx = pd.date_range(expected_start, end, freq="15min")
|
| 440 |
+
expected = frame_or_series(data=[1] * len(expected_idx), index=expected_idx)
|
| 441 |
+
tm.assert_equal(result, expected)
|
| 442 |
+
|
| 443 |
+
def test_drop_preserve_names(self):
|
| 444 |
+
index = pd.MultiIndex.from_arrays(
|
| 445 |
+
[[0, 0, 0, 1, 1, 1], [1, 2, 3, 1, 2, 3]], names=["one", "two"]
|
| 446 |
+
)
|
| 447 |
+
|
| 448 |
+
df = pd.DataFrame(np.random.default_rng(2).standard_normal((6, 3)), index=index)
|
| 449 |
+
|
| 450 |
+
result = df.drop([(0, 2)])
|
| 451 |
+
assert result.index.names == ("one", "two")
|
| 452 |
+
|
| 453 |
+
@pytest.mark.parametrize(
|
| 454 |
+
"operation", ["__iadd__", "__isub__", "__imul__", "__ipow__"]
|
| 455 |
+
)
|
| 456 |
+
@pytest.mark.parametrize("inplace", [False, True])
|
| 457 |
+
def test_inplace_drop_and_operation(self, operation, inplace):
|
| 458 |
+
# GH#30484
|
| 459 |
+
df = pd.DataFrame({"x": range(5)})
|
| 460 |
+
expected = df.copy()
|
| 461 |
+
df["y"] = range(5)
|
| 462 |
+
y = df["y"]
|
| 463 |
+
|
| 464 |
+
# For GH 63207 since pytest.mark.filterwarning did not filter warning here
|
| 465 |
+
msg = "The inplace keyword in DataFrame.drop is deprecated"
|
| 466 |
+
with tm.assert_produces_warning(Pandas4Warning, match=msg):
|
| 467 |
+
if inplace:
|
| 468 |
+
df.drop("y", axis=1, inplace=inplace)
|
| 469 |
+
else:
|
| 470 |
+
df = df.drop("y", axis=1, inplace=inplace)
|
| 471 |
+
|
| 472 |
+
# Perform operation and check result
|
| 473 |
+
getattr(y, operation)(1)
|
| 474 |
+
tm.assert_frame_equal(df, expected)
|
| 475 |
+
|
| 476 |
+
def test_drop_with_non_unique_multiindex(self):
|
| 477 |
+
# GH#36293
|
| 478 |
+
mi = pd.MultiIndex.from_arrays([["x", "y", "x"], ["i", "j", "i"]])
|
| 479 |
+
df = pd.DataFrame([1, 2, 3], index=mi)
|
| 480 |
+
result = df.drop(index="x")
|
| 481 |
+
expected = pd.DataFrame([2], index=pd.MultiIndex.from_arrays([["y"], ["j"]]))
|
| 482 |
+
tm.assert_frame_equal(result, expected)
|
| 483 |
+
|
| 484 |
+
@pytest.mark.parametrize("indexer", [("a", "a"), [("a", "a")]])
|
| 485 |
+
def test_drop_tuple_with_non_unique_multiindex(self, indexer):
|
| 486 |
+
# GH#42771
|
| 487 |
+
idx = pd.MultiIndex.from_product([["a", "b"], ["a", "a"]])
|
| 488 |
+
df = pd.DataFrame({"x": range(len(idx))}, index=idx)
|
| 489 |
+
result = df.drop(index=[("a", "a")])
|
| 490 |
+
expected = pd.DataFrame(
|
| 491 |
+
{"x": [2, 3]}, index=pd.MultiIndex.from_tuples([("b", "a"), ("b", "a")])
|
| 492 |
+
)
|
| 493 |
+
tm.assert_frame_equal(result, expected)
|
| 494 |
+
|
| 495 |
+
def test_drop_with_duplicate_columns(self):
|
| 496 |
+
df = pd.DataFrame(
|
| 497 |
+
[[1, 5, 7.0], [1, 5, 7.0], [1, 5, 7.0]], columns=["bar", "a", "a"]
|
| 498 |
+
)
|
| 499 |
+
result = df.drop(["a"], axis=1)
|
| 500 |
+
expected = pd.DataFrame([[1], [1], [1]], columns=["bar"])
|
| 501 |
+
tm.assert_frame_equal(result, expected)
|
| 502 |
+
result = df.drop("a", axis=1)
|
| 503 |
+
tm.assert_frame_equal(result, expected)
|
| 504 |
+
|
| 505 |
+
def test_drop_with_duplicate_columns2(self):
|
| 506 |
+
# drop buggy GH#6240
|
| 507 |
+
df = pd.DataFrame(
|
| 508 |
+
{
|
| 509 |
+
"A": np.random.default_rng(2).standard_normal(5),
|
| 510 |
+
"B": np.random.default_rng(2).standard_normal(5),
|
| 511 |
+
"C": np.random.default_rng(2).standard_normal(5),
|
| 512 |
+
"D": ["a", "b", "c", "d", "e"],
|
| 513 |
+
}
|
| 514 |
+
)
|
| 515 |
+
|
| 516 |
+
expected = df.take([0, 1, 1], axis=1)
|
| 517 |
+
df2 = df.take([2, 0, 1, 2, 1], axis=1)
|
| 518 |
+
result = df2.drop("C", axis=1)
|
| 519 |
+
tm.assert_frame_equal(result, expected)
|
| 520 |
+
|
| 521 |
+
@pytest.mark.filterwarnings("ignore:The inplace keyword in DataFrame.drop is")
|
| 522 |
+
def test_drop_inplace_no_leftover_column_reference(self):
|
| 523 |
+
# GH 13934
|
| 524 |
+
df = pd.DataFrame({"a": [1, 2, 3]}, columns=pd.Index(["a"], dtype="object"))
|
| 525 |
+
a = df.a
|
| 526 |
+
df.drop(["a"], axis=1, inplace=True)
|
| 527 |
+
tm.assert_index_equal(df.columns, pd.Index([], dtype="object"))
|
| 528 |
+
a -= a.mean()
|
| 529 |
+
tm.assert_index_equal(df.columns, pd.Index([], dtype="object"))
|
| 530 |
+
|
| 531 |
+
def test_drop_level_missing_label_multiindex(self):
|
| 532 |
+
# GH 18561
|
| 533 |
+
df = pd.DataFrame(index=pd.MultiIndex.from_product([range(3), range(3)]))
|
| 534 |
+
with pytest.raises(KeyError, match="labels \\[5\\] not found in level"):
|
| 535 |
+
df.drop(5, level=0)
|
| 536 |
+
|
| 537 |
+
@pytest.mark.parametrize("idx, level", [(["a", "b"], 0), (["a"], None)])
|
| 538 |
+
def test_drop_index_ea_dtype(self, any_numeric_ea_dtype, idx, level):
|
| 539 |
+
# GH#45860
|
| 540 |
+
df = pd.DataFrame(
|
| 541 |
+
{"a": [1, 2, 2, pd.NA], "b": 100}, dtype=any_numeric_ea_dtype
|
| 542 |
+
).set_index(idx)
|
| 543 |
+
result = df.drop(pd.Index([2, pd.NA]), level=level)
|
| 544 |
+
expected = pd.DataFrame(
|
| 545 |
+
{"a": [1], "b": 100}, dtype=any_numeric_ea_dtype
|
| 546 |
+
).set_index(idx)
|
| 547 |
+
tm.assert_frame_equal(result, expected)
|
| 548 |
+
|
| 549 |
+
def test_drop_index_arrow_binary_dtype_na(self):
|
| 550 |
+
# GH#63304
|
| 551 |
+
pytest.importorskip("pyarrow")
|
| 552 |
+
|
| 553 |
+
idx = pd.Index(
|
| 554 |
+
[None, b"\xe3", b"\xe3"], dtype="binary[pyarrow]", name="bytes_col"
|
| 555 |
+
)
|
| 556 |
+
df = pd.DataFrame(index=idx)
|
| 557 |
+
|
| 558 |
+
result = df.drop(index=[pd.NA])
|
| 559 |
+
idx = pd.Index([b"\xe3", b"\xe3"], dtype="binary[pyarrow]", name="bytes_col")
|
| 560 |
+
expected = pd.DataFrame(index=idx)
|
| 561 |
+
tm.assert_frame_equal(result, expected)
|
| 562 |
+
|
| 563 |
+
def test_drop_parse_strings_datetime_index(self):
|
| 564 |
+
# GH #5355
|
| 565 |
+
df = pd.DataFrame(
|
| 566 |
+
{"a": [1, 2], "b": [1, 2]},
|
| 567 |
+
index=[pd.Timestamp("2000-01-03"), pd.Timestamp("2000-01-04")],
|
| 568 |
+
)
|
| 569 |
+
result = df.drop("2000-01-03", axis=0)
|
| 570 |
+
expected = pd.DataFrame(
|
| 571 |
+
{"a": [2], "b": [2]}, index=[pd.Timestamp("2000-01-04")]
|
| 572 |
+
)
|
| 573 |
+
tm.assert_frame_equal(result, expected)
|
| 574 |
+
|
| 575 |
+
def test_drop_inplace_depr(self):
|
| 576 |
+
# GH 63207
|
| 577 |
+
df = pd.DataFrame(
|
| 578 |
+
{"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9], "d": [10, 11, 12]}
|
| 579 |
+
)
|
| 580 |
+
msg = "The inplace keyword in DataFrame.drop is deprecated"
|
| 581 |
+
|
| 582 |
+
# uses keyword, sets to true, warning
|
| 583 |
+
with tm.assert_produces_warning(Pandas4Warning, match=msg):
|
| 584 |
+
df.drop(columns=["a"], inplace=True)
|
| 585 |
+
# uses keyword, sets to false, warning
|
| 586 |
+
with tm.assert_produces_warning(Pandas4Warning, match=msg):
|
| 587 |
+
df.drop(columns=["b"], inplace=False)
|
| 588 |
+
# does not use keyword, no warning
|
| 589 |
+
with tm.assert_produces_warning(False):
|
| 590 |
+
df.drop(columns=["c"])
|
venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_drop_duplicates.py
ADDED
|
@@ -0,0 +1,553 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from datetime import datetime
|
| 2 |
+
import re
|
| 3 |
+
|
| 4 |
+
import numpy as np
|
| 5 |
+
import pytest
|
| 6 |
+
|
| 7 |
+
from pandas.errors import Pandas4Warning
|
| 8 |
+
|
| 9 |
+
import pandas as pd
|
| 10 |
+
import pandas._testing as tm
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
@pytest.mark.parametrize("subset", ["a", ["a"], ["a", "B"]])
|
| 14 |
+
def test_drop_duplicates_with_misspelled_column_name(subset):
|
| 15 |
+
# GH 19730
|
| 16 |
+
df = pd.DataFrame({"A": [0, 0, 1], "B": [0, 0, 1], "C": [0, 0, 1]})
|
| 17 |
+
msg = re.escape("Index(['a'], dtype=")
|
| 18 |
+
|
| 19 |
+
with pytest.raises(KeyError, match=msg):
|
| 20 |
+
df.drop_duplicates(subset)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def test_drop_duplicates():
|
| 24 |
+
df = pd.DataFrame(
|
| 25 |
+
{
|
| 26 |
+
"AAA": ["foo", "bar", "foo", "bar", "foo", "bar", "bar", "foo"],
|
| 27 |
+
"B": ["one", "one", "two", "two", "two", "two", "one", "two"],
|
| 28 |
+
"C": [1, 1, 2, 2, 2, 2, 1, 2],
|
| 29 |
+
"D": range(8),
|
| 30 |
+
}
|
| 31 |
+
)
|
| 32 |
+
# single column
|
| 33 |
+
result = df.drop_duplicates("AAA")
|
| 34 |
+
expected = df[:2]
|
| 35 |
+
tm.assert_frame_equal(result, expected)
|
| 36 |
+
|
| 37 |
+
result = df.drop_duplicates("AAA", keep="last")
|
| 38 |
+
expected = df.loc[[6, 7]]
|
| 39 |
+
tm.assert_frame_equal(result, expected)
|
| 40 |
+
|
| 41 |
+
result = df.drop_duplicates("AAA", keep=False)
|
| 42 |
+
expected = df.loc[[]]
|
| 43 |
+
tm.assert_frame_equal(result, expected)
|
| 44 |
+
assert len(result) == 0
|
| 45 |
+
|
| 46 |
+
# multi column
|
| 47 |
+
expected = df.loc[[0, 1, 2, 3]]
|
| 48 |
+
result = df.drop_duplicates(np.array(["AAA", "B"]))
|
| 49 |
+
tm.assert_frame_equal(result, expected)
|
| 50 |
+
result = df.drop_duplicates(["AAA", "B"])
|
| 51 |
+
tm.assert_frame_equal(result, expected)
|
| 52 |
+
|
| 53 |
+
result = df.drop_duplicates(("AAA", "B"), keep="last")
|
| 54 |
+
expected = df.loc[[0, 5, 6, 7]]
|
| 55 |
+
tm.assert_frame_equal(result, expected)
|
| 56 |
+
|
| 57 |
+
result = df.drop_duplicates(("AAA", "B"), keep=False)
|
| 58 |
+
expected = df.loc[[0]]
|
| 59 |
+
tm.assert_frame_equal(result, expected)
|
| 60 |
+
|
| 61 |
+
# consider everything
|
| 62 |
+
df2 = df.loc[:, ["AAA", "B", "C"]]
|
| 63 |
+
|
| 64 |
+
result = df2.drop_duplicates()
|
| 65 |
+
# in this case only
|
| 66 |
+
expected = df2.drop_duplicates(["AAA", "B"])
|
| 67 |
+
tm.assert_frame_equal(result, expected)
|
| 68 |
+
|
| 69 |
+
result = df2.drop_duplicates(keep="last")
|
| 70 |
+
expected = df2.drop_duplicates(["AAA", "B"], keep="last")
|
| 71 |
+
tm.assert_frame_equal(result, expected)
|
| 72 |
+
|
| 73 |
+
result = df2.drop_duplicates(keep=False)
|
| 74 |
+
expected = df2.drop_duplicates(["AAA", "B"], keep=False)
|
| 75 |
+
tm.assert_frame_equal(result, expected)
|
| 76 |
+
|
| 77 |
+
# integers
|
| 78 |
+
result = df.drop_duplicates("C")
|
| 79 |
+
expected = df.iloc[[0, 2]]
|
| 80 |
+
tm.assert_frame_equal(result, expected)
|
| 81 |
+
result = df.drop_duplicates("C", keep="last")
|
| 82 |
+
expected = df.iloc[[-2, -1]]
|
| 83 |
+
tm.assert_frame_equal(result, expected)
|
| 84 |
+
|
| 85 |
+
df["E"] = df["C"].astype("int8")
|
| 86 |
+
result = df.drop_duplicates("E")
|
| 87 |
+
expected = df.iloc[[0, 2]]
|
| 88 |
+
tm.assert_frame_equal(result, expected)
|
| 89 |
+
result = df.drop_duplicates("E", keep="last")
|
| 90 |
+
expected = df.iloc[[-2, -1]]
|
| 91 |
+
tm.assert_frame_equal(result, expected)
|
| 92 |
+
|
| 93 |
+
# GH 11376
|
| 94 |
+
df = pd.DataFrame({"x": [7, 6, 3, 3, 4, 8, 0], "y": [0, 6, 5, 5, 9, 1, 2]})
|
| 95 |
+
expected = df.loc[df.index != 3]
|
| 96 |
+
tm.assert_frame_equal(df.drop_duplicates(), expected)
|
| 97 |
+
|
| 98 |
+
df = pd.DataFrame([[1, 0], [0, 2]])
|
| 99 |
+
tm.assert_frame_equal(df.drop_duplicates(), df)
|
| 100 |
+
|
| 101 |
+
df = pd.DataFrame([[-2, 0], [0, -4]])
|
| 102 |
+
tm.assert_frame_equal(df.drop_duplicates(), df)
|
| 103 |
+
|
| 104 |
+
x = np.iinfo(np.int64).max / 3 * 2
|
| 105 |
+
df = pd.DataFrame([[-x, x], [0, x + 4]])
|
| 106 |
+
tm.assert_frame_equal(df.drop_duplicates(), df)
|
| 107 |
+
|
| 108 |
+
df = pd.DataFrame([[-x, x], [x, x + 4]])
|
| 109 |
+
tm.assert_frame_equal(df.drop_duplicates(), df)
|
| 110 |
+
|
| 111 |
+
# GH 11864
|
| 112 |
+
df = pd.DataFrame([i] * 9 for i in range(16))
|
| 113 |
+
df = pd.concat([df, pd.DataFrame([[1] + [0] * 8])], ignore_index=True)
|
| 114 |
+
|
| 115 |
+
for keep in ["first", "last", False]:
|
| 116 |
+
assert df.duplicated(keep=keep).sum() == 0
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def test_drop_duplicates_with_duplicate_column_names():
|
| 120 |
+
# GH17836
|
| 121 |
+
df = pd.DataFrame([[1, 2, 5], [3, 4, 6], [3, 4, 7]], columns=["a", "a", "b"])
|
| 122 |
+
|
| 123 |
+
result0 = df.drop_duplicates()
|
| 124 |
+
tm.assert_frame_equal(result0, df)
|
| 125 |
+
|
| 126 |
+
result1 = df.drop_duplicates("a")
|
| 127 |
+
expected1 = df[:2]
|
| 128 |
+
tm.assert_frame_equal(result1, expected1)
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def test_drop_duplicates_for_take_all():
|
| 132 |
+
df = pd.DataFrame(
|
| 133 |
+
{
|
| 134 |
+
"AAA": ["foo", "bar", "baz", "bar", "foo", "bar", "qux", "foo"],
|
| 135 |
+
"B": ["one", "one", "two", "two", "two", "two", "one", "two"],
|
| 136 |
+
"C": [1, 1, 2, 2, 2, 2, 1, 2],
|
| 137 |
+
"D": range(8),
|
| 138 |
+
}
|
| 139 |
+
)
|
| 140 |
+
# single column
|
| 141 |
+
result = df.drop_duplicates("AAA")
|
| 142 |
+
expected = df.iloc[[0, 1, 2, 6]]
|
| 143 |
+
tm.assert_frame_equal(result, expected)
|
| 144 |
+
|
| 145 |
+
result = df.drop_duplicates("AAA", keep="last")
|
| 146 |
+
expected = df.iloc[[2, 5, 6, 7]]
|
| 147 |
+
tm.assert_frame_equal(result, expected)
|
| 148 |
+
|
| 149 |
+
result = df.drop_duplicates("AAA", keep=False)
|
| 150 |
+
expected = df.iloc[[2, 6]]
|
| 151 |
+
tm.assert_frame_equal(result, expected)
|
| 152 |
+
|
| 153 |
+
# multiple columns
|
| 154 |
+
result = df.drop_duplicates(["AAA", "B"])
|
| 155 |
+
expected = df.iloc[[0, 1, 2, 3, 4, 6]]
|
| 156 |
+
tm.assert_frame_equal(result, expected)
|
| 157 |
+
|
| 158 |
+
result = df.drop_duplicates(["AAA", "B"], keep="last")
|
| 159 |
+
expected = df.iloc[[0, 1, 2, 5, 6, 7]]
|
| 160 |
+
tm.assert_frame_equal(result, expected)
|
| 161 |
+
|
| 162 |
+
result = df.drop_duplicates(["AAA", "B"], keep=False)
|
| 163 |
+
expected = df.iloc[[0, 1, 2, 6]]
|
| 164 |
+
tm.assert_frame_equal(result, expected)
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def test_drop_duplicates_tuple():
|
| 168 |
+
df = pd.DataFrame(
|
| 169 |
+
{
|
| 170 |
+
("AA", "AB"): ["foo", "bar", "foo", "bar", "foo", "bar", "bar", "foo"],
|
| 171 |
+
"B": ["one", "one", "two", "two", "two", "two", "one", "two"],
|
| 172 |
+
"C": [1, 1, 2, 2, 2, 2, 1, 2],
|
| 173 |
+
"D": range(8),
|
| 174 |
+
}
|
| 175 |
+
)
|
| 176 |
+
# single column
|
| 177 |
+
result = df.drop_duplicates(("AA", "AB"))
|
| 178 |
+
expected = df[:2]
|
| 179 |
+
tm.assert_frame_equal(result, expected)
|
| 180 |
+
|
| 181 |
+
result = df.drop_duplicates(("AA", "AB"), keep="last")
|
| 182 |
+
expected = df.loc[[6, 7]]
|
| 183 |
+
tm.assert_frame_equal(result, expected)
|
| 184 |
+
|
| 185 |
+
result = df.drop_duplicates(("AA", "AB"), keep=False)
|
| 186 |
+
expected = df.loc[[]] # empty df
|
| 187 |
+
assert len(result) == 0
|
| 188 |
+
tm.assert_frame_equal(result, expected)
|
| 189 |
+
|
| 190 |
+
# multi column
|
| 191 |
+
expected = df.loc[[0, 1, 2, 3]]
|
| 192 |
+
result = df.drop_duplicates((("AA", "AB"), "B"))
|
| 193 |
+
tm.assert_frame_equal(result, expected)
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
@pytest.mark.filterwarnings("ignore:The inplace keyword in DataFrame.drop_duplicates")
|
| 197 |
+
@pytest.mark.parametrize(
|
| 198 |
+
"df",
|
| 199 |
+
[
|
| 200 |
+
pd.DataFrame(),
|
| 201 |
+
pd.DataFrame(columns=[]),
|
| 202 |
+
pd.DataFrame(columns=["A", "B", "C"]),
|
| 203 |
+
pd.DataFrame(index=[]),
|
| 204 |
+
pd.DataFrame(index=["A", "B", "C"]),
|
| 205 |
+
],
|
| 206 |
+
)
|
| 207 |
+
def test_drop_duplicates_empty(df):
|
| 208 |
+
# GH 20516
|
| 209 |
+
result = df.drop_duplicates()
|
| 210 |
+
tm.assert_frame_equal(result, df)
|
| 211 |
+
|
| 212 |
+
result = df.copy()
|
| 213 |
+
result.drop_duplicates(inplace=True)
|
| 214 |
+
tm.assert_frame_equal(result, df)
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
def test_drop_duplicates_NA():
|
| 218 |
+
# none
|
| 219 |
+
df = pd.DataFrame(
|
| 220 |
+
{
|
| 221 |
+
"A": [None, None, "foo", "bar", "foo", "bar", "bar", "foo"],
|
| 222 |
+
"B": ["one", "one", "two", "two", "two", "two", "one", "two"],
|
| 223 |
+
"C": [1.0, np.nan, np.nan, np.nan, 1.0, 1.0, 1, 1.0],
|
| 224 |
+
"D": range(8),
|
| 225 |
+
}
|
| 226 |
+
)
|
| 227 |
+
# single column
|
| 228 |
+
result = df.drop_duplicates("A")
|
| 229 |
+
expected = df.loc[[0, 2, 3]]
|
| 230 |
+
tm.assert_frame_equal(result, expected)
|
| 231 |
+
|
| 232 |
+
result = df.drop_duplicates("A", keep="last")
|
| 233 |
+
expected = df.loc[[1, 6, 7]]
|
| 234 |
+
tm.assert_frame_equal(result, expected)
|
| 235 |
+
|
| 236 |
+
result = df.drop_duplicates("A", keep=False)
|
| 237 |
+
expected = df.loc[[]] # empty df
|
| 238 |
+
tm.assert_frame_equal(result, expected)
|
| 239 |
+
assert len(result) == 0
|
| 240 |
+
|
| 241 |
+
# multi column
|
| 242 |
+
result = df.drop_duplicates(["A", "B"])
|
| 243 |
+
expected = df.loc[[0, 2, 3, 6]]
|
| 244 |
+
tm.assert_frame_equal(result, expected)
|
| 245 |
+
|
| 246 |
+
result = df.drop_duplicates(["A", "B"], keep="last")
|
| 247 |
+
expected = df.loc[[1, 5, 6, 7]]
|
| 248 |
+
tm.assert_frame_equal(result, expected)
|
| 249 |
+
|
| 250 |
+
result = df.drop_duplicates(["A", "B"], keep=False)
|
| 251 |
+
expected = df.loc[[6]]
|
| 252 |
+
tm.assert_frame_equal(result, expected)
|
| 253 |
+
|
| 254 |
+
# nan
|
| 255 |
+
df = pd.DataFrame(
|
| 256 |
+
{
|
| 257 |
+
"A": ["foo", "bar", "foo", "bar", "foo", "bar", "bar", "foo"],
|
| 258 |
+
"B": ["one", "one", "two", "two", "two", "two", "one", "two"],
|
| 259 |
+
"C": [1.0, np.nan, np.nan, np.nan, 1.0, 1.0, 1, 1.0],
|
| 260 |
+
"D": range(8),
|
| 261 |
+
}
|
| 262 |
+
)
|
| 263 |
+
# single column
|
| 264 |
+
result = df.drop_duplicates("C")
|
| 265 |
+
expected = df[:2]
|
| 266 |
+
tm.assert_frame_equal(result, expected)
|
| 267 |
+
|
| 268 |
+
result = df.drop_duplicates("C", keep="last")
|
| 269 |
+
expected = df.loc[[3, 7]]
|
| 270 |
+
tm.assert_frame_equal(result, expected)
|
| 271 |
+
|
| 272 |
+
result = df.drop_duplicates("C", keep=False)
|
| 273 |
+
expected = df.loc[[]] # empty df
|
| 274 |
+
tm.assert_frame_equal(result, expected)
|
| 275 |
+
assert len(result) == 0
|
| 276 |
+
|
| 277 |
+
# multi column
|
| 278 |
+
result = df.drop_duplicates(["C", "B"])
|
| 279 |
+
expected = df.loc[[0, 1, 2, 4]]
|
| 280 |
+
tm.assert_frame_equal(result, expected)
|
| 281 |
+
|
| 282 |
+
result = df.drop_duplicates(["C", "B"], keep="last")
|
| 283 |
+
expected = df.loc[[1, 3, 6, 7]]
|
| 284 |
+
tm.assert_frame_equal(result, expected)
|
| 285 |
+
|
| 286 |
+
result = df.drop_duplicates(["C", "B"], keep=False)
|
| 287 |
+
expected = df.loc[[1]]
|
| 288 |
+
tm.assert_frame_equal(result, expected)
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
def test_drop_duplicates_NA_for_take_all():
|
| 292 |
+
# none
|
| 293 |
+
df = pd.DataFrame(
|
| 294 |
+
{
|
| 295 |
+
"A": [None, None, "foo", "bar", "foo", "baz", "bar", "qux"],
|
| 296 |
+
"C": [1.0, np.nan, np.nan, np.nan, 1.0, 2.0, 3, 1.0],
|
| 297 |
+
}
|
| 298 |
+
)
|
| 299 |
+
|
| 300 |
+
# single column
|
| 301 |
+
result = df.drop_duplicates("A")
|
| 302 |
+
expected = df.iloc[[0, 2, 3, 5, 7]]
|
| 303 |
+
tm.assert_frame_equal(result, expected)
|
| 304 |
+
|
| 305 |
+
result = df.drop_duplicates("A", keep="last")
|
| 306 |
+
expected = df.iloc[[1, 4, 5, 6, 7]]
|
| 307 |
+
tm.assert_frame_equal(result, expected)
|
| 308 |
+
|
| 309 |
+
result = df.drop_duplicates("A", keep=False)
|
| 310 |
+
expected = df.iloc[[5, 7]]
|
| 311 |
+
tm.assert_frame_equal(result, expected)
|
| 312 |
+
|
| 313 |
+
# nan
|
| 314 |
+
|
| 315 |
+
# single column
|
| 316 |
+
result = df.drop_duplicates("C")
|
| 317 |
+
expected = df.iloc[[0, 1, 5, 6]]
|
| 318 |
+
tm.assert_frame_equal(result, expected)
|
| 319 |
+
|
| 320 |
+
result = df.drop_duplicates("C", keep="last")
|
| 321 |
+
expected = df.iloc[[3, 5, 6, 7]]
|
| 322 |
+
tm.assert_frame_equal(result, expected)
|
| 323 |
+
|
| 324 |
+
result = df.drop_duplicates("C", keep=False)
|
| 325 |
+
expected = df.iloc[[5, 6]]
|
| 326 |
+
tm.assert_frame_equal(result, expected)
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
@pytest.mark.filterwarnings("ignore:The inplace keyword in DataFrame.drop_duplicates")
|
| 330 |
+
def test_drop_duplicates_inplace():
|
| 331 |
+
orig = pd.DataFrame(
|
| 332 |
+
{
|
| 333 |
+
"A": ["foo", "bar", "foo", "bar", "foo", "bar", "bar", "foo"],
|
| 334 |
+
"B": ["one", "one", "two", "two", "two", "two", "one", "two"],
|
| 335 |
+
"C": [1, 1, 2, 2, 2, 2, 1, 2],
|
| 336 |
+
"D": range(8),
|
| 337 |
+
}
|
| 338 |
+
)
|
| 339 |
+
# single column
|
| 340 |
+
df = orig.copy()
|
| 341 |
+
return_value = df.drop_duplicates("A", inplace=True)
|
| 342 |
+
expected = orig[:2]
|
| 343 |
+
result = df
|
| 344 |
+
tm.assert_frame_equal(result, expected)
|
| 345 |
+
assert return_value is None
|
| 346 |
+
|
| 347 |
+
df = orig.copy()
|
| 348 |
+
return_value = df.drop_duplicates("A", keep="last", inplace=True)
|
| 349 |
+
expected = orig.loc[[6, 7]]
|
| 350 |
+
result = df
|
| 351 |
+
tm.assert_frame_equal(result, expected)
|
| 352 |
+
assert return_value is None
|
| 353 |
+
|
| 354 |
+
df = orig.copy()
|
| 355 |
+
return_value = df.drop_duplicates("A", keep=False, inplace=True)
|
| 356 |
+
expected = orig.loc[[]]
|
| 357 |
+
result = df
|
| 358 |
+
tm.assert_frame_equal(result, expected)
|
| 359 |
+
assert len(df) == 0
|
| 360 |
+
assert return_value is None
|
| 361 |
+
|
| 362 |
+
# multi column
|
| 363 |
+
df = orig.copy()
|
| 364 |
+
return_value = df.drop_duplicates(["A", "B"], inplace=True)
|
| 365 |
+
expected = orig.loc[[0, 1, 2, 3]]
|
| 366 |
+
result = df
|
| 367 |
+
tm.assert_frame_equal(result, expected)
|
| 368 |
+
assert return_value is None
|
| 369 |
+
|
| 370 |
+
df = orig.copy()
|
| 371 |
+
return_value = df.drop_duplicates(["A", "B"], keep="last", inplace=True)
|
| 372 |
+
expected = orig.loc[[0, 5, 6, 7]]
|
| 373 |
+
result = df
|
| 374 |
+
tm.assert_frame_equal(result, expected)
|
| 375 |
+
assert return_value is None
|
| 376 |
+
|
| 377 |
+
df = orig.copy()
|
| 378 |
+
return_value = df.drop_duplicates(["A", "B"], keep=False, inplace=True)
|
| 379 |
+
expected = orig.loc[[0]]
|
| 380 |
+
result = df
|
| 381 |
+
tm.assert_frame_equal(result, expected)
|
| 382 |
+
assert return_value is None
|
| 383 |
+
|
| 384 |
+
# consider everything
|
| 385 |
+
orig2 = orig.loc[:, ["A", "B", "C"]].copy()
|
| 386 |
+
|
| 387 |
+
df2 = orig2.copy()
|
| 388 |
+
return_value = df2.drop_duplicates(inplace=True)
|
| 389 |
+
# in this case only
|
| 390 |
+
expected = orig2.drop_duplicates(["A", "B"])
|
| 391 |
+
result = df2
|
| 392 |
+
tm.assert_frame_equal(result, expected)
|
| 393 |
+
assert return_value is None
|
| 394 |
+
|
| 395 |
+
df2 = orig2.copy()
|
| 396 |
+
return_value = df2.drop_duplicates(keep="last", inplace=True)
|
| 397 |
+
expected = orig2.drop_duplicates(["A", "B"], keep="last")
|
| 398 |
+
result = df2
|
| 399 |
+
tm.assert_frame_equal(result, expected)
|
| 400 |
+
assert return_value is None
|
| 401 |
+
|
| 402 |
+
df2 = orig2.copy()
|
| 403 |
+
return_value = df2.drop_duplicates(keep=False, inplace=True)
|
| 404 |
+
expected = orig2.drop_duplicates(["A", "B"], keep=False)
|
| 405 |
+
result = df2
|
| 406 |
+
tm.assert_frame_equal(result, expected)
|
| 407 |
+
assert return_value is None
|
| 408 |
+
|
| 409 |
+
|
| 410 |
+
@pytest.mark.filterwarnings("ignore:The inplace keyword in DataFrame.drop_duplicates")
|
| 411 |
+
@pytest.mark.parametrize("inplace", [True, False])
|
| 412 |
+
@pytest.mark.parametrize(
|
| 413 |
+
"origin_dict, output_dict, ignore_index, output_index",
|
| 414 |
+
[
|
| 415 |
+
({"A": [2, 2, 3]}, {"A": [2, 3]}, True, range(2)),
|
| 416 |
+
({"A": [2, 2, 3]}, {"A": [2, 3]}, False, range(0, 4, 2)),
|
| 417 |
+
({"A": [2, 2, 3], "B": [2, 2, 4]}, {"A": [2, 3], "B": [2, 4]}, True, range(2)),
|
| 418 |
+
(
|
| 419 |
+
{"A": [2, 2, 3], "B": [2, 2, 4]},
|
| 420 |
+
{"A": [2, 3], "B": [2, 4]},
|
| 421 |
+
False,
|
| 422 |
+
range(0, 4, 2),
|
| 423 |
+
),
|
| 424 |
+
],
|
| 425 |
+
)
|
| 426 |
+
def test_drop_duplicates_ignore_index(
|
| 427 |
+
inplace, origin_dict, output_dict, ignore_index, output_index
|
| 428 |
+
):
|
| 429 |
+
# GH 30114
|
| 430 |
+
df = pd.DataFrame(origin_dict)
|
| 431 |
+
expected = pd.DataFrame(output_dict, index=output_index)
|
| 432 |
+
|
| 433 |
+
if inplace:
|
| 434 |
+
result_df = df.copy()
|
| 435 |
+
result_df.drop_duplicates(ignore_index=ignore_index, inplace=inplace)
|
| 436 |
+
else:
|
| 437 |
+
result_df = df.drop_duplicates(ignore_index=ignore_index, inplace=inplace)
|
| 438 |
+
|
| 439 |
+
tm.assert_frame_equal(result_df, expected)
|
| 440 |
+
tm.assert_frame_equal(df, pd.DataFrame(origin_dict))
|
| 441 |
+
|
| 442 |
+
|
| 443 |
+
def test_drop_duplicates_null_in_object_column(nulls_fixture):
|
| 444 |
+
# https://github.com/pandas-dev/pandas/issues/32992
|
| 445 |
+
df = pd.DataFrame([[1, nulls_fixture], [2, "a"]], dtype=object)
|
| 446 |
+
result = df.drop_duplicates()
|
| 447 |
+
tm.assert_frame_equal(result, df)
|
| 448 |
+
|
| 449 |
+
|
| 450 |
+
def test_drop_duplicates_series_vs_dataframe(keep):
|
| 451 |
+
# GH#14192
|
| 452 |
+
df = pd.DataFrame(
|
| 453 |
+
{
|
| 454 |
+
"a": [1, 1, 1, "one", "one"],
|
| 455 |
+
"b": [2, 2, np.nan, np.nan, np.nan],
|
| 456 |
+
"c": [3, 3, np.nan, np.nan, "three"],
|
| 457 |
+
"d": [1, 2, 3, 4, 4],
|
| 458 |
+
"e": [
|
| 459 |
+
datetime(2015, 1, 1),
|
| 460 |
+
datetime(2015, 1, 1),
|
| 461 |
+
datetime(2015, 2, 1),
|
| 462 |
+
pd.NaT,
|
| 463 |
+
pd.NaT,
|
| 464 |
+
],
|
| 465 |
+
}
|
| 466 |
+
)
|
| 467 |
+
for column in df.columns:
|
| 468 |
+
dropped_frame = df[[column]].drop_duplicates(keep=keep)
|
| 469 |
+
dropped_series = df[column].drop_duplicates(keep=keep)
|
| 470 |
+
tm.assert_frame_equal(dropped_frame, dropped_series.to_frame())
|
| 471 |
+
|
| 472 |
+
|
| 473 |
+
@pytest.mark.parametrize("arg", [[1], 1, "True", [], 0])
|
| 474 |
+
def test_drop_duplicates_non_boolean_ignore_index(arg):
|
| 475 |
+
# GH#38274
|
| 476 |
+
df = pd.DataFrame({"a": [1, 2, 1, 3]})
|
| 477 |
+
msg = '^For argument "ignore_index" expected type bool, received type .*.$'
|
| 478 |
+
with pytest.raises(ValueError, match=msg):
|
| 479 |
+
df.drop_duplicates(ignore_index=arg)
|
| 480 |
+
|
| 481 |
+
|
| 482 |
+
def test_drop_duplicates_set():
|
| 483 |
+
# GH#59237
|
| 484 |
+
df = pd.DataFrame(
|
| 485 |
+
{
|
| 486 |
+
"AAA": ["foo", "bar", "foo", "bar", "foo", "bar", "bar", "foo"],
|
| 487 |
+
"B": ["one", "one", "two", "two", "two", "two", "one", "two"],
|
| 488 |
+
"C": [1, 1, 2, 2, 2, 2, 1, 2],
|
| 489 |
+
"D": range(8),
|
| 490 |
+
}
|
| 491 |
+
)
|
| 492 |
+
# single column
|
| 493 |
+
result = df.drop_duplicates({"AAA"})
|
| 494 |
+
expected = df[:2]
|
| 495 |
+
tm.assert_frame_equal(result, expected)
|
| 496 |
+
|
| 497 |
+
result = df.drop_duplicates({"AAA"}, keep="last")
|
| 498 |
+
expected = df.loc[[6, 7]]
|
| 499 |
+
tm.assert_frame_equal(result, expected)
|
| 500 |
+
|
| 501 |
+
result = df.drop_duplicates({"AAA"}, keep=False)
|
| 502 |
+
expected = df.loc[[]]
|
| 503 |
+
tm.assert_frame_equal(result, expected)
|
| 504 |
+
assert len(result) == 0
|
| 505 |
+
|
| 506 |
+
# multi column
|
| 507 |
+
expected = df.loc[[0, 1, 2, 3]]
|
| 508 |
+
result = df.drop_duplicates({"AAA", "B"})
|
| 509 |
+
tm.assert_frame_equal(result, expected)
|
| 510 |
+
|
| 511 |
+
result = df.drop_duplicates({"AAA", "B"}, keep="last")
|
| 512 |
+
expected = df.loc[[0, 5, 6, 7]]
|
| 513 |
+
tm.assert_frame_equal(result, expected)
|
| 514 |
+
|
| 515 |
+
result = df.drop_duplicates({"AAA", "B"}, keep=False)
|
| 516 |
+
expected = df.loc[[0]]
|
| 517 |
+
tm.assert_frame_equal(result, expected)
|
| 518 |
+
|
| 519 |
+
|
| 520 |
+
def test_drop_duplicates_with_empty_missing():
|
| 521 |
+
# https://github.com/pandas-dev/pandas/issues/62611 - specific bug with pyarrow
|
| 522 |
+
df = pd.DataFrame(data={"A": ["a", "b", "", "a", None, "b"]})
|
| 523 |
+
df["B"] = "b"
|
| 524 |
+
result = df.drop_duplicates()
|
| 525 |
+
expected = pd.DataFrame(
|
| 526 |
+
data={"A": ["a", "b", "", None], "B": ["b", "b", "b", "b"]}, index=[0, 1, 2, 4]
|
| 527 |
+
)
|
| 528 |
+
tm.assert_frame_equal(result, expected)
|
| 529 |
+
|
| 530 |
+
|
| 531 |
+
def test_drop_duplicates_inplace_depr():
|
| 532 |
+
msg = "The inplace keyword in DataFrame.drop_duplicates is deprecated"
|
| 533 |
+
|
| 534 |
+
df = pd.DataFrame({"A": [1, 2, 2, 3]})
|
| 535 |
+
df_orig = df.copy()
|
| 536 |
+
expected = pd.DataFrame({"A": [1, 2, 3]}, index=[0, 1, 3])
|
| 537 |
+
|
| 538 |
+
# does not use keyword, no warning
|
| 539 |
+
with tm.assert_produces_warning(False):
|
| 540 |
+
result = df.drop_duplicates()
|
| 541 |
+
tm.assert_frame_equal(result, expected)
|
| 542 |
+
tm.assert_frame_equal(df, df_orig)
|
| 543 |
+
|
| 544 |
+
# uses keyword, set to false, warning
|
| 545 |
+
with tm.assert_produces_warning(Pandas4Warning, match=msg):
|
| 546 |
+
result = df.drop_duplicates(inplace=False)
|
| 547 |
+
tm.assert_frame_equal(result, expected)
|
| 548 |
+
tm.assert_frame_equal(df, df_orig)
|
| 549 |
+
|
| 550 |
+
# uses keyword, set to true, warning
|
| 551 |
+
with tm.assert_produces_warning(Pandas4Warning, match=msg):
|
| 552 |
+
df.drop_duplicates(inplace=True)
|
| 553 |
+
tm.assert_frame_equal(df, expected)
|
venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_droplevel.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import pandas._testing as tm
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class TestDropLevel:
|
| 8 |
+
def test_droplevel(self, frame_or_series):
|
| 9 |
+
# GH#20342
|
| 10 |
+
cols = pd.MultiIndex.from_tuples(
|
| 11 |
+
[("c", "e"), ("d", "f")], names=["level_1", "level_2"]
|
| 12 |
+
)
|
| 13 |
+
mi = pd.MultiIndex.from_tuples([(1, 2), (5, 6), (9, 10)], names=["a", "b"])
|
| 14 |
+
df = pd.DataFrame([[3, 4], [7, 8], [11, 12]], index=mi, columns=cols)
|
| 15 |
+
if frame_or_series is not pd.DataFrame:
|
| 16 |
+
df = df.iloc[:, 0]
|
| 17 |
+
|
| 18 |
+
# test that dropping of a level in index works
|
| 19 |
+
expected = df.reset_index("a", drop=True)
|
| 20 |
+
result = df.droplevel("a", axis="index")
|
| 21 |
+
tm.assert_equal(result, expected)
|
| 22 |
+
|
| 23 |
+
if frame_or_series is pd.DataFrame:
|
| 24 |
+
# test that dropping of a level in columns works
|
| 25 |
+
expected = df.copy()
|
| 26 |
+
expected.columns = pd.Index(["c", "d"], name="level_1")
|
| 27 |
+
result = df.droplevel("level_2", axis="columns")
|
| 28 |
+
tm.assert_equal(result, expected)
|
| 29 |
+
else:
|
| 30 |
+
# test that droplevel raises ValueError on axis != 0
|
| 31 |
+
with pytest.raises(ValueError, match="No axis named columns"):
|
| 32 |
+
df.droplevel(1, axis="columns")
|
venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_dropna.py
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
| 1 |
+
import datetime
|
| 2 |
+
|
| 3 |
+
import dateutil
|
| 4 |
+
import numpy as np
|
| 5 |
+
import pytest
|
| 6 |
+
|
| 7 |
+
from pandas.errors import Pandas4Warning
|
| 8 |
+
|
| 9 |
+
import pandas as pd
|
| 10 |
+
import pandas._testing as tm
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class TestDataFrameMissingData:
|
| 14 |
+
@pytest.mark.filterwarnings("ignore:The inplace keyword in DataFrame.dropna")
|
| 15 |
+
def test_dropEmptyRows(self, float_frame):
|
| 16 |
+
N = len(float_frame.index)
|
| 17 |
+
mat = np.random.default_rng(2).standard_normal(N)
|
| 18 |
+
mat[:5] = np.nan
|
| 19 |
+
|
| 20 |
+
frame = pd.DataFrame({"foo": mat}, index=float_frame.index)
|
| 21 |
+
original = pd.Series(mat, index=float_frame.index, name="foo")
|
| 22 |
+
expected = original.dropna()
|
| 23 |
+
inplace_frame1, inplace_frame2 = frame.copy(), frame.copy()
|
| 24 |
+
|
| 25 |
+
smaller_frame = frame.dropna(how="all")
|
| 26 |
+
# check that original was preserved
|
| 27 |
+
tm.assert_series_equal(frame["foo"], original)
|
| 28 |
+
return_value = inplace_frame1.dropna(how="all", inplace=True)
|
| 29 |
+
tm.assert_series_equal(smaller_frame["foo"], expected)
|
| 30 |
+
tm.assert_series_equal(inplace_frame1["foo"], expected)
|
| 31 |
+
assert return_value is None
|
| 32 |
+
|
| 33 |
+
smaller_frame = frame.dropna(how="all", subset=["foo"])
|
| 34 |
+
return_value = inplace_frame2.dropna(how="all", subset=["foo"], inplace=True)
|
| 35 |
+
tm.assert_series_equal(smaller_frame["foo"], expected)
|
| 36 |
+
tm.assert_series_equal(inplace_frame2["foo"], expected)
|
| 37 |
+
assert return_value is None
|
| 38 |
+
|
| 39 |
+
@pytest.mark.filterwarnings("ignore:The inplace keyword in DataFrame.dropna")
|
| 40 |
+
def test_dropIncompleteRows(self, float_frame):
|
| 41 |
+
N = len(float_frame.index)
|
| 42 |
+
mat = np.random.default_rng(2).standard_normal(N)
|
| 43 |
+
mat[:5] = np.nan
|
| 44 |
+
|
| 45 |
+
frame = pd.DataFrame({"foo": mat}, index=float_frame.index)
|
| 46 |
+
frame["bar"] = 5
|
| 47 |
+
original = pd.Series(mat, index=float_frame.index, name="foo")
|
| 48 |
+
inp_frame1, inp_frame2 = frame.copy(), frame.copy()
|
| 49 |
+
|
| 50 |
+
smaller_frame = frame.dropna()
|
| 51 |
+
tm.assert_series_equal(frame["foo"], original)
|
| 52 |
+
return_value = inp_frame1.dropna(inplace=True)
|
| 53 |
+
|
| 54 |
+
exp = pd.Series(mat[5:], index=float_frame.index[5:], name="foo")
|
| 55 |
+
tm.assert_series_equal(smaller_frame["foo"], exp)
|
| 56 |
+
tm.assert_series_equal(inp_frame1["foo"], exp)
|
| 57 |
+
assert return_value is None
|
| 58 |
+
|
| 59 |
+
samesize_frame = frame.dropna(subset=["bar"])
|
| 60 |
+
tm.assert_series_equal(frame["foo"], original)
|
| 61 |
+
assert (frame["bar"] == 5).all()
|
| 62 |
+
return_value = inp_frame2.dropna(subset=["bar"], inplace=True)
|
| 63 |
+
tm.assert_index_equal(samesize_frame.index, float_frame.index)
|
| 64 |
+
tm.assert_index_equal(inp_frame2.index, float_frame.index)
|
| 65 |
+
assert return_value is None
|
| 66 |
+
|
| 67 |
+
@pytest.mark.filterwarnings("ignore:The inplace keyword in DataFrame.dropna")
|
| 68 |
+
def test_dropna(self):
|
| 69 |
+
df = pd.DataFrame(np.random.default_rng(2).standard_normal((6, 4)))
|
| 70 |
+
df.iloc[:2, 2] = np.nan
|
| 71 |
+
|
| 72 |
+
dropped = df.dropna(axis=1)
|
| 73 |
+
expected = df.loc[:, [0, 1, 3]]
|
| 74 |
+
inp = df.copy()
|
| 75 |
+
return_value = inp.dropna(axis=1, inplace=True)
|
| 76 |
+
tm.assert_frame_equal(dropped, expected)
|
| 77 |
+
tm.assert_frame_equal(inp, expected)
|
| 78 |
+
assert return_value is None
|
| 79 |
+
|
| 80 |
+
dropped = df.dropna(axis=0)
|
| 81 |
+
expected = df.loc[list(range(2, 6))]
|
| 82 |
+
inp = df.copy()
|
| 83 |
+
return_value = inp.dropna(axis=0, inplace=True)
|
| 84 |
+
tm.assert_frame_equal(dropped, expected)
|
| 85 |
+
tm.assert_frame_equal(inp, expected)
|
| 86 |
+
assert return_value is None
|
| 87 |
+
|
| 88 |
+
# threshold
|
| 89 |
+
dropped = df.dropna(axis=1, thresh=5)
|
| 90 |
+
expected = df.loc[:, [0, 1, 3]]
|
| 91 |
+
inp = df.copy()
|
| 92 |
+
return_value = inp.dropna(axis=1, thresh=5, inplace=True)
|
| 93 |
+
tm.assert_frame_equal(dropped, expected)
|
| 94 |
+
tm.assert_frame_equal(inp, expected)
|
| 95 |
+
assert return_value is None
|
| 96 |
+
|
| 97 |
+
dropped = df.dropna(axis=0, thresh=4)
|
| 98 |
+
expected = df.loc[range(2, 6)]
|
| 99 |
+
inp = df.copy()
|
| 100 |
+
return_value = inp.dropna(axis=0, thresh=4, inplace=True)
|
| 101 |
+
tm.assert_frame_equal(dropped, expected)
|
| 102 |
+
tm.assert_frame_equal(inp, expected)
|
| 103 |
+
assert return_value is None
|
| 104 |
+
|
| 105 |
+
dropped = df.dropna(axis=1, thresh=4)
|
| 106 |
+
tm.assert_frame_equal(dropped, df)
|
| 107 |
+
|
| 108 |
+
dropped = df.dropna(axis=1, thresh=3)
|
| 109 |
+
tm.assert_frame_equal(dropped, df)
|
| 110 |
+
|
| 111 |
+
# subset
|
| 112 |
+
dropped = df.dropna(axis=0, subset=[0, 1, 3])
|
| 113 |
+
inp = df.copy()
|
| 114 |
+
return_value = inp.dropna(axis=0, subset=[0, 1, 3], inplace=True)
|
| 115 |
+
tm.assert_frame_equal(dropped, df)
|
| 116 |
+
tm.assert_frame_equal(inp, df)
|
| 117 |
+
assert return_value is None
|
| 118 |
+
|
| 119 |
+
# all
|
| 120 |
+
dropped = df.dropna(axis=1, how="all")
|
| 121 |
+
tm.assert_frame_equal(dropped, df)
|
| 122 |
+
|
| 123 |
+
df[2] = np.nan
|
| 124 |
+
dropped = df.dropna(axis=1, how="all")
|
| 125 |
+
expected = df.loc[:, [0, 1, 3]]
|
| 126 |
+
tm.assert_frame_equal(dropped, expected)
|
| 127 |
+
|
| 128 |
+
# bad input
|
| 129 |
+
msg = "No axis named 3 for object type DataFrame"
|
| 130 |
+
with pytest.raises(ValueError, match=msg):
|
| 131 |
+
df.dropna(axis=3)
|
| 132 |
+
|
| 133 |
+
@pytest.mark.filterwarnings(
|
| 134 |
+
"ignore:The inplace keyword in (Series|DataFrame).dropna"
|
| 135 |
+
)
|
| 136 |
+
@pytest.mark.filterwarnings(
|
| 137 |
+
"ignore:The inplace keyword in (Series|DataFrame).drop is"
|
| 138 |
+
)
|
| 139 |
+
def test_drop_and_dropna_caching(self):
|
| 140 |
+
# tst that cacher updates
|
| 141 |
+
original = pd.Series([1, 2, np.nan], name="A")
|
| 142 |
+
expected = pd.Series([1, 2], dtype=original.dtype, name="A")
|
| 143 |
+
df = pd.DataFrame({"A": original.values.copy()})
|
| 144 |
+
df2 = df.copy()
|
| 145 |
+
df["A"].dropna()
|
| 146 |
+
tm.assert_series_equal(df["A"], original)
|
| 147 |
+
|
| 148 |
+
ser = df["A"]
|
| 149 |
+
return_value = ser.dropna(inplace=True)
|
| 150 |
+
tm.assert_series_equal(ser, expected)
|
| 151 |
+
tm.assert_series_equal(df["A"], original)
|
| 152 |
+
assert return_value is None
|
| 153 |
+
|
| 154 |
+
df2["A"].drop([1])
|
| 155 |
+
tm.assert_series_equal(df2["A"], original)
|
| 156 |
+
|
| 157 |
+
ser = df2["A"]
|
| 158 |
+
return_value = ser.drop([1], inplace=True)
|
| 159 |
+
tm.assert_series_equal(ser, original.drop([1]))
|
| 160 |
+
tm.assert_series_equal(df2["A"], original)
|
| 161 |
+
assert return_value is None
|
| 162 |
+
|
| 163 |
+
def test_dropna_corner(self, float_frame):
|
| 164 |
+
# bad input
|
| 165 |
+
msg = "invalid how option: foo"
|
| 166 |
+
with pytest.raises(ValueError, match=msg):
|
| 167 |
+
float_frame.dropna(how="foo")
|
| 168 |
+
# non-existent column - 8303
|
| 169 |
+
with pytest.raises(KeyError, match=r"^\['X'\]$"):
|
| 170 |
+
float_frame.dropna(subset=["A", "X"])
|
| 171 |
+
|
| 172 |
+
@pytest.mark.filterwarnings("ignore:The inplace keyword in DataFrame.dropna")
|
| 173 |
+
def test_dropna_multiple_axes(self):
|
| 174 |
+
df = pd.DataFrame(
|
| 175 |
+
[
|
| 176 |
+
[1, np.nan, 2, 3],
|
| 177 |
+
[4, np.nan, 5, 6],
|
| 178 |
+
[np.nan, np.nan, np.nan, np.nan],
|
| 179 |
+
[7, np.nan, 8, 9],
|
| 180 |
+
]
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
# GH20987
|
| 184 |
+
with pytest.raises(TypeError, match="supplying multiple axes"):
|
| 185 |
+
df.dropna(how="all", axis=[0, 1])
|
| 186 |
+
with pytest.raises(TypeError, match="supplying multiple axes"):
|
| 187 |
+
df.dropna(how="all", axis=(0, 1))
|
| 188 |
+
|
| 189 |
+
inp = df.copy()
|
| 190 |
+
with pytest.raises(TypeError, match="supplying multiple axes"):
|
| 191 |
+
inp.dropna(how="all", axis=(0, 1), inplace=True)
|
| 192 |
+
|
| 193 |
+
def test_dropna_tz_aware_datetime(self):
|
| 194 |
+
# GH13407
|
| 195 |
+
df = pd.DataFrame()
|
| 196 |
+
dt1 = datetime.datetime(2015, 1, 1, tzinfo=dateutil.tz.tzutc())
|
| 197 |
+
dt2 = datetime.datetime(2015, 2, 2, tzinfo=dateutil.tz.tzutc())
|
| 198 |
+
df["Time"] = [dt1]
|
| 199 |
+
result = df.dropna(axis=0)
|
| 200 |
+
expected = pd.DataFrame({"Time": [dt1]})
|
| 201 |
+
tm.assert_frame_equal(result, expected)
|
| 202 |
+
|
| 203 |
+
# Ex2
|
| 204 |
+
df = pd.DataFrame({"Time": [dt1, None, np.nan, dt2]})
|
| 205 |
+
result = df.dropna(axis=0)
|
| 206 |
+
expected = pd.DataFrame([dt1, dt2], columns=["Time"], index=range(0, 6, 3))
|
| 207 |
+
tm.assert_frame_equal(result, expected)
|
| 208 |
+
|
| 209 |
+
def test_dropna_categorical_interval_index(self):
|
| 210 |
+
# GH 25087
|
| 211 |
+
ii = pd.IntervalIndex.from_breaks([0, 2.78, 3.14, 6.28])
|
| 212 |
+
ci = pd.CategoricalIndex(ii)
|
| 213 |
+
df = pd.DataFrame({"A": list("abc")}, index=ci)
|
| 214 |
+
|
| 215 |
+
expected = df
|
| 216 |
+
result = df.dropna()
|
| 217 |
+
tm.assert_frame_equal(result, expected)
|
| 218 |
+
|
| 219 |
+
def test_dropna_with_duplicate_columns(self):
|
| 220 |
+
df = pd.DataFrame(
|
| 221 |
+
{
|
| 222 |
+
"A": np.random.default_rng(2).standard_normal(5),
|
| 223 |
+
"B": np.random.default_rng(2).standard_normal(5),
|
| 224 |
+
"C": np.random.default_rng(2).standard_normal(5),
|
| 225 |
+
"D": ["a", "b", "c", "d", "e"],
|
| 226 |
+
}
|
| 227 |
+
)
|
| 228 |
+
df.iloc[2, [0, 1, 2]] = np.nan
|
| 229 |
+
df.iloc[0, 0] = np.nan
|
| 230 |
+
df.iloc[1, 1] = np.nan
|
| 231 |
+
df.iloc[:, 3] = np.nan
|
| 232 |
+
expected = df.dropna(subset=["A", "B", "C"], how="all")
|
| 233 |
+
expected.columns = ["A", "A", "B", "C"]
|
| 234 |
+
|
| 235 |
+
df.columns = ["A", "A", "B", "C"]
|
| 236 |
+
|
| 237 |
+
result = df.dropna(subset=["A", "C"], how="all")
|
| 238 |
+
tm.assert_frame_equal(result, expected)
|
| 239 |
+
|
| 240 |
+
def test_set_single_column_subset(self):
|
| 241 |
+
# GH 41021
|
| 242 |
+
df = pd.DataFrame({"A": [1, 2, 3], "B": list("abc"), "C": [4, np.nan, 5]})
|
| 243 |
+
expected = pd.DataFrame(
|
| 244 |
+
{"A": [1, 3], "B": list("ac"), "C": [4.0, 5.0]}, index=range(0, 4, 2)
|
| 245 |
+
)
|
| 246 |
+
result = df.dropna(subset="C")
|
| 247 |
+
tm.assert_frame_equal(result, expected)
|
| 248 |
+
|
| 249 |
+
def test_single_column_not_present_in_axis(self):
|
| 250 |
+
# GH 41021
|
| 251 |
+
df = pd.DataFrame({"A": [1, 2, 3]})
|
| 252 |
+
|
| 253 |
+
# Column not present
|
| 254 |
+
with pytest.raises(KeyError, match="['D']"):
|
| 255 |
+
df.dropna(subset="D", axis=0)
|
| 256 |
+
|
| 257 |
+
def test_subset_is_nparray(self):
|
| 258 |
+
# GH 41021
|
| 259 |
+
df = pd.DataFrame({"A": [1, 2, np.nan], "B": list("abc"), "C": [4, np.nan, 5]})
|
| 260 |
+
expected = pd.DataFrame({"A": [1.0], "B": ["a"], "C": [4.0]})
|
| 261 |
+
result = df.dropna(subset=np.array(["A", "C"]))
|
| 262 |
+
tm.assert_frame_equal(result, expected)
|
| 263 |
+
|
| 264 |
+
def test_no_nans_in_frame(self, axis):
|
| 265 |
+
# GH#41965
|
| 266 |
+
df = pd.DataFrame([[1, 2], [3, 4]], columns=pd.RangeIndex(0, 2))
|
| 267 |
+
expected = df.copy()
|
| 268 |
+
result = df.dropna(axis=axis)
|
| 269 |
+
tm.assert_frame_equal(result, expected, check_index_type=True)
|
| 270 |
+
|
| 271 |
+
def test_how_thresh_param_incompatible(self):
|
| 272 |
+
# GH46575
|
| 273 |
+
df = pd.DataFrame([1, 2, pd.NA])
|
| 274 |
+
msg = "You cannot set both the how and thresh arguments at the same time"
|
| 275 |
+
with pytest.raises(TypeError, match=msg):
|
| 276 |
+
df.dropna(how="all", thresh=2)
|
| 277 |
+
|
| 278 |
+
with pytest.raises(TypeError, match=msg):
|
| 279 |
+
df.dropna(how="any", thresh=2)
|
| 280 |
+
|
| 281 |
+
with pytest.raises(TypeError, match=msg):
|
| 282 |
+
df.dropna(how=None, thresh=None)
|
| 283 |
+
|
| 284 |
+
@pytest.mark.filterwarnings("ignore:The inplace keyword in DataFrame.dropna")
|
| 285 |
+
@pytest.mark.parametrize("val", [1, 1.5])
|
| 286 |
+
def test_dropna_ignore_index(self, val):
|
| 287 |
+
# GH#31725
|
| 288 |
+
df = pd.DataFrame({"a": [1, 2, val]}, index=[3, 2, 1])
|
| 289 |
+
result = df.dropna(ignore_index=True)
|
| 290 |
+
expected = pd.DataFrame({"a": [1, 2, val]})
|
| 291 |
+
tm.assert_frame_equal(result, expected)
|
| 292 |
+
|
| 293 |
+
df.dropna(ignore_index=True, inplace=True)
|
| 294 |
+
tm.assert_frame_equal(df, expected)
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
def test_dropna_inplace_depr():
|
| 298 |
+
msg = "The inplace keyword in DataFrame.dropna is deprecated"
|
| 299 |
+
|
| 300 |
+
df = pd.DataFrame({"a": [1.0, 1.5, np.nan, 2.0]})
|
| 301 |
+
df_orig = df.copy()
|
| 302 |
+
expected = pd.DataFrame({"a": [1.0, 1.5, 2.0]}, index=[0, 1, 3])
|
| 303 |
+
|
| 304 |
+
# does not use keyword, no warning
|
| 305 |
+
with tm.assert_produces_warning(False):
|
| 306 |
+
result = df.dropna()
|
| 307 |
+
tm.assert_frame_equal(result, expected)
|
| 308 |
+
tm.assert_frame_equal(df, df_orig)
|
| 309 |
+
|
| 310 |
+
# uses keyword, set to false, warning
|
| 311 |
+
with tm.assert_produces_warning(Pandas4Warning, match=msg):
|
| 312 |
+
result = df.dropna(inplace=False)
|
| 313 |
+
tm.assert_frame_equal(result, expected)
|
| 314 |
+
tm.assert_frame_equal(df, df_orig)
|
| 315 |
+
|
| 316 |
+
# uses keyword, set to true, warning
|
| 317 |
+
with tm.assert_produces_warning(Pandas4Warning, match=msg):
|
| 318 |
+
df.dropna(inplace=True)
|
| 319 |
+
tm.assert_frame_equal(df, expected)
|
venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_dtypes.py
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from datetime import timedelta
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
from pandas.core.dtypes.dtypes import DatetimeTZDtype
|
| 7 |
+
|
| 8 |
+
import pandas as pd
|
| 9 |
+
import pandas._testing as tm
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class TestDataFrameDataTypes:
|
| 13 |
+
def test_empty_frame_dtypes(self):
|
| 14 |
+
empty_df = pd.DataFrame()
|
| 15 |
+
tm.assert_series_equal(empty_df.dtypes, pd.Series(dtype=object))
|
| 16 |
+
|
| 17 |
+
nocols_df = pd.DataFrame(index=[1, 2, 3])
|
| 18 |
+
tm.assert_series_equal(nocols_df.dtypes, pd.Series(dtype=object))
|
| 19 |
+
|
| 20 |
+
norows_df = pd.DataFrame(columns=list("abc"))
|
| 21 |
+
tm.assert_series_equal(norows_df.dtypes, pd.Series(object, index=list("abc")))
|
| 22 |
+
|
| 23 |
+
norows_int_df = pd.DataFrame(columns=list("abc")).astype(np.int32)
|
| 24 |
+
tm.assert_series_equal(
|
| 25 |
+
norows_int_df.dtypes, pd.Series(np.dtype("int32"), index=list("abc"))
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
df = pd.DataFrame({"a": 1, "b": True, "c": 1.0}, index=[1, 2, 3])
|
| 29 |
+
ex_dtypes = pd.Series({"a": np.int64, "b": np.bool_, "c": np.float64})
|
| 30 |
+
tm.assert_series_equal(df.dtypes, ex_dtypes)
|
| 31 |
+
|
| 32 |
+
# same but for empty slice of df
|
| 33 |
+
tm.assert_series_equal(df[:0].dtypes, ex_dtypes)
|
| 34 |
+
|
| 35 |
+
def test_datetime_with_tz_dtypes(self):
|
| 36 |
+
tzframe = pd.DataFrame(
|
| 37 |
+
{
|
| 38 |
+
"A": pd.date_range("20130101", periods=3, unit="ns"),
|
| 39 |
+
"B": pd.date_range("20130101", periods=3, tz="US/Eastern", unit="ns"),
|
| 40 |
+
"C": pd.date_range("20130101", periods=3, tz="CET", unit="ns"),
|
| 41 |
+
}
|
| 42 |
+
)
|
| 43 |
+
tzframe.iloc[1, 1] = pd.NaT
|
| 44 |
+
tzframe.iloc[1, 2] = pd.NaT
|
| 45 |
+
result = tzframe.dtypes.sort_index()
|
| 46 |
+
expected = pd.Series(
|
| 47 |
+
[
|
| 48 |
+
np.dtype("datetime64[ns]"),
|
| 49 |
+
DatetimeTZDtype("ns", "US/Eastern"),
|
| 50 |
+
DatetimeTZDtype("ns", "CET"),
|
| 51 |
+
],
|
| 52 |
+
["A", "B", "C"],
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
tm.assert_series_equal(result, expected)
|
| 56 |
+
|
| 57 |
+
def test_dtypes_are_correct_after_column_slice(self):
|
| 58 |
+
# GH6525
|
| 59 |
+
df = pd.DataFrame(index=range(5), columns=list("abc"), dtype=np.float64)
|
| 60 |
+
tm.assert_series_equal(
|
| 61 |
+
df.dtypes,
|
| 62 |
+
pd.Series({"a": np.float64, "b": np.float64, "c": np.float64}),
|
| 63 |
+
)
|
| 64 |
+
tm.assert_series_equal(df.iloc[:, 2:].dtypes, pd.Series({"c": np.float64}))
|
| 65 |
+
tm.assert_series_equal(
|
| 66 |
+
df.dtypes,
|
| 67 |
+
pd.Series({"a": np.float64, "b": np.float64, "c": np.float64}),
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
@pytest.mark.parametrize(
|
| 71 |
+
"data",
|
| 72 |
+
[pd.NA, True],
|
| 73 |
+
)
|
| 74 |
+
def test_dtypes_are_correct_after_groupby_last(self, data):
|
| 75 |
+
# GH46409
|
| 76 |
+
df = pd.DataFrame(
|
| 77 |
+
{"id": [1, 2, 3, 4], "test": [True, pd.NA, data, False]}
|
| 78 |
+
).convert_dtypes()
|
| 79 |
+
result = df.groupby("id").last().test
|
| 80 |
+
expected = df.set_index("id").test
|
| 81 |
+
assert result.dtype == pd.BooleanDtype()
|
| 82 |
+
tm.assert_series_equal(expected, result)
|
| 83 |
+
|
| 84 |
+
def test_dtypes_gh8722(self, float_string_frame):
|
| 85 |
+
float_string_frame["bool"] = float_string_frame["A"] > 0
|
| 86 |
+
result = float_string_frame.dtypes
|
| 87 |
+
expected = pd.Series(
|
| 88 |
+
{k: v.dtype for k, v in float_string_frame.items()}, index=result.index
|
| 89 |
+
)
|
| 90 |
+
tm.assert_series_equal(result, expected)
|
| 91 |
+
|
| 92 |
+
def test_dtypes_timedeltas(self):
|
| 93 |
+
df = pd.DataFrame(
|
| 94 |
+
{
|
| 95 |
+
"A": pd.Series(
|
| 96 |
+
pd.date_range("2012-1-1", periods=3, freq="D", unit="ns")
|
| 97 |
+
),
|
| 98 |
+
"B": pd.Series([timedelta(days=i) for i in range(3)]),
|
| 99 |
+
}
|
| 100 |
+
)
|
| 101 |
+
result = df.dtypes
|
| 102 |
+
expected = pd.Series(
|
| 103 |
+
[np.dtype("datetime64[ns]"), np.dtype("timedelta64[us]")], index=list("AB")
|
| 104 |
+
)
|
| 105 |
+
tm.assert_series_equal(result, expected)
|
| 106 |
+
|
| 107 |
+
df["C"] = df["A"] + df["B"]
|
| 108 |
+
result = df.dtypes
|
| 109 |
+
expected = pd.Series(
|
| 110 |
+
[
|
| 111 |
+
np.dtype("datetime64[ns]"),
|
| 112 |
+
np.dtype("timedelta64[us]"),
|
| 113 |
+
np.dtype("datetime64[ns]"),
|
| 114 |
+
],
|
| 115 |
+
index=list("ABC"),
|
| 116 |
+
)
|
| 117 |
+
tm.assert_series_equal(result, expected)
|
| 118 |
+
|
| 119 |
+
# mixed int types
|
| 120 |
+
df["D"] = 1
|
| 121 |
+
result = df.dtypes
|
| 122 |
+
expected = pd.Series(
|
| 123 |
+
[
|
| 124 |
+
np.dtype("datetime64[ns]"),
|
| 125 |
+
np.dtype("timedelta64[us]"),
|
| 126 |
+
np.dtype("datetime64[ns]"),
|
| 127 |
+
np.dtype("int64"),
|
| 128 |
+
],
|
| 129 |
+
index=list("ABCD"),
|
| 130 |
+
)
|
| 131 |
+
tm.assert_series_equal(result, expected)
|
| 132 |
+
|
| 133 |
+
def test_frame_apply_np_array_return_type(self, using_infer_string):
|
| 134 |
+
# GH 35517
|
| 135 |
+
df = pd.DataFrame([["foo"]])
|
| 136 |
+
result = df.apply(lambda col: np.array("bar"))
|
| 137 |
+
expected = pd.Series(np.array("bar"))
|
| 138 |
+
tm.assert_series_equal(result, expected)
|
venv/lib/python3.14/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
| 8 |
+
import pandas._testing as tm
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
@pytest.mark.parametrize("subset", ["a", ["a"], ["a", "B"]])
|
| 12 |
+
def test_duplicated_with_misspelled_column_name(subset):
|
| 13 |
+
# GH 19730
|
| 14 |
+
df = pd.DataFrame({"A": [0, 0, 1], "B": [0, 0, 1], "C": [0, 0, 1]})
|
| 15 |
+
msg = re.escape("Index(['a'], dtype=")
|
| 16 |
+
|
| 17 |
+
with pytest.raises(KeyError, match=msg):
|
| 18 |
+
df.duplicated(subset)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def test_duplicated_implemented_no_recursion():
|
| 22 |
+
# gh-21524
|
| 23 |
+
# Ensure duplicated isn't implemented using recursion that
|
| 24 |
+
# can fail on wide frames
|
| 25 |
+
df = pd.DataFrame(np.random.default_rng(2).integers(0, 1000, (10, 1000)))
|
| 26 |
+
rec_limit = sys.getrecursionlimit()
|
| 27 |
+
try:
|
| 28 |
+
sys.setrecursionlimit(100)
|
| 29 |
+
result = df.duplicated()
|
| 30 |
+
finally:
|
| 31 |
+
sys.setrecursionlimit(rec_limit)
|
| 32 |
+
|
| 33 |
+
# Then duplicates produce the bool Series as a result and don't fail during
|
| 34 |
+
# calculation. Actual values doesn't matter here, though usually it's all
|
| 35 |
+
# False in this case
|
| 36 |
+
assert isinstance(result, pd.Series)
|
| 37 |
+
assert result.dtype == np.bool_
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
@pytest.mark.parametrize(
|
| 41 |
+
"keep, expected",
|
| 42 |
+
[
|
| 43 |
+
("first", pd.Series([False, False, True, False, True])),
|
| 44 |
+
("last", pd.Series([True, True, False, False, False])),
|
| 45 |
+
(False, pd.Series([True, True, True, False, True])),
|
| 46 |
+
],
|
| 47 |
+
)
|
| 48 |
+
def test_duplicated_keep(keep, expected):
|
| 49 |
+
df = pd.DataFrame({"A": [0, 1, 1, 2, 0], "B": ["a", "b", "b", "c", "a"]})
|
| 50 |
+
|
| 51 |
+
result = df.duplicated(keep=keep)
|
| 52 |
+
tm.assert_series_equal(result, expected)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
@pytest.mark.xfail(reason="GH#21720; nan/None falsely considered equal")
|
| 56 |
+
@pytest.mark.parametrize(
|
| 57 |
+
"keep, expected",
|
| 58 |
+
[
|
| 59 |
+
("first", pd.Series([False, False, True, False, True])),
|
| 60 |
+
("last", pd.Series([True, True, False, False, False])),
|
| 61 |
+
(False, pd.Series([True, True, True, False, True])),
|
| 62 |
+
],
|
| 63 |
+
)
|
| 64 |
+
def test_duplicated_nan_none(keep, expected):
|
| 65 |
+
df = pd.DataFrame({"C": [np.nan, 3, 3, None, np.nan], "x": 1}, dtype=object)
|
| 66 |
+
|
| 67 |
+
result = df.duplicated(keep=keep)
|
| 68 |
+
tm.assert_series_equal(result, expected)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
@pytest.mark.parametrize("subset", [None, ["A", "B"], "A"])
|
| 72 |
+
def test_duplicated_subset(subset, keep):
|
| 73 |
+
df = pd.DataFrame(
|
| 74 |
+
{
|
| 75 |
+
"A": [0, 1, 1, 2, 0],
|
| 76 |
+
"B": ["a", "b", "b", "c", "a"],
|
| 77 |
+
"C": [np.nan, 3, 3, None, np.nan],
|
| 78 |
+
}
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
if subset is None:
|
| 82 |
+
subset = list(df.columns)
|
| 83 |
+
elif isinstance(subset, str):
|
| 84 |
+
# need to have a DataFrame, not a Series
|
| 85 |
+
# -> select columns with singleton list, not string
|
| 86 |
+
subset = [subset]
|
| 87 |
+
|
| 88 |
+
expected = df[subset].duplicated(keep=keep)
|
| 89 |
+
result = df.duplicated(keep=keep, subset=subset)
|
| 90 |
+
tm.assert_series_equal(result, expected)
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def test_duplicated_on_empty_frame():
|
| 94 |
+
# GH 25184
|
| 95 |
+
|
| 96 |
+
df = pd.DataFrame(columns=["a", "b"])
|
| 97 |
+
dupes = df.duplicated("a")
|
| 98 |
+
|
| 99 |
+
result = df[dupes]
|
| 100 |
+
expected = df.copy()
|
| 101 |
+
tm.assert_frame_equal(result, expected)
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def test_duplicated_on_empty_frame_with_index():
|
| 105 |
+
# GH#61191
|
| 106 |
+
df = pd.DataFrame(index=[0, 1])
|
| 107 |
+
result = df.duplicated()
|
| 108 |
+
expected = pd.Series(False, dtype=bool, index=df.index)
|
| 109 |
+
tm.assert_series_equal(result, expected)
|
| 110 |
+
|
| 111 |
+
# Boolean indexing with the result should work
|
| 112 |
+
result = df[df.duplicated()]
|
| 113 |
+
expected = df.iloc[:0]
|
| 114 |
+
tm.assert_frame_equal(result, expected)
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def test_frame_datetime64_duplicated():
|
| 118 |
+
dates = pd.date_range("2010-07-01", end="2010-08-05")
|
| 119 |
+
|
| 120 |
+
tst = pd.DataFrame({"symbol": "AAA", "date": dates})
|
| 121 |
+
result = tst.duplicated(["date", "symbol"])
|
| 122 |
+
assert (-result).all()
|
| 123 |
+
|
| 124 |
+
tst = pd.DataFrame({"date": dates})
|
| 125 |
+
result = tst.date.duplicated()
|
| 126 |
+
assert (-result).all()
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
@pytest.mark.parametrize(
|
| 130 |
+
"values",
|
| 131 |
+
[
|
| 132 |
+
pd.to_datetime(["2020-01-01", "2020-01-01", None]).tz_localize("UTC"),
|
| 133 |
+
pd.PeriodIndex(["2020-01-01", "2020-01-01", None], freq="D"),
|
| 134 |
+
pd.arrays.IntervalArray.from_tuples([(0.0, 1.0), (0.0, 1.0), None]),
|
| 135 |
+
],
|
| 136 |
+
)
|
| 137 |
+
def test_duplicated_no_values_deprecation(values):
|
| 138 |
+
# GH#69025 the multi-column path must not self-trigger the .values deprecation
|
| 139 |
+
df = pd.DataFrame({"a": values, "b": [1, 1, 1]})
|
| 140 |
+
with tm.assert_produces_warning(None):
|
| 141 |
+
result = df.duplicated()
|
| 142 |
+
dropped = df.drop_duplicates()
|
| 143 |
+
|
| 144 |
+
tm.assert_series_equal(result, pd.Series([False, True, False]))
|
| 145 |
+
tm.assert_frame_equal(dropped, df.iloc[[0, 2]])
|
venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_equals.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import pandas._testing as tm
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class TestEquals:
|
| 8 |
+
def test_dataframe_not_equal(self):
|
| 9 |
+
# see GH#28839
|
| 10 |
+
df1 = pd.DataFrame({"a": [1, 2], "b": ["s", "d"]})
|
| 11 |
+
df2 = pd.DataFrame({"a": ["s", "d"], "b": [1, 2]})
|
| 12 |
+
assert df1.equals(df2) is False
|
| 13 |
+
|
| 14 |
+
def test_equals_object_array_vs_scalar(self):
|
| 15 |
+
# GH#43867 one object-dtype element is a numpy array, the other a
|
| 16 |
+
# scalar; these must not compare equal
|
| 17 |
+
df = pd.DataFrame({"x": ["a"]}, dtype=object)
|
| 18 |
+
other = df.copy()
|
| 19 |
+
other["x"] = [np.array(["a"], dtype=object)]
|
| 20 |
+
assert df["x"].dtype == other["x"].dtype == object
|
| 21 |
+
assert not df.equals(other)
|
| 22 |
+
assert not other.equals(df)
|
| 23 |
+
|
| 24 |
+
def test_equals_different_blocks(self):
|
| 25 |
+
# GH#9330
|
| 26 |
+
df0 = pd.DataFrame(
|
| 27 |
+
{"A": [1.0, 2.0], "B": np.array([1, 2], dtype=np.int64), "C": [3.0, 4.0]}
|
| 28 |
+
)
|
| 29 |
+
# build df1 via sequential __setitem__ so the float columns end up
|
| 30 |
+
# in separate blocks instead of being consolidated upfront
|
| 31 |
+
df1 = pd.DataFrame({"A": [1.0, 2.0]})
|
| 32 |
+
df1["B"] = np.array([1, 2], dtype=np.int64)
|
| 33 |
+
df1["C"] = np.array([3.0, 4.0])
|
| 34 |
+
assert len(df0._mgr.blocks) == 2
|
| 35 |
+
assert len(df1._mgr.blocks) == 3
|
| 36 |
+
|
| 37 |
+
# do the real tests
|
| 38 |
+
tm.assert_frame_equal(df0, df1)
|
| 39 |
+
assert df0.equals(df1)
|
| 40 |
+
assert df1.equals(df0)
|
| 41 |
+
|
| 42 |
+
def test_equals(self):
|
| 43 |
+
# Add object dtype column with nans
|
| 44 |
+
index = np.random.default_rng(2).random(10)
|
| 45 |
+
df1 = pd.DataFrame(
|
| 46 |
+
np.random.default_rng(2).random(10), index=index, columns=["floats"]
|
| 47 |
+
)
|
| 48 |
+
df1["text"] = "the sky is so blue. we could use more chocolate.".split()
|
| 49 |
+
df1["start"] = pd.date_range("2000-1-1", periods=10, freq="min")
|
| 50 |
+
df1["end"] = pd.date_range("2000-1-1", periods=10, freq="D")
|
| 51 |
+
df1["diff"] = df1["end"] - df1["start"]
|
| 52 |
+
# Explicitly cast to object, to avoid implicit cast when setting np.nan
|
| 53 |
+
df1["bool"] = (np.arange(10) % 3 == 0).astype(object)
|
| 54 |
+
df1.loc[::2] = np.nan
|
| 55 |
+
df2 = df1.copy()
|
| 56 |
+
assert df1["text"].equals(df2["text"])
|
| 57 |
+
assert df1["start"].equals(df2["start"])
|
| 58 |
+
assert df1["end"].equals(df2["end"])
|
| 59 |
+
assert df1["diff"].equals(df2["diff"])
|
| 60 |
+
assert df1["bool"].equals(df2["bool"])
|
| 61 |
+
assert df1.equals(df2)
|
| 62 |
+
assert not df1.equals(object)
|
| 63 |
+
|
| 64 |
+
# different dtype
|
| 65 |
+
different = df1.copy()
|
| 66 |
+
different["floats"] = different["floats"].astype("float32")
|
| 67 |
+
assert not df1.equals(different)
|
| 68 |
+
|
| 69 |
+
# different index
|
| 70 |
+
different_index = -index
|
| 71 |
+
different = df2.set_index(different_index)
|
| 72 |
+
assert not df1.equals(different)
|
| 73 |
+
|
| 74 |
+
# different columns
|
| 75 |
+
different = df2.copy()
|
| 76 |
+
different.columns = df2.columns[::-1]
|
| 77 |
+
assert not df1.equals(different)
|
| 78 |
+
|
| 79 |
+
# DatetimeIndex
|
| 80 |
+
index = pd.date_range("2000-1-1", periods=10, freq="min")
|
| 81 |
+
df1 = df1.set_index(index)
|
| 82 |
+
df2 = df1.copy()
|
| 83 |
+
assert df1.equals(df2)
|
| 84 |
+
|
| 85 |
+
# MultiIndex
|
| 86 |
+
df3 = df1.set_index(["text"], append=True)
|
| 87 |
+
df2 = df1.set_index(["text"], append=True)
|
| 88 |
+
assert df3.equals(df2)
|
| 89 |
+
|
| 90 |
+
df2 = df1.set_index(["floats"], append=True)
|
| 91 |
+
assert not df3.equals(df2)
|
| 92 |
+
|
| 93 |
+
# NaN in index
|
| 94 |
+
df3 = df1.set_index(["floats"], append=True)
|
| 95 |
+
df2 = df1.set_index(["floats"], append=True)
|
| 96 |
+
assert df3.equals(df2)
|
| 97 |
+
|
| 98 |
+
def test_equals_categorical_categories_order(self):
|
| 99 |
+
cat1 = pd.Categorical(["a", "b", "a"], categories=["a", "b"])
|
| 100 |
+
cat2 = pd.Categorical(["a", "b", "a"], categories=["b", "a"])
|
| 101 |
+
df1 = pd.DataFrame({"c": cat1})
|
| 102 |
+
df2 = pd.DataFrame({"c": cat2})
|
| 103 |
+
|
| 104 |
+
assert df1.equals(df2)
|
| 105 |
+
|
| 106 |
+
cat3 = pd.Categorical(["a", "b", "a"], categories=["a", "b", "c"])
|
| 107 |
+
df3 = pd.DataFrame({"c": cat3})
|
| 108 |
+
|
| 109 |
+
assert not df1.equals(df3)
|
venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_explode.py
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
import pandas as pd
|
| 7 |
+
import pandas._testing as tm
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def test_error():
|
| 11 |
+
df = pd.DataFrame(
|
| 12 |
+
{"A": pd.Series([[0, 1, 2], np.nan, [], (3, 4)], index=list("abcd")), "B": 1}
|
| 13 |
+
)
|
| 14 |
+
with pytest.raises(
|
| 15 |
+
ValueError, match="column must be a scalar, tuple, or list thereof"
|
| 16 |
+
):
|
| 17 |
+
df.explode([list("AA")])
|
| 18 |
+
|
| 19 |
+
with pytest.raises(ValueError, match="column must be unique"):
|
| 20 |
+
df.explode(list("AA"))
|
| 21 |
+
|
| 22 |
+
df.columns = list("AA")
|
| 23 |
+
with pytest.raises(
|
| 24 |
+
ValueError,
|
| 25 |
+
match=re.escape("DataFrame columns must be unique. Duplicate columns: ['A']"),
|
| 26 |
+
):
|
| 27 |
+
df.explode("A")
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
@pytest.mark.parametrize(
|
| 31 |
+
"input_subset, error_message",
|
| 32 |
+
[
|
| 33 |
+
(
|
| 34 |
+
list("AC"),
|
| 35 |
+
"columns must have matching element counts",
|
| 36 |
+
),
|
| 37 |
+
(
|
| 38 |
+
[],
|
| 39 |
+
"column must be nonempty",
|
| 40 |
+
),
|
| 41 |
+
],
|
| 42 |
+
)
|
| 43 |
+
def test_error_multi_columns(input_subset, error_message):
|
| 44 |
+
# GH 39240
|
| 45 |
+
df = pd.DataFrame(
|
| 46 |
+
{
|
| 47 |
+
"A": [[0, 1, 2], np.nan, [], (3, 4)],
|
| 48 |
+
"B": 1,
|
| 49 |
+
"C": [["a", "b", "c"], "foo", [], ["d", "e", "f"]],
|
| 50 |
+
},
|
| 51 |
+
index=list("abcd"),
|
| 52 |
+
)
|
| 53 |
+
with pytest.raises(ValueError, match=error_message):
|
| 54 |
+
df.explode(input_subset)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
@pytest.mark.parametrize(
|
| 58 |
+
"scalar",
|
| 59 |
+
["a", 0, 1.5, pd.Timedelta("1 days"), pd.Timestamp("2019-12-31")],
|
| 60 |
+
)
|
| 61 |
+
def test_basic(scalar):
|
| 62 |
+
df = pd.DataFrame(
|
| 63 |
+
{scalar: pd.Series([[0, 1, 2], np.nan, [], (3, 4)], index=list("abcd")), "B": 1}
|
| 64 |
+
)
|
| 65 |
+
result = df.explode(scalar)
|
| 66 |
+
expected = pd.DataFrame(
|
| 67 |
+
{
|
| 68 |
+
scalar: pd.Series(
|
| 69 |
+
[0, 1, 2, np.nan, np.nan, 3, 4], index=list("aaabcdd"), dtype=object
|
| 70 |
+
),
|
| 71 |
+
"B": 1,
|
| 72 |
+
}
|
| 73 |
+
)
|
| 74 |
+
tm.assert_frame_equal(result, expected)
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def test_multi_index_rows():
|
| 78 |
+
df = pd.DataFrame(
|
| 79 |
+
{"A": np.array([[0, 1, 2], np.nan, [], (3, 4)], dtype=object), "B": 1},
|
| 80 |
+
index=pd.MultiIndex.from_tuples([("a", 1), ("a", 2), ("b", 1), ("b", 2)]),
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
result = df.explode("A")
|
| 84 |
+
expected = pd.DataFrame(
|
| 85 |
+
{
|
| 86 |
+
"A": pd.Series(
|
| 87 |
+
[0, 1, 2, np.nan, np.nan, 3, 4],
|
| 88 |
+
index=pd.MultiIndex.from_tuples(
|
| 89 |
+
[
|
| 90 |
+
("a", 1),
|
| 91 |
+
("a", 1),
|
| 92 |
+
("a", 1),
|
| 93 |
+
("a", 2),
|
| 94 |
+
("b", 1),
|
| 95 |
+
("b", 2),
|
| 96 |
+
("b", 2),
|
| 97 |
+
]
|
| 98 |
+
),
|
| 99 |
+
dtype=object,
|
| 100 |
+
),
|
| 101 |
+
"B": 1,
|
| 102 |
+
}
|
| 103 |
+
)
|
| 104 |
+
tm.assert_frame_equal(result, expected)
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def test_multi_index_columns():
|
| 108 |
+
df = pd.DataFrame(
|
| 109 |
+
{("A", 1): np.array([[0, 1, 2], np.nan, [], (3, 4)], dtype=object), ("A", 2): 1}
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
+
result = df.explode(("A", 1))
|
| 113 |
+
expected = pd.DataFrame(
|
| 114 |
+
{
|
| 115 |
+
("A", 1): pd.Series(
|
| 116 |
+
[0, 1, 2, np.nan, np.nan, 3, 4],
|
| 117 |
+
index=pd.Index([0, 0, 0, 1, 2, 3, 3]),
|
| 118 |
+
dtype=object,
|
| 119 |
+
),
|
| 120 |
+
("A", 2): 1,
|
| 121 |
+
}
|
| 122 |
+
)
|
| 123 |
+
tm.assert_frame_equal(result, expected)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def test_usecase():
|
| 127 |
+
# explode a single column
|
| 128 |
+
# gh-10511
|
| 129 |
+
df = pd.DataFrame(
|
| 130 |
+
[[11, range(5), 10], [22, range(3), 20]], columns=list("ABC")
|
| 131 |
+
).set_index("C")
|
| 132 |
+
result = df.explode("B")
|
| 133 |
+
|
| 134 |
+
expected = pd.DataFrame(
|
| 135 |
+
{
|
| 136 |
+
"A": [11, 11, 11, 11, 11, 22, 22, 22],
|
| 137 |
+
"B": np.array([0, 1, 2, 3, 4, 0, 1, 2], dtype=object),
|
| 138 |
+
"C": [10, 10, 10, 10, 10, 20, 20, 20],
|
| 139 |
+
},
|
| 140 |
+
columns=list("ABC"),
|
| 141 |
+
).set_index("C")
|
| 142 |
+
|
| 143 |
+
tm.assert_frame_equal(result, expected)
|
| 144 |
+
|
| 145 |
+
# gh-8517
|
| 146 |
+
df = pd.DataFrame(
|
| 147 |
+
[["2014-01-01", "Alice", "A B"], ["2014-01-02", "Bob", "C D"]],
|
| 148 |
+
columns=["dt", "name", "text"],
|
| 149 |
+
)
|
| 150 |
+
result = df.assign(text=df.text.str.split(" ")).explode("text")
|
| 151 |
+
expected = pd.DataFrame(
|
| 152 |
+
[
|
| 153 |
+
["2014-01-01", "Alice", "A"],
|
| 154 |
+
["2014-01-01", "Alice", "B"],
|
| 155 |
+
["2014-01-02", "Bob", "C"],
|
| 156 |
+
["2014-01-02", "Bob", "D"],
|
| 157 |
+
],
|
| 158 |
+
columns=["dt", "name", "text"],
|
| 159 |
+
index=[0, 0, 1, 1],
|
| 160 |
+
)
|
| 161 |
+
tm.assert_frame_equal(result, expected)
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
@pytest.mark.parametrize(
|
| 165 |
+
"input_dict, input_index, expected_dict, expected_index",
|
| 166 |
+
[
|
| 167 |
+
(
|
| 168 |
+
{"col1": [[1, 2], [3, 4]], "col2": ["foo", "bar"]},
|
| 169 |
+
[0, 0],
|
| 170 |
+
{"col1": [1, 2, 3, 4], "col2": ["foo", "foo", "bar", "bar"]},
|
| 171 |
+
[0, 0, 0, 0],
|
| 172 |
+
),
|
| 173 |
+
(
|
| 174 |
+
{"col1": [[1, 2], [3, 4]], "col2": ["foo", "bar"]},
|
| 175 |
+
pd.Index([0, 0], name="my_index"),
|
| 176 |
+
{"col1": [1, 2, 3, 4], "col2": ["foo", "foo", "bar", "bar"]},
|
| 177 |
+
pd.Index([0, 0, 0, 0], name="my_index"),
|
| 178 |
+
),
|
| 179 |
+
(
|
| 180 |
+
{"col1": [[1, 2], [3, 4]], "col2": ["foo", "bar"]},
|
| 181 |
+
pd.MultiIndex.from_arrays(
|
| 182 |
+
[[0, 0], [1, 1]], names=["my_first_index", "my_second_index"]
|
| 183 |
+
),
|
| 184 |
+
{"col1": [1, 2, 3, 4], "col2": ["foo", "foo", "bar", "bar"]},
|
| 185 |
+
pd.MultiIndex.from_arrays(
|
| 186 |
+
[[0, 0, 0, 0], [1, 1, 1, 1]],
|
| 187 |
+
names=["my_first_index", "my_second_index"],
|
| 188 |
+
),
|
| 189 |
+
),
|
| 190 |
+
(
|
| 191 |
+
{"col1": [[1, 2], [3, 4]], "col2": ["foo", "bar"]},
|
| 192 |
+
pd.MultiIndex.from_arrays([[0, 0], [1, 1]], names=["my_index", None]),
|
| 193 |
+
{"col1": [1, 2, 3, 4], "col2": ["foo", "foo", "bar", "bar"]},
|
| 194 |
+
pd.MultiIndex.from_arrays(
|
| 195 |
+
[[0, 0, 0, 0], [1, 1, 1, 1]], names=["my_index", None]
|
| 196 |
+
),
|
| 197 |
+
),
|
| 198 |
+
],
|
| 199 |
+
)
|
| 200 |
+
def test_duplicate_index(input_dict, input_index, expected_dict, expected_index):
|
| 201 |
+
# GH 28005
|
| 202 |
+
df = pd.DataFrame(input_dict, index=input_index, dtype=object)
|
| 203 |
+
result = df.explode("col1")
|
| 204 |
+
expected = pd.DataFrame(expected_dict, index=expected_index, dtype=object)
|
| 205 |
+
tm.assert_frame_equal(result, expected)
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
def test_ignore_index():
|
| 209 |
+
# GH 34932
|
| 210 |
+
df = pd.DataFrame({"id": range(0, 20, 10), "values": [list("ab"), list("cd")]})
|
| 211 |
+
result = df.explode("values", ignore_index=True)
|
| 212 |
+
expected = pd.DataFrame(
|
| 213 |
+
{"id": [0, 0, 10, 10], "values": list("abcd")}, index=range(4)
|
| 214 |
+
)
|
| 215 |
+
tm.assert_frame_equal(result, expected)
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
def test_explode_sets():
|
| 219 |
+
# https://github.com/pandas-dev/pandas/issues/35614
|
| 220 |
+
df = pd.DataFrame({"a": [{"x", "y"}], "b": [1]}, index=[1])
|
| 221 |
+
result = df.explode(column="a").sort_values(by="a")
|
| 222 |
+
expected = pd.DataFrame({"a": ["x", "y"], "b": [1, 1]}, index=[1, 1])
|
| 223 |
+
tm.assert_frame_equal(result, expected)
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
@pytest.mark.parametrize(
|
| 227 |
+
"input_subset, expected_dict, expected_index",
|
| 228 |
+
[
|
| 229 |
+
(
|
| 230 |
+
list("AC"),
|
| 231 |
+
{
|
| 232 |
+
"A": pd.Series(
|
| 233 |
+
[0, 1, 2, np.nan, np.nan, 3, 4, np.nan],
|
| 234 |
+
index=list("aaabcdde"),
|
| 235 |
+
dtype=object,
|
| 236 |
+
),
|
| 237 |
+
"B": 1,
|
| 238 |
+
"C": ["a", "b", "c", "foo", np.nan, "d", "e", np.nan],
|
| 239 |
+
},
|
| 240 |
+
list("aaabcdde"),
|
| 241 |
+
),
|
| 242 |
+
(
|
| 243 |
+
list("A"),
|
| 244 |
+
{
|
| 245 |
+
"A": pd.Series(
|
| 246 |
+
[0, 1, 2, np.nan, np.nan, 3, 4, np.nan],
|
| 247 |
+
index=list("aaabcdde"),
|
| 248 |
+
dtype=object,
|
| 249 |
+
),
|
| 250 |
+
"B": 1,
|
| 251 |
+
"C": [
|
| 252 |
+
["a", "b", "c"],
|
| 253 |
+
["a", "b", "c"],
|
| 254 |
+
["a", "b", "c"],
|
| 255 |
+
"foo",
|
| 256 |
+
[],
|
| 257 |
+
["d", "e"],
|
| 258 |
+
["d", "e"],
|
| 259 |
+
np.nan,
|
| 260 |
+
],
|
| 261 |
+
},
|
| 262 |
+
list("aaabcdde"),
|
| 263 |
+
),
|
| 264 |
+
],
|
| 265 |
+
)
|
| 266 |
+
def test_multi_columns(input_subset, expected_dict, expected_index):
|
| 267 |
+
# GH 39240
|
| 268 |
+
df = pd.DataFrame(
|
| 269 |
+
{
|
| 270 |
+
"A": [[0, 1, 2], np.nan, [], (3, 4), np.nan],
|
| 271 |
+
"B": 1,
|
| 272 |
+
"C": [["a", "b", "c"], "foo", [], ["d", "e"], np.nan],
|
| 273 |
+
},
|
| 274 |
+
index=list("abcde"),
|
| 275 |
+
)
|
| 276 |
+
result = df.explode(input_subset)
|
| 277 |
+
expected = pd.DataFrame(expected_dict, expected_index)
|
| 278 |
+
tm.assert_frame_equal(result, expected)
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
def test_multi_columns_nan_empty():
|
| 282 |
+
# GH 46084
|
| 283 |
+
df = pd.DataFrame(
|
| 284 |
+
{
|
| 285 |
+
"A": [[0, 1], [5], [], [2, 3]],
|
| 286 |
+
"B": [9, 8, 7, 6],
|
| 287 |
+
"C": [[1, 2], np.nan, [], [3, 4]],
|
| 288 |
+
}
|
| 289 |
+
)
|
| 290 |
+
result = df.explode(["A", "C"])
|
| 291 |
+
expected = pd.DataFrame(
|
| 292 |
+
{
|
| 293 |
+
"A": np.array([0, 1, 5, np.nan, 2, 3], dtype=object),
|
| 294 |
+
"B": [9, 9, 8, 7, 6, 6],
|
| 295 |
+
"C": np.array([1, 2, np.nan, np.nan, 3, 4], dtype=object),
|
| 296 |
+
},
|
| 297 |
+
index=[0, 0, 1, 2, 3, 3],
|
| 298 |
+
)
|
| 299 |
+
tm.assert_frame_equal(result, expected)
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
def test_str_dtype():
|
| 303 |
+
# https://github.com/pandas-dev/pandas/pull/61623
|
| 304 |
+
df = pd.DataFrame({"a": ["x", "y"]}, dtype="str")
|
| 305 |
+
result = df.explode(column="a")
|
| 306 |
+
assert result is not df
|
| 307 |
+
tm.assert_frame_equal(result, df)
|
venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_fillna.py
ADDED
|
@@ -0,0 +1,935 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import pytest
|
| 3 |
+
|
| 4 |
+
from pandas.errors import (
|
| 5 |
+
InvalidIndexError,
|
| 6 |
+
OutOfBoundsDatetime,
|
| 7 |
+
Pandas4Warning,
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
import pandas as pd
|
| 11 |
+
import pandas._testing as tm
|
| 12 |
+
from pandas.tests.frame.common import _check_mixed_float
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class TestFillNA:
|
| 16 |
+
def test_fillna_dict_inplace_nonunique_columns(self):
|
| 17 |
+
# GH#38966
|
| 18 |
+
df = pd.DataFrame(
|
| 19 |
+
{
|
| 20 |
+
"A": [np.nan] * 3,
|
| 21 |
+
"B": [pd.NaT, pd.Timestamp(1), pd.NaT],
|
| 22 |
+
"C": [np.nan, "foo", 2],
|
| 23 |
+
}
|
| 24 |
+
)
|
| 25 |
+
df.columns = ["A", "A", "A"]
|
| 26 |
+
orig = df[:]
|
| 27 |
+
|
| 28 |
+
# GH#45153 filling datetime with int is deprecated
|
| 29 |
+
with tm.assert_produces_warning(Pandas4Warning, match="fill value"):
|
| 30 |
+
df.fillna({"A": 2}, inplace=True)
|
| 31 |
+
# The first and third columns can be set inplace, while the second cannot.
|
| 32 |
+
|
| 33 |
+
expected = pd.DataFrame(
|
| 34 |
+
{"A": [2.0] * 3, "B": [2, pd.Timestamp(1), 2], "C": [2, "foo", 2]}
|
| 35 |
+
)
|
| 36 |
+
expected.columns = ["A", "A", "A"]
|
| 37 |
+
tm.assert_frame_equal(df, expected)
|
| 38 |
+
assert not tm.shares_memory(df.iloc[:, 1], orig.iloc[:, 1])
|
| 39 |
+
|
| 40 |
+
def test_fillna_on_column_view(self):
|
| 41 |
+
# GH#46149 avoid unnecessary copies
|
| 42 |
+
arr = np.full((40, 50), np.nan)
|
| 43 |
+
df = pd.DataFrame(arr, copy=False)
|
| 44 |
+
|
| 45 |
+
with tm.raises_chained_assignment_error():
|
| 46 |
+
df[0].fillna(-1, inplace=True)
|
| 47 |
+
assert np.isnan(arr[:, 0]).all()
|
| 48 |
+
|
| 49 |
+
# i.e. we didn't create a new 49-column block
|
| 50 |
+
assert len(df._mgr.blocks) == 1
|
| 51 |
+
assert np.shares_memory(df.values, arr)
|
| 52 |
+
|
| 53 |
+
def test_fillna_datetime(self, datetime_frame):
|
| 54 |
+
tf = datetime_frame
|
| 55 |
+
tf.loc[tf.index[:5], "A"] = np.nan
|
| 56 |
+
tf.loc[tf.index[-5:], "A"] = np.nan
|
| 57 |
+
|
| 58 |
+
zero_filled = datetime_frame.fillna(0)
|
| 59 |
+
assert (zero_filled.loc[zero_filled.index[:5], "A"] == 0).all()
|
| 60 |
+
|
| 61 |
+
padded = datetime_frame.ffill()
|
| 62 |
+
assert np.isnan(padded.loc[padded.index[:5], "A"]).all()
|
| 63 |
+
|
| 64 |
+
msg = r"missing 1 required positional argument: 'value'"
|
| 65 |
+
with pytest.raises(TypeError, match=msg):
|
| 66 |
+
datetime_frame.fillna()
|
| 67 |
+
|
| 68 |
+
def test_fillna_mixed_type(self, float_string_frame, using_infer_string):
|
| 69 |
+
mf = float_string_frame
|
| 70 |
+
mf.loc[mf.index[5:20], "foo"] = np.nan
|
| 71 |
+
mf.loc[mf.index[-10:], "A"] = np.nan
|
| 72 |
+
|
| 73 |
+
result = mf.ffill()
|
| 74 |
+
assert (
|
| 75 |
+
result.loc[result.index[-10:], "A"] == result.loc[result.index[-11], "A"]
|
| 76 |
+
).all()
|
| 77 |
+
assert (result.loc[result.index[5:20], "foo"] == "bar").all()
|
| 78 |
+
|
| 79 |
+
# GH#45153 filling string column with int is deprecated
|
| 80 |
+
warn = Pandas4Warning if using_infer_string else None
|
| 81 |
+
with tm.assert_produces_warning(warn, match="fill value"):
|
| 82 |
+
result = mf.fillna(value=0)
|
| 83 |
+
assert (result.loc[result.index[-10:], "A"] == 0).all()
|
| 84 |
+
assert (result.loc[result.index[5:20], "foo"] == 0).all()
|
| 85 |
+
|
| 86 |
+
def test_fillna_mixed_float(self, mixed_float_frame):
|
| 87 |
+
# mixed numeric (but no float16)
|
| 88 |
+
mf = mixed_float_frame.reindex(columns=["A", "B", "D"])
|
| 89 |
+
mf.loc[mf.index[-10:], "A"] = np.nan
|
| 90 |
+
result = mf.fillna(value=0)
|
| 91 |
+
_check_mixed_float(result, dtype={"C": None})
|
| 92 |
+
result = mf.ffill()
|
| 93 |
+
_check_mixed_float(result, dtype={"C": None})
|
| 94 |
+
|
| 95 |
+
def test_fillna_different_dtype(self):
|
| 96 |
+
# with different dtype (GH#3386)
|
| 97 |
+
df = pd.DataFrame(
|
| 98 |
+
[["a", "a", np.nan, "a"], ["b", "b", np.nan, "b"], ["c", "c", np.nan, "c"]]
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
# GH#45153 filling float with string is deprecated
|
| 102 |
+
with tm.assert_produces_warning(Pandas4Warning, match="fill value"):
|
| 103 |
+
result = df.fillna({2: "foo"})
|
| 104 |
+
expected = pd.DataFrame(
|
| 105 |
+
[["a", "a", "foo", "a"], ["b", "b", "foo", "b"], ["c", "c", "foo", "c"]]
|
| 106 |
+
)
|
| 107 |
+
# column is originally float (all-NaN) -> filling with string gives object dtype
|
| 108 |
+
expected[2] = expected[2].astype("object")
|
| 109 |
+
tm.assert_frame_equal(result, expected)
|
| 110 |
+
|
| 111 |
+
with tm.assert_produces_warning(Pandas4Warning, match="fill value"):
|
| 112 |
+
result = df.fillna({2: "foo"}, inplace=True)
|
| 113 |
+
assert result is df
|
| 114 |
+
tm.assert_frame_equal(df, expected)
|
| 115 |
+
|
| 116 |
+
def test_fillna_limit_and_value(self):
|
| 117 |
+
# limit and value
|
| 118 |
+
df = pd.DataFrame(np.random.default_rng(2).standard_normal((10, 3)))
|
| 119 |
+
df.iloc[2:7, 0] = np.nan
|
| 120 |
+
df.iloc[3:5, 2] = np.nan
|
| 121 |
+
|
| 122 |
+
expected = df.copy()
|
| 123 |
+
expected.iloc[2, 0] = 999
|
| 124 |
+
expected.iloc[3, 2] = 999
|
| 125 |
+
result = df.fillna(999, limit=1)
|
| 126 |
+
tm.assert_frame_equal(result, expected)
|
| 127 |
+
|
| 128 |
+
def test_fillna_datelike(self):
|
| 129 |
+
# with datelike
|
| 130 |
+
# GH#6344
|
| 131 |
+
df = pd.DataFrame(
|
| 132 |
+
{
|
| 133 |
+
"Date": [pd.NaT, pd.Timestamp("2014-1-1")],
|
| 134 |
+
"Date2": [pd.Timestamp("2013-1-1"), pd.NaT],
|
| 135 |
+
}
|
| 136 |
+
)
|
| 137 |
+
|
| 138 |
+
expected = df.copy()
|
| 139 |
+
expected["Date"] = expected["Date"].fillna(df.loc[df.index[0], "Date2"])
|
| 140 |
+
result = df.fillna(value={"Date": df["Date2"]})
|
| 141 |
+
tm.assert_frame_equal(result, expected)
|
| 142 |
+
|
| 143 |
+
def test_fillna_tzaware(self):
|
| 144 |
+
# with timezone
|
| 145 |
+
# GH#15855
|
| 146 |
+
df = pd.DataFrame({"A": [pd.Timestamp("2012-11-11 00:00:00+01:00"), pd.NaT]})
|
| 147 |
+
exp = pd.DataFrame(
|
| 148 |
+
{
|
| 149 |
+
"A": [
|
| 150 |
+
pd.Timestamp("2012-11-11 00:00:00+01:00"),
|
| 151 |
+
pd.Timestamp("2012-11-11 00:00:00+01:00"),
|
| 152 |
+
]
|
| 153 |
+
}
|
| 154 |
+
)
|
| 155 |
+
res = df.ffill()
|
| 156 |
+
tm.assert_frame_equal(res, exp)
|
| 157 |
+
|
| 158 |
+
df = pd.DataFrame({"A": [pd.NaT, pd.Timestamp("2012-11-11 00:00:00+01:00")]})
|
| 159 |
+
exp = pd.DataFrame(
|
| 160 |
+
{
|
| 161 |
+
"A": [
|
| 162 |
+
pd.Timestamp("2012-11-11 00:00:00+01:00"),
|
| 163 |
+
pd.Timestamp("2012-11-11 00:00:00+01:00"),
|
| 164 |
+
]
|
| 165 |
+
}
|
| 166 |
+
)
|
| 167 |
+
res = df.bfill()
|
| 168 |
+
tm.assert_frame_equal(res, exp)
|
| 169 |
+
|
| 170 |
+
def test_fillna_tzaware_different_column(self):
|
| 171 |
+
# with timezone in another column
|
| 172 |
+
# GH#15522
|
| 173 |
+
df = pd.DataFrame(
|
| 174 |
+
{
|
| 175 |
+
"A": pd.date_range("20130101", periods=4, tz="US/Eastern"),
|
| 176 |
+
"B": [1, 2, np.nan, np.nan],
|
| 177 |
+
}
|
| 178 |
+
)
|
| 179 |
+
result = df.ffill()
|
| 180 |
+
expected = pd.DataFrame(
|
| 181 |
+
{
|
| 182 |
+
"A": pd.date_range("20130101", periods=4, tz="US/Eastern"),
|
| 183 |
+
"B": [1.0, 2.0, 2.0, 2.0],
|
| 184 |
+
}
|
| 185 |
+
)
|
| 186 |
+
tm.assert_frame_equal(result, expected)
|
| 187 |
+
|
| 188 |
+
def test_na_actions_categorical(self):
|
| 189 |
+
cat = pd.Categorical([1, 2, 3, np.nan], categories=[1, 2, 3])
|
| 190 |
+
vals = ["a", "b", np.nan, "d"]
|
| 191 |
+
df = pd.DataFrame({"cats": cat, "vals": vals})
|
| 192 |
+
cat2 = pd.Categorical([1, 2, 3, 3], categories=[1, 2, 3])
|
| 193 |
+
vals2 = ["a", "b", "b", "d"]
|
| 194 |
+
df_exp_fill = pd.DataFrame({"cats": cat2, "vals": vals2})
|
| 195 |
+
cat3 = pd.Categorical([1, 2, 3], categories=[1, 2, 3])
|
| 196 |
+
vals3 = ["a", "b", np.nan]
|
| 197 |
+
df_exp_drop_cats = pd.DataFrame({"cats": cat3, "vals": vals3})
|
| 198 |
+
cat4 = pd.Categorical([1, 2], categories=[1, 2, 3])
|
| 199 |
+
vals4 = ["a", "b"]
|
| 200 |
+
df_exp_drop_all = pd.DataFrame({"cats": cat4, "vals": vals4})
|
| 201 |
+
|
| 202 |
+
# fillna
|
| 203 |
+
res = df.fillna(value={"cats": 3, "vals": "b"})
|
| 204 |
+
tm.assert_frame_equal(res, df_exp_fill)
|
| 205 |
+
|
| 206 |
+
msg = "Cannot setitem on a Categorical with a new category"
|
| 207 |
+
with pytest.raises(TypeError, match=msg):
|
| 208 |
+
df.fillna(value={"cats": 4, "vals": "c"})
|
| 209 |
+
|
| 210 |
+
res = df.ffill()
|
| 211 |
+
tm.assert_frame_equal(res, df_exp_fill)
|
| 212 |
+
|
| 213 |
+
# dropna
|
| 214 |
+
res = df.dropna(subset=["cats"])
|
| 215 |
+
tm.assert_frame_equal(res, df_exp_drop_cats)
|
| 216 |
+
|
| 217 |
+
res = df.dropna()
|
| 218 |
+
tm.assert_frame_equal(res, df_exp_drop_all)
|
| 219 |
+
|
| 220 |
+
# make sure that fillna takes missing values into account
|
| 221 |
+
c = pd.Categorical([np.nan, "b", np.nan], categories=["a", "b"])
|
| 222 |
+
df = pd.DataFrame({"cats": c, "vals": [1, 2, 3]})
|
| 223 |
+
|
| 224 |
+
cat_exp = pd.Categorical(["a", "b", "a"], categories=["a", "b"])
|
| 225 |
+
df_exp = pd.DataFrame({"cats": cat_exp, "vals": [1, 2, 3]})
|
| 226 |
+
|
| 227 |
+
res = df.fillna("a")
|
| 228 |
+
tm.assert_frame_equal(res, df_exp)
|
| 229 |
+
|
| 230 |
+
def test_fillna_categorical_nan(self):
|
| 231 |
+
# GH#14021
|
| 232 |
+
# np.nan should always be a valid filler
|
| 233 |
+
cat = pd.Categorical([np.nan, 2, np.nan])
|
| 234 |
+
val = pd.Categorical([np.nan, np.nan, np.nan])
|
| 235 |
+
df = pd.DataFrame({"cats": cat, "vals": val})
|
| 236 |
+
|
| 237 |
+
# GH#32950 df.median() is poorly behaved because there is no
|
| 238 |
+
# Categorical.median
|
| 239 |
+
median = pd.Series({"cats": 2.0, "vals": np.nan})
|
| 240 |
+
|
| 241 |
+
res = df.fillna(median)
|
| 242 |
+
v_exp = [np.nan, np.nan, np.nan]
|
| 243 |
+
df_exp = pd.DataFrame({"cats": [2, 2, 2], "vals": v_exp}, dtype="category")
|
| 244 |
+
tm.assert_frame_equal(res, df_exp)
|
| 245 |
+
|
| 246 |
+
result = df.cats.fillna(np.nan)
|
| 247 |
+
tm.assert_series_equal(result, df.cats)
|
| 248 |
+
|
| 249 |
+
result = df.vals.fillna(np.nan)
|
| 250 |
+
tm.assert_series_equal(result, df.vals)
|
| 251 |
+
|
| 252 |
+
idx = pd.DatetimeIndex(
|
| 253 |
+
["2011-01-01 09:00", "2016-01-01 23:45", "2011-01-01 09:00", pd.NaT, pd.NaT]
|
| 254 |
+
)
|
| 255 |
+
df = pd.DataFrame({"a": pd.Categorical(idx)})
|
| 256 |
+
tm.assert_frame_equal(df.fillna(value=pd.NaT), df)
|
| 257 |
+
|
| 258 |
+
idx = pd.PeriodIndex(
|
| 259 |
+
["2011-01", "2011-01", "2011-01", pd.NaT, pd.NaT], freq="M"
|
| 260 |
+
)
|
| 261 |
+
df = pd.DataFrame({"a": pd.Categorical(idx)})
|
| 262 |
+
tm.assert_frame_equal(df.fillna(value=pd.NaT), df)
|
| 263 |
+
|
| 264 |
+
idx = pd.TimedeltaIndex(["1 days", "2 days", "1 days", pd.NaT, pd.NaT])
|
| 265 |
+
df = pd.DataFrame({"a": pd.Categorical(idx)})
|
| 266 |
+
tm.assert_frame_equal(df.fillna(value=pd.NaT), df)
|
| 267 |
+
|
| 268 |
+
def test_fillna_with_categorical_series(self):
|
| 269 |
+
# https://github.com/pandas-dev/pandas/issues/56329
|
| 270 |
+
df = pd.DataFrame(
|
| 271 |
+
{"cats": pd.Categorical(["A", "B", "C"]), "ints": [1.0, 2.0, np.nan]}
|
| 272 |
+
)
|
| 273 |
+
|
| 274 |
+
filler = pd.Series(pd.Categorical([10.0, 20.0, 30.0]))
|
| 275 |
+
result = df.fillna({"ints": filler})
|
| 276 |
+
|
| 277 |
+
expected = pd.DataFrame(
|
| 278 |
+
{"cats": pd.Categorical(["A", "B", "C"]), "ints": [1.0, 2.0, 30.0]}
|
| 279 |
+
)
|
| 280 |
+
tm.assert_frame_equal(result, expected)
|
| 281 |
+
|
| 282 |
+
def test_fillna_no_downcast(self, frame_or_series):
|
| 283 |
+
# GH#45603 preserve object dtype
|
| 284 |
+
obj = frame_or_series([1, 2, 3], dtype="object")
|
| 285 |
+
result = obj.fillna("")
|
| 286 |
+
tm.assert_equal(result, obj)
|
| 287 |
+
|
| 288 |
+
@pytest.mark.parametrize("columns", [["A", "A", "B"], ["A", "A"]])
|
| 289 |
+
def test_fillna_dictlike_value_duplicate_colnames(self, columns):
|
| 290 |
+
# GH#43476
|
| 291 |
+
df = pd.DataFrame(np.nan, index=[0, 1], columns=columns)
|
| 292 |
+
with tm.assert_produces_warning(None):
|
| 293 |
+
result = df.fillna({"A": 0})
|
| 294 |
+
|
| 295 |
+
expected = df.copy()
|
| 296 |
+
expected["A"] = 0.0
|
| 297 |
+
tm.assert_frame_equal(result, expected)
|
| 298 |
+
|
| 299 |
+
def test_fillna_dtype_conversion(self):
|
| 300 |
+
# make sure that fillna on an empty frame works
|
| 301 |
+
df = pd.DataFrame(index=["A", "B", "C"], columns=[1, 2, 3, 4, 5])
|
| 302 |
+
result = df.dtypes
|
| 303 |
+
expected = pd.Series([np.dtype("object")] * 5, index=[1, 2, 3, 4, 5])
|
| 304 |
+
tm.assert_series_equal(result, expected)
|
| 305 |
+
result = df.fillna(1)
|
| 306 |
+
expected = pd.DataFrame(
|
| 307 |
+
1, index=["A", "B", "C"], columns=[1, 2, 3, 4, 5], dtype=object
|
| 308 |
+
)
|
| 309 |
+
tm.assert_frame_equal(result, expected)
|
| 310 |
+
|
| 311 |
+
# empty block
|
| 312 |
+
df = pd.DataFrame(index=range(3), columns=["A", "B"], dtype="float64")
|
| 313 |
+
# GH#45153 filling float with string is deprecated
|
| 314 |
+
with tm.assert_produces_warning(Pandas4Warning, match="fill value"):
|
| 315 |
+
result = df.fillna("nan")
|
| 316 |
+
expected = pd.DataFrame(
|
| 317 |
+
"nan", dtype="object", index=range(3), columns=["A", "B"]
|
| 318 |
+
)
|
| 319 |
+
tm.assert_frame_equal(result, expected)
|
| 320 |
+
|
| 321 |
+
@pytest.mark.parametrize("val", ["", 1, np.nan, 1.0])
|
| 322 |
+
def test_fillna_dtype_conversion_equiv_replace(self, val):
|
| 323 |
+
df = pd.DataFrame({"A": [1, np.nan], "B": [1.0, 2.0]})
|
| 324 |
+
expected = df.replace(np.nan, val)
|
| 325 |
+
# GH#45153 filling with incompatible value is deprecated
|
| 326 |
+
warn = Pandas4Warning if isinstance(val, str) else None
|
| 327 |
+
with tm.assert_produces_warning(warn, match="fill value"):
|
| 328 |
+
result = df.fillna(val)
|
| 329 |
+
tm.assert_frame_equal(result, expected)
|
| 330 |
+
|
| 331 |
+
def test_fillna_datetime_columns(self):
|
| 332 |
+
# GH#7095
|
| 333 |
+
df = pd.DataFrame(
|
| 334 |
+
{
|
| 335 |
+
"A": [-1, -2, np.nan],
|
| 336 |
+
"B": pd.date_range("20130101", periods=3),
|
| 337 |
+
"C": ["foo", "bar", None],
|
| 338 |
+
"D": ["foo2", "bar2", None],
|
| 339 |
+
},
|
| 340 |
+
index=pd.date_range("20130110", periods=3),
|
| 341 |
+
)
|
| 342 |
+
# GH#45153 filling float with string is deprecated
|
| 343 |
+
with tm.assert_produces_warning(Pandas4Warning, match="fill value"):
|
| 344 |
+
result = df.fillna("?")
|
| 345 |
+
expected = pd.DataFrame(
|
| 346 |
+
{
|
| 347 |
+
"A": [-1, -2, "?"],
|
| 348 |
+
"B": pd.date_range("20130101", periods=3),
|
| 349 |
+
"C": ["foo", "bar", "?"],
|
| 350 |
+
"D": ["foo2", "bar2", "?"],
|
| 351 |
+
},
|
| 352 |
+
index=pd.date_range("20130110", periods=3),
|
| 353 |
+
)
|
| 354 |
+
tm.assert_frame_equal(result, expected)
|
| 355 |
+
|
| 356 |
+
df = pd.DataFrame(
|
| 357 |
+
{
|
| 358 |
+
"A": [-1, -2, np.nan],
|
| 359 |
+
"B": [pd.Timestamp("2013-01-01"), pd.Timestamp("2013-01-02"), pd.NaT],
|
| 360 |
+
"C": ["foo", "bar", None],
|
| 361 |
+
"D": ["foo2", "bar2", None],
|
| 362 |
+
},
|
| 363 |
+
index=pd.date_range("20130110", periods=3),
|
| 364 |
+
)
|
| 365 |
+
# GH#45153 filling datetime with string is deprecated
|
| 366 |
+
with tm.assert_produces_warning(Pandas4Warning, match="fill value"):
|
| 367 |
+
result = df.fillna("?")
|
| 368 |
+
expected = pd.DataFrame(
|
| 369 |
+
{
|
| 370 |
+
"A": [-1, -2, "?"],
|
| 371 |
+
"B": [pd.Timestamp("2013-01-01"), pd.Timestamp("2013-01-02"), "?"],
|
| 372 |
+
"C": ["foo", "bar", "?"],
|
| 373 |
+
"D": ["foo2", "bar2", "?"],
|
| 374 |
+
},
|
| 375 |
+
index=pd.date_range("20130110", periods=3),
|
| 376 |
+
)
|
| 377 |
+
tm.assert_frame_equal(result, expected)
|
| 378 |
+
|
| 379 |
+
def test_ffill(self, datetime_frame):
|
| 380 |
+
datetime_frame.loc[datetime_frame.index[:5], "A"] = np.nan
|
| 381 |
+
datetime_frame.loc[datetime_frame.index[-5:], "A"] = np.nan
|
| 382 |
+
|
| 383 |
+
alt = datetime_frame.ffill()
|
| 384 |
+
tm.assert_frame_equal(datetime_frame.ffill(), alt)
|
| 385 |
+
|
| 386 |
+
def test_bfill(self, datetime_frame):
|
| 387 |
+
datetime_frame.loc[datetime_frame.index[:5], "A"] = np.nan
|
| 388 |
+
datetime_frame.loc[datetime_frame.index[-5:], "A"] = np.nan
|
| 389 |
+
|
| 390 |
+
alt = datetime_frame.bfill()
|
| 391 |
+
tm.assert_frame_equal(datetime_frame.bfill(), alt)
|
| 392 |
+
|
| 393 |
+
def test_frame_pad_backfill_limit(self):
|
| 394 |
+
index = np.arange(10)
|
| 395 |
+
df = pd.DataFrame(
|
| 396 |
+
np.random.default_rng(2).standard_normal((10, 4)), index=index
|
| 397 |
+
)
|
| 398 |
+
|
| 399 |
+
result = df[:2].reindex(index, method="pad", limit=5)
|
| 400 |
+
|
| 401 |
+
expected = df[:2].reindex(index).ffill()
|
| 402 |
+
expected.iloc[-3:] = np.nan
|
| 403 |
+
tm.assert_frame_equal(result, expected)
|
| 404 |
+
|
| 405 |
+
result = df[-2:].reindex(index, method="backfill", limit=5)
|
| 406 |
+
|
| 407 |
+
expected = df[-2:].reindex(index).bfill()
|
| 408 |
+
expected.iloc[:3] = np.nan
|
| 409 |
+
tm.assert_frame_equal(result, expected)
|
| 410 |
+
|
| 411 |
+
def test_frame_fillna_limit(self):
|
| 412 |
+
index = np.arange(10)
|
| 413 |
+
df = pd.DataFrame(
|
| 414 |
+
np.random.default_rng(2).standard_normal((10, 4)), index=index
|
| 415 |
+
)
|
| 416 |
+
|
| 417 |
+
result = df[:2].reindex(index)
|
| 418 |
+
result = result.ffill(limit=5)
|
| 419 |
+
|
| 420 |
+
expected = df[:2].reindex(index).ffill()
|
| 421 |
+
expected.iloc[-3:] = np.nan
|
| 422 |
+
tm.assert_frame_equal(result, expected)
|
| 423 |
+
|
| 424 |
+
result = df[-2:].reindex(index)
|
| 425 |
+
result = result.bfill(limit=5)
|
| 426 |
+
|
| 427 |
+
expected = df[-2:].reindex(index).bfill()
|
| 428 |
+
expected.iloc[:3] = np.nan
|
| 429 |
+
tm.assert_frame_equal(result, expected)
|
| 430 |
+
|
| 431 |
+
def test_fillna_skip_certain_blocks(self):
|
| 432 |
+
# don't try to fill boolean, int blocks
|
| 433 |
+
|
| 434 |
+
df = pd.DataFrame(np.random.default_rng(2).standard_normal((10, 4)).astype(int))
|
| 435 |
+
|
| 436 |
+
# it works!
|
| 437 |
+
df.fillna(np.nan)
|
| 438 |
+
|
| 439 |
+
@pytest.mark.parametrize("type", [int, float])
|
| 440 |
+
def test_fillna_positive_limit(self, type):
|
| 441 |
+
df = pd.DataFrame(np.random.default_rng(2).standard_normal((10, 4))).astype(
|
| 442 |
+
type
|
| 443 |
+
)
|
| 444 |
+
|
| 445 |
+
msg = "Limit must be greater than 0"
|
| 446 |
+
with pytest.raises(ValueError, match=msg):
|
| 447 |
+
df.fillna(0, limit=-5)
|
| 448 |
+
|
| 449 |
+
@pytest.mark.parametrize("type", [int, float])
|
| 450 |
+
def test_fillna_integer_limit(self, type):
|
| 451 |
+
df = pd.DataFrame(np.random.default_rng(2).standard_normal((10, 4))).astype(
|
| 452 |
+
type
|
| 453 |
+
)
|
| 454 |
+
|
| 455 |
+
msg = "Limit must be an integer"
|
| 456 |
+
with pytest.raises(ValueError, match=msg):
|
| 457 |
+
df.fillna(0, limit=0.5)
|
| 458 |
+
|
| 459 |
+
def test_fillna_inplace(self):
|
| 460 |
+
df = pd.DataFrame(np.random.default_rng(2).standard_normal((10, 4)))
|
| 461 |
+
df.loc[:4, 1] = np.nan
|
| 462 |
+
df.loc[-4:, 3] = np.nan
|
| 463 |
+
|
| 464 |
+
expected = df.fillna(value=0)
|
| 465 |
+
assert expected is not df
|
| 466 |
+
|
| 467 |
+
result = df.fillna(value=0, inplace=True)
|
| 468 |
+
assert result is df
|
| 469 |
+
tm.assert_frame_equal(df, expected)
|
| 470 |
+
|
| 471 |
+
result = df.fillna(value={0: 0}, inplace=True)
|
| 472 |
+
assert result is df
|
| 473 |
+
|
| 474 |
+
df.loc[:4, 1] = np.nan
|
| 475 |
+
df.loc[-4:, 3] = np.nan
|
| 476 |
+
expected = df.ffill()
|
| 477 |
+
assert expected is not df
|
| 478 |
+
|
| 479 |
+
df.ffill(inplace=True)
|
| 480 |
+
tm.assert_frame_equal(df, expected)
|
| 481 |
+
|
| 482 |
+
def test_fillna_dict_series(self):
|
| 483 |
+
df = pd.DataFrame(
|
| 484 |
+
{
|
| 485 |
+
"a": [np.nan, 1, 2, np.nan, np.nan],
|
| 486 |
+
"b": [1, 2, 3, np.nan, np.nan],
|
| 487 |
+
"c": [np.nan, 1, 2, 3, 4],
|
| 488 |
+
}
|
| 489 |
+
)
|
| 490 |
+
|
| 491 |
+
result = df.fillna({"a": 0, "b": 5})
|
| 492 |
+
|
| 493 |
+
expected = df.copy()
|
| 494 |
+
expected["a"] = expected["a"].fillna(0)
|
| 495 |
+
expected["b"] = expected["b"].fillna(5)
|
| 496 |
+
tm.assert_frame_equal(result, expected)
|
| 497 |
+
|
| 498 |
+
# it works
|
| 499 |
+
result = df.fillna({"a": 0, "b": 5, "d": 7})
|
| 500 |
+
|
| 501 |
+
# Series treated same as dict
|
| 502 |
+
result = df.fillna(df.max())
|
| 503 |
+
expected = df.fillna(df.max().to_dict())
|
| 504 |
+
tm.assert_frame_equal(result, expected)
|
| 505 |
+
|
| 506 |
+
def test_fillna_dict_series_axis_1(self):
|
| 507 |
+
df = pd.DataFrame(
|
| 508 |
+
{
|
| 509 |
+
"a": [np.nan, 1, 2, np.nan, np.nan],
|
| 510 |
+
"b": [1, 2, 3, np.nan, np.nan],
|
| 511 |
+
"c": [np.nan, 1, 2, 3, 4],
|
| 512 |
+
}
|
| 513 |
+
)
|
| 514 |
+
result = df.fillna(df.max(axis=1), axis=1)
|
| 515 |
+
result = df.fillna(df.max(axis=1), axis=1, inplace=True)
|
| 516 |
+
assert result is df
|
| 517 |
+
expected = pd.DataFrame(
|
| 518 |
+
{
|
| 519 |
+
"a": [1.0, 1.0, 2.0, 3.0, 4.0],
|
| 520 |
+
"b": [1.0, 2.0, 3.0, 3.0, 4.0],
|
| 521 |
+
"c": [1.0, 1.0, 2.0, 3.0, 4.0],
|
| 522 |
+
}
|
| 523 |
+
)
|
| 524 |
+
tm.assert_frame_equal(result, expected)
|
| 525 |
+
tm.assert_frame_equal(df, expected)
|
| 526 |
+
|
| 527 |
+
def test_fillna_dict_series_axis_1_mismatch_cols(self):
|
| 528 |
+
df = pd.DataFrame(
|
| 529 |
+
{
|
| 530 |
+
"a": ["abc", "def", np.nan, "ghi", "jkl"],
|
| 531 |
+
"b": [1, 2, 3, np.nan, np.nan],
|
| 532 |
+
"c": [np.nan, 1, 2, 3, 4],
|
| 533 |
+
}
|
| 534 |
+
)
|
| 535 |
+
with pytest.raises(ValueError, match="All columns must have the same dtype"):
|
| 536 |
+
df.fillna(pd.Series({"a": "abc", "b": "def", "c": "hij"}), axis=1)
|
| 537 |
+
|
| 538 |
+
def test_fillna_dict_series_axis_1_value_mismatch_with_cols(self):
|
| 539 |
+
df = pd.DataFrame(
|
| 540 |
+
{
|
| 541 |
+
"a": [np.nan, 1, 2, np.nan, np.nan],
|
| 542 |
+
"b": [1, 2, 3, np.nan, np.nan],
|
| 543 |
+
"c": [np.nan, 1, 2, 3, 4],
|
| 544 |
+
}
|
| 545 |
+
)
|
| 546 |
+
with pytest.raises(ValueError, match=".* not a suitable type to fill into .*"):
|
| 547 |
+
df.fillna(pd.Series({"a": "abc", "b": "def", "c": "hij"}), axis=1)
|
| 548 |
+
|
| 549 |
+
def test_fillna_dataframe(self):
|
| 550 |
+
# GH#8377
|
| 551 |
+
df = pd.DataFrame(
|
| 552 |
+
{
|
| 553 |
+
"a": [np.nan, 1, 2, np.nan, np.nan],
|
| 554 |
+
"b": [1, 2, 3, np.nan, np.nan],
|
| 555 |
+
"c": [np.nan, 1, 2, 3, 4],
|
| 556 |
+
},
|
| 557 |
+
index=list("VWXYZ"),
|
| 558 |
+
)
|
| 559 |
+
|
| 560 |
+
# df2 may have different index and columns
|
| 561 |
+
df2 = pd.DataFrame(
|
| 562 |
+
{
|
| 563 |
+
"a": [np.nan, 10, 20, 30, 40],
|
| 564 |
+
"b": [50, 60, 70, 80, 90],
|
| 565 |
+
"foo": ["bar"] * 5,
|
| 566 |
+
},
|
| 567 |
+
index=list("VWXuZ"),
|
| 568 |
+
)
|
| 569 |
+
|
| 570 |
+
result = df.fillna(df2)
|
| 571 |
+
|
| 572 |
+
# only those columns and indices which are shared get filled
|
| 573 |
+
expected = pd.DataFrame(
|
| 574 |
+
{
|
| 575 |
+
"a": [np.nan, 1, 2, np.nan, 40],
|
| 576 |
+
"b": [1, 2, 3, np.nan, 90],
|
| 577 |
+
"c": [np.nan, 1, 2, 3, 4],
|
| 578 |
+
},
|
| 579 |
+
index=list("VWXYZ"),
|
| 580 |
+
)
|
| 581 |
+
|
| 582 |
+
tm.assert_frame_equal(result, expected)
|
| 583 |
+
|
| 584 |
+
def test_fillna_columns(self):
|
| 585 |
+
arr = np.random.default_rng(2).standard_normal((10, 10))
|
| 586 |
+
arr[:, ::2] = np.nan
|
| 587 |
+
df = pd.DataFrame(arr)
|
| 588 |
+
|
| 589 |
+
result = df.ffill(axis=1)
|
| 590 |
+
expected = df.T.ffill().T
|
| 591 |
+
tm.assert_frame_equal(result, expected)
|
| 592 |
+
|
| 593 |
+
df.insert(6, "foo", 5)
|
| 594 |
+
result = df.ffill(axis=1)
|
| 595 |
+
expected = df.astype(float).ffill(axis=1)
|
| 596 |
+
tm.assert_frame_equal(result, expected)
|
| 597 |
+
|
| 598 |
+
def test_fillna_invalid_value(self, float_frame):
|
| 599 |
+
# list
|
| 600 |
+
msg = '"value" parameter must be a scalar or dict, but you passed a "{}"'
|
| 601 |
+
with pytest.raises(TypeError, match=msg.format("list")):
|
| 602 |
+
float_frame.fillna([1, 2])
|
| 603 |
+
# tuple
|
| 604 |
+
with pytest.raises(TypeError, match=msg.format("tuple")):
|
| 605 |
+
float_frame.fillna((1, 2))
|
| 606 |
+
# frame with series
|
| 607 |
+
msg = (
|
| 608 |
+
'"value" parameter must be a scalar, dict or Series, but you '
|
| 609 |
+
'passed a "DataFrame"'
|
| 610 |
+
)
|
| 611 |
+
with pytest.raises(TypeError, match=msg):
|
| 612 |
+
float_frame.iloc[:, 0].fillna(float_frame)
|
| 613 |
+
|
| 614 |
+
def test_fillna_col_reordering(self):
|
| 615 |
+
cols = ["COL." + str(i) for i in range(5, 0, -1)]
|
| 616 |
+
data = np.random.default_rng(2).random((20, 5))
|
| 617 |
+
df = pd.DataFrame(index=range(20), columns=cols, data=data)
|
| 618 |
+
filled = df.ffill()
|
| 619 |
+
assert df.columns.tolist() == filled.columns.tolist()
|
| 620 |
+
|
| 621 |
+
def test_fill_empty(self, float_frame):
|
| 622 |
+
df = float_frame.reindex(columns=[])
|
| 623 |
+
result = df.fillna(value=0)
|
| 624 |
+
tm.assert_frame_equal(result, df)
|
| 625 |
+
|
| 626 |
+
def test_fillna_with_columns_and_limit(self):
|
| 627 |
+
# GH40989
|
| 628 |
+
df = pd.DataFrame(
|
| 629 |
+
[
|
| 630 |
+
[np.nan, 2, np.nan, 0],
|
| 631 |
+
[3, 4, np.nan, 1],
|
| 632 |
+
[np.nan, np.nan, np.nan, 5],
|
| 633 |
+
[np.nan, 3, np.nan, 4],
|
| 634 |
+
],
|
| 635 |
+
columns=list("ABCD"),
|
| 636 |
+
)
|
| 637 |
+
result = df.fillna(axis=1, value=100, limit=1)
|
| 638 |
+
result2 = df.fillna(axis=1, value=100, limit=2)
|
| 639 |
+
|
| 640 |
+
expected = pd.DataFrame(
|
| 641 |
+
{
|
| 642 |
+
"A": pd.Series([100, 3, 100, 100], dtype="float64"),
|
| 643 |
+
"B": [2, 4, np.nan, 3],
|
| 644 |
+
"C": [np.nan, 100, np.nan, np.nan],
|
| 645 |
+
"D": pd.Series([0, 1, 5, 4], dtype="float64"),
|
| 646 |
+
},
|
| 647 |
+
index=[0, 1, 2, 3],
|
| 648 |
+
)
|
| 649 |
+
expected2 = pd.DataFrame(
|
| 650 |
+
{
|
| 651 |
+
"A": pd.Series([100, 3, 100, 100], dtype="float64"),
|
| 652 |
+
"B": pd.Series([2, 4, 100, 3], dtype="float64"),
|
| 653 |
+
"C": [100, 100, np.nan, 100],
|
| 654 |
+
"D": pd.Series([0, 1, 5, 4], dtype="float64"),
|
| 655 |
+
},
|
| 656 |
+
index=[0, 1, 2, 3],
|
| 657 |
+
)
|
| 658 |
+
|
| 659 |
+
tm.assert_frame_equal(result, expected)
|
| 660 |
+
tm.assert_frame_equal(result2, expected2)
|
| 661 |
+
|
| 662 |
+
def test_fillna_datetime_inplace(self):
|
| 663 |
+
# GH#48863
|
| 664 |
+
df = pd.DataFrame(
|
| 665 |
+
{
|
| 666 |
+
"date1": pd.to_datetime(["2018-05-30", None]),
|
| 667 |
+
"date2": pd.to_datetime(["2018-09-30", None]),
|
| 668 |
+
}
|
| 669 |
+
)
|
| 670 |
+
expected = df.copy()
|
| 671 |
+
df.fillna(np.nan, inplace=True)
|
| 672 |
+
tm.assert_frame_equal(df, expected)
|
| 673 |
+
|
| 674 |
+
def test_fillna_inplace_with_columns_limit_and_value(self):
|
| 675 |
+
# GH40989
|
| 676 |
+
df = pd.DataFrame(
|
| 677 |
+
[
|
| 678 |
+
[np.nan, 2, np.nan, 0],
|
| 679 |
+
[3, 4, np.nan, 1],
|
| 680 |
+
[np.nan, np.nan, np.nan, 5],
|
| 681 |
+
[np.nan, 3, np.nan, 4],
|
| 682 |
+
],
|
| 683 |
+
columns=list("ABCD"),
|
| 684 |
+
)
|
| 685 |
+
|
| 686 |
+
expected = df.fillna(axis=1, value=100, limit=1)
|
| 687 |
+
assert expected is not df
|
| 688 |
+
|
| 689 |
+
result = df.fillna(axis=1, value=100, limit=1, inplace=True)
|
| 690 |
+
assert result is df
|
| 691 |
+
tm.assert_frame_equal(df, expected)
|
| 692 |
+
|
| 693 |
+
@pytest.mark.parametrize("val", [-1, {"x": -1, "y": -1}])
|
| 694 |
+
def test_inplace_dict_update_view(self, val):
|
| 695 |
+
# GH#47188
|
| 696 |
+
df = pd.DataFrame({"x": [np.nan, 2], "y": [np.nan, 2]})
|
| 697 |
+
df_orig = df.copy()
|
| 698 |
+
result_view = df[:]
|
| 699 |
+
df.fillna(val, inplace=True)
|
| 700 |
+
expected = pd.DataFrame({"x": [-1, 2.0], "y": [-1.0, 2]})
|
| 701 |
+
tm.assert_frame_equal(df, expected)
|
| 702 |
+
tm.assert_frame_equal(result_view, df_orig)
|
| 703 |
+
|
| 704 |
+
def test_single_block_df_with_horizontal_axis(self):
|
| 705 |
+
# GH 47713
|
| 706 |
+
df = pd.DataFrame(
|
| 707 |
+
{
|
| 708 |
+
"col1": [5, 0, np.nan, 10, np.nan],
|
| 709 |
+
"col2": [7, np.nan, np.nan, 5, 3],
|
| 710 |
+
"col3": [12, np.nan, 1, 2, 0],
|
| 711 |
+
"col4": [np.nan, 1, 1, np.nan, 18],
|
| 712 |
+
}
|
| 713 |
+
)
|
| 714 |
+
result = df.fillna(50, limit=1, axis=1)
|
| 715 |
+
expected = pd.DataFrame(
|
| 716 |
+
[
|
| 717 |
+
[5.0, 7.0, 12.0, 50.0],
|
| 718 |
+
[0.0, 50.0, np.nan, 1.0],
|
| 719 |
+
[50.0, np.nan, 1.0, 1.0],
|
| 720 |
+
[10.0, 5.0, 2.0, 50.0],
|
| 721 |
+
[50.0, 3.0, 0.0, 18.0],
|
| 722 |
+
],
|
| 723 |
+
columns=["col1", "col2", "col3", "col4"],
|
| 724 |
+
)
|
| 725 |
+
tm.assert_frame_equal(result, expected)
|
| 726 |
+
|
| 727 |
+
def test_fillna_with_multi_index_frame(self):
|
| 728 |
+
# GH 47649
|
| 729 |
+
pdf = pd.DataFrame(
|
| 730 |
+
{
|
| 731 |
+
("x", "a"): [np.nan, 2.0, 3.0],
|
| 732 |
+
("x", "b"): [1.0, 2.0, np.nan],
|
| 733 |
+
("y", "c"): [1.0, 2.0, np.nan],
|
| 734 |
+
}
|
| 735 |
+
)
|
| 736 |
+
expected = pd.DataFrame(
|
| 737 |
+
{
|
| 738 |
+
("x", "a"): [-1.0, 2.0, 3.0],
|
| 739 |
+
("x", "b"): [1.0, 2.0, -1.0],
|
| 740 |
+
("y", "c"): [1.0, 2.0, np.nan],
|
| 741 |
+
}
|
| 742 |
+
)
|
| 743 |
+
tm.assert_frame_equal(pdf.fillna({"x": -1}), expected)
|
| 744 |
+
tm.assert_frame_equal(pdf.fillna({"x": -1, ("x", "b"): -2}), expected)
|
| 745 |
+
|
| 746 |
+
expected = pd.DataFrame(
|
| 747 |
+
{
|
| 748 |
+
("x", "a"): [-1.0, 2.0, 3.0],
|
| 749 |
+
("x", "b"): [1.0, 2.0, -2.0],
|
| 750 |
+
("y", "c"): [1.0, 2.0, np.nan],
|
| 751 |
+
}
|
| 752 |
+
)
|
| 753 |
+
tm.assert_frame_equal(pdf.fillna({("x", "b"): -2, "x": -1}), expected)
|
| 754 |
+
|
| 755 |
+
def test_fillna_multiindex_with_duplicate_columns(self):
|
| 756 |
+
# GH#53498
|
| 757 |
+
data = [[np.nan, 2, 3], [4, np.nan, 6], [7, 8, np.nan]]
|
| 758 |
+
df = pd.DataFrame(
|
| 759 |
+
data,
|
| 760 |
+
columns=pd.MultiIndex.from_tuples([("x", "a"), ("x", "a"), ("y", "b")]),
|
| 761 |
+
)
|
| 762 |
+
result = df.fillna({("x", "a"): 0})
|
| 763 |
+
expected = pd.DataFrame(
|
| 764 |
+
[[0.0, 2.0, 3.0], [4.0, 0.0, 6.0], [7.0, 8.0, np.nan]],
|
| 765 |
+
columns=pd.MultiIndex.from_tuples([("x", "a"), ("x", "a"), ("y", "b")]),
|
| 766 |
+
)
|
| 767 |
+
tm.assert_frame_equal(result, expected)
|
| 768 |
+
|
| 769 |
+
|
| 770 |
+
def test_fillna_nonconsolidated_frame():
|
| 771 |
+
# https://github.com/pandas-dev/pandas/issues/36495
|
| 772 |
+
df = pd.DataFrame(
|
| 773 |
+
[
|
| 774 |
+
[1, 1, 1, 1.0],
|
| 775 |
+
[2, 2, 2, 2.0],
|
| 776 |
+
[3, 3, 3, 3.0],
|
| 777 |
+
],
|
| 778 |
+
columns=["i1", "i2", "i3", "f1"],
|
| 779 |
+
)
|
| 780 |
+
df_nonconsol = df.pivot(index="i1", columns="i2")
|
| 781 |
+
result = df_nonconsol.fillna(0)
|
| 782 |
+
assert result.isna().sum().sum() == 0
|
| 783 |
+
|
| 784 |
+
|
| 785 |
+
def test_fillna_nones_inplace():
|
| 786 |
+
# GH 48480
|
| 787 |
+
df = pd.DataFrame(
|
| 788 |
+
[[None, None], [None, None]],
|
| 789 |
+
columns=["A", "B"],
|
| 790 |
+
)
|
| 791 |
+
result = df.fillna(value={"A": 1, "B": 2}, inplace=True)
|
| 792 |
+
assert result is df
|
| 793 |
+
|
| 794 |
+
expected = pd.DataFrame([[1, 2], [1, 2]], columns=["A", "B"], dtype=object)
|
| 795 |
+
tm.assert_frame_equal(df, expected)
|
| 796 |
+
|
| 797 |
+
|
| 798 |
+
@pytest.mark.parametrize(
|
| 799 |
+
"data, expected_data, method, kwargs",
|
| 800 |
+
(
|
| 801 |
+
(
|
| 802 |
+
[np.nan, np.nan, 3, np.nan, np.nan, np.nan, 7, np.nan, np.nan],
|
| 803 |
+
[np.nan, np.nan, 3.0, 3.0, 3.0, 3.0, 7.0, np.nan, np.nan],
|
| 804 |
+
"ffill",
|
| 805 |
+
{"limit_area": "inside"},
|
| 806 |
+
),
|
| 807 |
+
(
|
| 808 |
+
[np.nan, np.nan, 3, np.nan, np.nan, np.nan, 7, np.nan, np.nan],
|
| 809 |
+
[np.nan, np.nan, 3.0, 3.0, np.nan, np.nan, 7.0, np.nan, np.nan],
|
| 810 |
+
"ffill",
|
| 811 |
+
{"limit_area": "inside", "limit": 1},
|
| 812 |
+
),
|
| 813 |
+
(
|
| 814 |
+
[np.nan, np.nan, 3, np.nan, np.nan, np.nan, 7, np.nan, np.nan],
|
| 815 |
+
[np.nan, np.nan, 3.0, np.nan, np.nan, np.nan, 7.0, 7.0, 7.0],
|
| 816 |
+
"ffill",
|
| 817 |
+
{"limit_area": "outside"},
|
| 818 |
+
),
|
| 819 |
+
(
|
| 820 |
+
[np.nan, np.nan, 3, np.nan, np.nan, np.nan, 7, np.nan, np.nan],
|
| 821 |
+
[np.nan, np.nan, 3.0, np.nan, np.nan, np.nan, 7.0, 7.0, np.nan],
|
| 822 |
+
"ffill",
|
| 823 |
+
{"limit_area": "outside", "limit": 1},
|
| 824 |
+
),
|
| 825 |
+
(
|
| 826 |
+
[np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan],
|
| 827 |
+
[np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan],
|
| 828 |
+
"ffill",
|
| 829 |
+
{"limit_area": "outside", "limit": 1},
|
| 830 |
+
),
|
| 831 |
+
(
|
| 832 |
+
range(5),
|
| 833 |
+
range(5),
|
| 834 |
+
"ffill",
|
| 835 |
+
{"limit_area": "outside", "limit": 1},
|
| 836 |
+
),
|
| 837 |
+
(
|
| 838 |
+
[np.nan, np.nan, 3, np.nan, np.nan, np.nan, 7, np.nan, np.nan],
|
| 839 |
+
[np.nan, np.nan, 3.0, 7.0, 7.0, 7.0, 7.0, np.nan, np.nan],
|
| 840 |
+
"bfill",
|
| 841 |
+
{"limit_area": "inside"},
|
| 842 |
+
),
|
| 843 |
+
(
|
| 844 |
+
[np.nan, np.nan, 3, np.nan, np.nan, np.nan, 7, np.nan, np.nan],
|
| 845 |
+
[np.nan, np.nan, 3.0, np.nan, np.nan, 7.0, 7.0, np.nan, np.nan],
|
| 846 |
+
"bfill",
|
| 847 |
+
{"limit_area": "inside", "limit": 1},
|
| 848 |
+
),
|
| 849 |
+
(
|
| 850 |
+
[np.nan, np.nan, 3, np.nan, np.nan, np.nan, 7, np.nan, np.nan],
|
| 851 |
+
[3.0, 3.0, 3.0, np.nan, np.nan, np.nan, 7.0, np.nan, np.nan],
|
| 852 |
+
"bfill",
|
| 853 |
+
{"limit_area": "outside"},
|
| 854 |
+
),
|
| 855 |
+
(
|
| 856 |
+
[np.nan, np.nan, 3, np.nan, np.nan, np.nan, 7, np.nan, np.nan],
|
| 857 |
+
[np.nan, 3.0, 3.0, np.nan, np.nan, np.nan, 7.0, np.nan, np.nan],
|
| 858 |
+
"bfill",
|
| 859 |
+
{"limit_area": "outside", "limit": 1},
|
| 860 |
+
),
|
| 861 |
+
),
|
| 862 |
+
)
|
| 863 |
+
def test_ffill_bfill_limit_area(data, expected_data, method, kwargs):
|
| 864 |
+
# GH#56492
|
| 865 |
+
df = pd.DataFrame(data)
|
| 866 |
+
expected = pd.DataFrame(expected_data)
|
| 867 |
+
result = getattr(df, method)(**kwargs)
|
| 868 |
+
tm.assert_frame_equal(result, expected)
|
| 869 |
+
|
| 870 |
+
|
| 871 |
+
@pytest.mark.parametrize("test_frame", [True, False])
|
| 872 |
+
@pytest.mark.parametrize("dtype", ["float", "object"])
|
| 873 |
+
def test_fillna_with_none_object(test_frame, dtype):
|
| 874 |
+
# GH#57723
|
| 875 |
+
obj = pd.Series([1, np.nan, 3], dtype=dtype)
|
| 876 |
+
if test_frame:
|
| 877 |
+
obj = obj.to_frame()
|
| 878 |
+
result = obj.fillna(value=None)
|
| 879 |
+
expected = pd.Series([1, None, 3], dtype=dtype)
|
| 880 |
+
if test_frame:
|
| 881 |
+
expected = expected.to_frame()
|
| 882 |
+
tm.assert_equal(result, expected)
|
| 883 |
+
|
| 884 |
+
|
| 885 |
+
def test_fillna_out_of_bounds_datetime():
|
| 886 |
+
# GH#61208
|
| 887 |
+
df = pd.DataFrame(
|
| 888 |
+
{
|
| 889 |
+
"datetime": pd.date_range("1/1/2011", periods=3, freq="h", unit="ns"),
|
| 890 |
+
"value": [1, 2, 3],
|
| 891 |
+
}
|
| 892 |
+
)
|
| 893 |
+
df.iloc[0, 0] = None
|
| 894 |
+
|
| 895 |
+
msg = "Cannot cast 0001-01-01 00:00:00 to unit='ns' without overflow"
|
| 896 |
+
# GH#45153 the Pandas4Warning fires before the OutOfBoundsDatetime
|
| 897 |
+
with tm.assert_produces_warning(Pandas4Warning, match="fill value"):
|
| 898 |
+
with pytest.raises(OutOfBoundsDatetime, match=msg):
|
| 899 |
+
df.fillna(pd.Timestamp("0001-01-01"))
|
| 900 |
+
|
| 901 |
+
|
| 902 |
+
def test_fillna_dtype_preservation_after_apply():
|
| 903 |
+
# GH#14407 - fillna after apply should preserve dtypes correctly
|
| 904 |
+
# (block splitting should occur for mixed-dtype results)
|
| 905 |
+
df = pd.DataFrame(
|
| 906 |
+
{"c1": list("ABC"), "c2": list("123"), "c3": [1.5, 2.5, 3.5], "c4": [0, 1, 2]}
|
| 907 |
+
)
|
| 908 |
+
result = df.apply(lambda x: pd.to_numeric(x, errors="coerce")).fillna(df)
|
| 909 |
+
assert result["c1"].dtype == object
|
| 910 |
+
assert result["c2"].dtype == np.int64
|
| 911 |
+
assert result["c3"].dtype == np.float64
|
| 912 |
+
assert result["c4"].dtype == np.int64
|
| 913 |
+
|
| 914 |
+
|
| 915 |
+
def test_fillna_with_duplicate_index_and_unique_fill_frame():
|
| 916 |
+
# GH#36974 filling a frame that has a duplicated index from a frame with a
|
| 917 |
+
# unique index must align by label instead of raising InvalidIndexError
|
| 918 |
+
df = pd.DataFrame({"a": [np.nan, np.nan, 5.0]}, index=[0, 1, 0])
|
| 919 |
+
df_fillna = pd.DataFrame({"a": [10.0, 20.0]}, index=[0, 1])
|
| 920 |
+
result = df.fillna(df_fillna)
|
| 921 |
+
expected = pd.DataFrame({"a": [10.0, 20.0, 5.0]}, index=[0, 1, 0])
|
| 922 |
+
tm.assert_frame_equal(result, expected)
|
| 923 |
+
|
| 924 |
+
|
| 925 |
+
@pytest.mark.parametrize("axis", ["index", "columns"])
|
| 926 |
+
def test_fillna_fill_frame_with_duplicate_labels_raises(axis):
|
| 927 |
+
# GH#27672
|
| 928 |
+
df = pd.DataFrame({"A": [1.0, np.nan], "B": [np.nan, 2.0]}, index=["a", "b"])
|
| 929 |
+
if axis == "index":
|
| 930 |
+
value = pd.DataFrame({"A": [1, 0, 2], "B": [1, 2, 3]}, index=["b", "a", "b"])
|
| 931 |
+
else:
|
| 932 |
+
value = pd.DataFrame([[1, 2, 3]] * 2, index=["a", "b"], columns=["A", "B", "B"])
|
| 933 |
+
msg = "Cannot align with an object that has duplicate labels"
|
| 934 |
+
with pytest.raises(InvalidIndexError, match=msg):
|
| 935 |
+
df.fillna(value)
|
venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_filter.py
ADDED
|
@@ -0,0 +1,510 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import pytest
|
| 3 |
+
|
| 4 |
+
import pandas.util._test_decorators as td
|
| 5 |
+
|
| 6 |
+
import pandas as pd
|
| 7 |
+
import pandas._testing as tm
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class TestDataFrameFilter:
|
| 11 |
+
def test_filter(self, float_frame, float_string_frame):
|
| 12 |
+
# Items
|
| 13 |
+
filtered = float_frame.filter(["A", "B", "E"])
|
| 14 |
+
assert len(filtered.columns) == 2
|
| 15 |
+
assert "E" not in filtered
|
| 16 |
+
|
| 17 |
+
filtered = float_frame.filter(["A", "B", "E"], axis="columns")
|
| 18 |
+
assert len(filtered.columns) == 2
|
| 19 |
+
assert "E" not in filtered
|
| 20 |
+
|
| 21 |
+
# Other axis
|
| 22 |
+
idx = float_frame.index[0:4]
|
| 23 |
+
filtered = float_frame.filter(idx, axis="index")
|
| 24 |
+
expected = float_frame.reindex(index=idx)
|
| 25 |
+
tm.assert_frame_equal(filtered, expected)
|
| 26 |
+
|
| 27 |
+
# like
|
| 28 |
+
fcopy = float_frame.copy()
|
| 29 |
+
fcopy["AA"] = 1
|
| 30 |
+
|
| 31 |
+
filtered = fcopy.filter(like="A")
|
| 32 |
+
assert len(filtered.columns) == 2
|
| 33 |
+
assert "AA" in filtered
|
| 34 |
+
|
| 35 |
+
# like with ints in column names
|
| 36 |
+
df = pd.DataFrame(0.0, index=[0, 1, 2], columns=[0, 1, "_A", "_B"])
|
| 37 |
+
filtered = df.filter(like="_")
|
| 38 |
+
assert len(filtered.columns) == 2
|
| 39 |
+
|
| 40 |
+
# regex with ints in column names
|
| 41 |
+
# from PR #10384
|
| 42 |
+
df = pd.DataFrame(0.0, index=[0, 1, 2], columns=["A1", 1, "B", 2, "C"])
|
| 43 |
+
expected = pd.DataFrame(
|
| 44 |
+
0.0, index=[0, 1, 2], columns=pd.Index([1, 2], dtype=object)
|
| 45 |
+
)
|
| 46 |
+
filtered = df.filter(regex="^[0-9]+$")
|
| 47 |
+
tm.assert_frame_equal(filtered, expected)
|
| 48 |
+
|
| 49 |
+
expected = pd.DataFrame(0.0, index=[0, 1, 2], columns=[0, "0", 1, "1"])
|
| 50 |
+
# shouldn't remove anything
|
| 51 |
+
filtered = expected.filter(regex="^[0-9]+$")
|
| 52 |
+
tm.assert_frame_equal(filtered, expected)
|
| 53 |
+
|
| 54 |
+
# pass in None
|
| 55 |
+
no_arg_msg = "Must pass a positional argument or one of `items`, `cond`"
|
| 56 |
+
with pytest.raises(TypeError, match=no_arg_msg):
|
| 57 |
+
float_frame.filter()
|
| 58 |
+
with pytest.raises(TypeError, match=no_arg_msg):
|
| 59 |
+
float_frame.filter(items=None)
|
| 60 |
+
with pytest.raises(TypeError, match=no_arg_msg):
|
| 61 |
+
float_frame.filter(axis=1)
|
| 62 |
+
|
| 63 |
+
# test mutually exclusive arguments
|
| 64 |
+
with pytest.raises(TypeError, match="mutually exclusive"):
|
| 65 |
+
float_frame.filter(items=["one", "three"], regex="e$", like="bbi")
|
| 66 |
+
with pytest.raises(TypeError, match="mutually exclusive"):
|
| 67 |
+
float_frame.filter(items=["one", "three"], regex="e$", axis=1)
|
| 68 |
+
with pytest.raises(TypeError, match="mutually exclusive"):
|
| 69 |
+
float_frame.filter(items=["one", "three"], regex="e$")
|
| 70 |
+
with pytest.raises(TypeError, match="mutually exclusive"):
|
| 71 |
+
float_frame.filter(items=["one", "three"], like="bbi", axis=0)
|
| 72 |
+
with pytest.raises(TypeError, match="mutually exclusive"):
|
| 73 |
+
float_frame.filter(items=["one", "three"], like="bbi")
|
| 74 |
+
|
| 75 |
+
# objects
|
| 76 |
+
filtered = float_string_frame.filter(like="foo")
|
| 77 |
+
assert "foo" in filtered
|
| 78 |
+
|
| 79 |
+
# unicode columns, won't ascii-encode
|
| 80 |
+
df = float_frame.rename(columns={"B": "\u2202"})
|
| 81 |
+
filtered = df.filter(like="C")
|
| 82 |
+
assert "C" in filtered
|
| 83 |
+
|
| 84 |
+
def test_filter_regex_search(self, float_frame):
|
| 85 |
+
fcopy = float_frame.copy()
|
| 86 |
+
fcopy["AA"] = 1
|
| 87 |
+
|
| 88 |
+
# regex
|
| 89 |
+
filtered = fcopy.filter(regex="[A]+")
|
| 90 |
+
assert len(filtered.columns) == 2
|
| 91 |
+
assert "AA" in filtered
|
| 92 |
+
|
| 93 |
+
# doesn't have to be at beginning
|
| 94 |
+
df = pd.DataFrame(
|
| 95 |
+
{"aBBa": [1, 2], "BBaBB": [1, 2], "aCCa": [1, 2], "aCCaBB": [1, 2]}
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
result = df.filter(regex="BB")
|
| 99 |
+
exp = df[[x for x in df.columns if "BB" in x]]
|
| 100 |
+
tm.assert_frame_equal(result, exp)
|
| 101 |
+
|
| 102 |
+
@pytest.mark.parametrize(
|
| 103 |
+
"name,expected_data",
|
| 104 |
+
[
|
| 105 |
+
("a", {"a": [1, 2]}),
|
| 106 |
+
("あ", {"あ": [3, 4]}),
|
| 107 |
+
],
|
| 108 |
+
)
|
| 109 |
+
def test_filter_unicode(self, name, expected_data):
|
| 110 |
+
# GH13101
|
| 111 |
+
df = pd.DataFrame({"a": [1, 2], "あ": [3, 4]})
|
| 112 |
+
expected = pd.DataFrame(expected_data)
|
| 113 |
+
|
| 114 |
+
tm.assert_frame_equal(df.filter(like=name), expected)
|
| 115 |
+
tm.assert_frame_equal(df.filter(regex=name), expected)
|
| 116 |
+
|
| 117 |
+
def test_filter_bytestring(self):
|
| 118 |
+
# GH13101
|
| 119 |
+
name = "a"
|
| 120 |
+
df = pd.DataFrame({b"a": [1, 2], b"b": [3, 4]})
|
| 121 |
+
expected = pd.DataFrame({b"a": [1, 2]})
|
| 122 |
+
|
| 123 |
+
tm.assert_frame_equal(df.filter(like=name), expected)
|
| 124 |
+
tm.assert_frame_equal(df.filter(regex=name), expected)
|
| 125 |
+
|
| 126 |
+
def test_filter_corner(self):
|
| 127 |
+
empty = pd.DataFrame()
|
| 128 |
+
|
| 129 |
+
result = empty.filter([])
|
| 130 |
+
tm.assert_frame_equal(result, empty)
|
| 131 |
+
|
| 132 |
+
result = empty.filter(like="foo")
|
| 133 |
+
tm.assert_frame_equal(result, empty)
|
| 134 |
+
|
| 135 |
+
def test_filter_regex_non_string(self):
|
| 136 |
+
# GH#5798 trying to filter on non-string columns should drop,
|
| 137 |
+
# not raise
|
| 138 |
+
df = pd.DataFrame(
|
| 139 |
+
np.random.default_rng(2).random((3, 2)), columns=["STRING", 123]
|
| 140 |
+
)
|
| 141 |
+
result = df.filter(regex="STRING")
|
| 142 |
+
expected = df[["STRING"]]
|
| 143 |
+
tm.assert_frame_equal(result, expected)
|
| 144 |
+
|
| 145 |
+
def test_filter_keep_order(self):
|
| 146 |
+
# GH#54980
|
| 147 |
+
df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
|
| 148 |
+
result = df.filter(items=["B", "A"])
|
| 149 |
+
expected = df[["B", "A"]]
|
| 150 |
+
tm.assert_frame_equal(result, expected)
|
| 151 |
+
|
| 152 |
+
def test_filter_different_dtype(self):
|
| 153 |
+
# GH#54980
|
| 154 |
+
df = pd.DataFrame({1: [1, 2, 3], 2: [4, 5, 6]})
|
| 155 |
+
result = df.filter(items=["B", "A"])
|
| 156 |
+
expected = df[[]]
|
| 157 |
+
tm.assert_frame_equal(result, expected)
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
@pytest.fixture
|
| 161 |
+
def df():
|
| 162 |
+
return pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]}, index=["x", "y", "z"])
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
@pytest.mark.parametrize(
|
| 166 |
+
"mask",
|
| 167 |
+
[
|
| 168 |
+
[False, True, True],
|
| 169 |
+
np.array([False, True, True]),
|
| 170 |
+
pd.array([False, True, True], dtype="boolean"),
|
| 171 |
+
pd.Index([False, True, True]),
|
| 172 |
+
pd.Series([False, True, True], index=["x", "y", "z"]),
|
| 173 |
+
lambda df: df["a"] > 1,
|
| 174 |
+
pd.col("a") > 1,
|
| 175 |
+
],
|
| 176 |
+
)
|
| 177 |
+
def test_filter_cond_rows(df, mask):
|
| 178 |
+
# GH#61317
|
| 179 |
+
result = df.filter(cond=mask)
|
| 180 |
+
expected = df.iloc[1:]
|
| 181 |
+
tm.assert_frame_equal(result, expected)
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
@pytest.mark.parametrize("mask", [lambda df: df["a"] > 1, pd.col("a") > 1])
|
| 185 |
+
def test_filter_positional_callable_is_mask(df, mask):
|
| 186 |
+
# GH#61317
|
| 187 |
+
result = df.filter(mask)
|
| 188 |
+
expected = df.iloc[1:]
|
| 189 |
+
tm.assert_frame_equal(result, expected)
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
@pytest.mark.parametrize(
|
| 193 |
+
"mask",
|
| 194 |
+
[
|
| 195 |
+
[True, False, True],
|
| 196 |
+
[True, None, False],
|
| 197 |
+
np.array([True, False, True]),
|
| 198 |
+
pd.array([True, False, True], dtype="boolean"),
|
| 199 |
+
pd.Index([True, False, True]),
|
| 200 |
+
pd.Series([True, False, True], index=["x", "y", "z"]),
|
| 201 |
+
],
|
| 202 |
+
)
|
| 203 |
+
def test_filter_positional_bools_select_labels(df, mask):
|
| 204 |
+
# GH#61317
|
| 205 |
+
# A list-like of booleans passed positionally selects labels, as it did
|
| 206 |
+
# before masks were supported, but warns since it is likely meant as a mask
|
| 207 |
+
msg = "A list-like of booleans passed positionally to DataFrame.filter"
|
| 208 |
+
with tm.assert_produces_warning(UserWarning, match=msg):
|
| 209 |
+
result = df.filter(mask)
|
| 210 |
+
expected = df.iloc[:, []]
|
| 211 |
+
tm.assert_frame_equal(result, expected)
|
| 212 |
+
|
| 213 |
+
# the explicit keyword does not warn
|
| 214 |
+
result = df.filter(items=mask)
|
| 215 |
+
tm.assert_frame_equal(result, expected)
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
@pytest.mark.parametrize(
|
| 219 |
+
"arg, cols",
|
| 220 |
+
[
|
| 221 |
+
(["b", "a"], ["b", "a"]),
|
| 222 |
+
(("b", "a"), ["b", "a"]),
|
| 223 |
+
((True, False, True), []),
|
| 224 |
+
],
|
| 225 |
+
)
|
| 226 |
+
def test_filter_positional_labels_no_warning(df, arg, cols):
|
| 227 |
+
# GH#61317
|
| 228 |
+
# tuples are never masks
|
| 229 |
+
result = df.filter(arg)
|
| 230 |
+
expected = df[cols]
|
| 231 |
+
tm.assert_frame_equal(result, expected)
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
def test_filter_na_label():
|
| 235 |
+
# GH#61317
|
| 236 |
+
df = pd.DataFrame({np.nan: [1], "a": [2]})
|
| 237 |
+
result = df.filter(items=[np.nan])
|
| 238 |
+
expected = df.iloc[:, [0]]
|
| 239 |
+
tm.assert_frame_equal(result, expected, check_column_type=False)
|
| 240 |
+
|
| 241 |
+
df = pd.DataFrame({"a": [1, 2]}, index=[np.nan, "x"])
|
| 242 |
+
result = df.filter(items=[np.nan], axis=0)
|
| 243 |
+
expected = df.iloc[[0]]
|
| 244 |
+
tm.assert_frame_equal(result, expected, check_index_type=False)
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
def test_filter_tuple_labels_multiindex():
|
| 248 |
+
# GH#61317
|
| 249 |
+
mi = pd.MultiIndex.from_tuples([(True, False), (False, True)])
|
| 250 |
+
df = pd.DataFrame({"a": [1, 2]}, index=mi)
|
| 251 |
+
result = df.filter([(True, False)], axis=0)
|
| 252 |
+
expected = df.iloc[[0]]
|
| 253 |
+
tm.assert_frame_equal(result, expected)
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
@pytest.mark.parametrize(
|
| 257 |
+
"dtype",
|
| 258 |
+
[
|
| 259 |
+
"bool",
|
| 260 |
+
"boolean",
|
| 261 |
+
pytest.param("bool[pyarrow]", marks=td.skip_if_no("pyarrow")),
|
| 262 |
+
],
|
| 263 |
+
)
|
| 264 |
+
def test_filter_bool_labels(dtype):
|
| 265 |
+
# GH#61317
|
| 266 |
+
df = pd.DataFrame({"a": [1, 2]}, index=pd.Index([True, False], dtype=dtype))
|
| 267 |
+
result = df.filter(items=[True], axis=0)
|
| 268 |
+
expected = df.iloc[[0]]
|
| 269 |
+
tm.assert_frame_equal(result, expected)
|
| 270 |
+
|
| 271 |
+
msg = "A list-like of booleans passed positionally to DataFrame.filter"
|
| 272 |
+
with tm.assert_produces_warning(UserWarning, match=msg):
|
| 273 |
+
result = df.filter([True], axis=0)
|
| 274 |
+
tm.assert_frame_equal(result, expected)
|
| 275 |
+
|
| 276 |
+
result = df.filter(cond=[False, True], axis=0)
|
| 277 |
+
expected = df.iloc[[1]]
|
| 278 |
+
tm.assert_frame_equal(result, expected)
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
@pytest.mark.parametrize(
|
| 282 |
+
"kwargs",
|
| 283 |
+
[
|
| 284 |
+
{"items": ["a"]},
|
| 285 |
+
{"cond": [True, False, True]},
|
| 286 |
+
{"like": "a"},
|
| 287 |
+
{"regex": "a"},
|
| 288 |
+
],
|
| 289 |
+
)
|
| 290 |
+
def test_filter_positional_and_keyword_mutually_exclusive(df, kwargs):
|
| 291 |
+
# GH#61317
|
| 292 |
+
msg = "mutually exclusive"
|
| 293 |
+
with pytest.raises(TypeError, match=msg):
|
| 294 |
+
df.filter(["a"], **kwargs)
|
| 295 |
+
with pytest.raises(TypeError, match=msg):
|
| 296 |
+
df.filter(cond=[True, False, True], items=["a"])
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
@pytest.mark.parametrize(
|
| 300 |
+
"cond",
|
| 301 |
+
[["a"], [1, 0, 1], (True, False, True), "abc", np.array([1.0, 0.0, 1.0])],
|
| 302 |
+
)
|
| 303 |
+
def test_filter_cond_not_mask_raises(df, cond):
|
| 304 |
+
# GH#61317
|
| 305 |
+
msg = "cond passed to DataFrame.filter must be a one-dimensional boolean mask"
|
| 306 |
+
with pytest.raises(TypeError, match=msg):
|
| 307 |
+
df.filter(cond=cond)
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
def test_filter_cond_series_aligns(df):
|
| 311 |
+
# GH#61317
|
| 312 |
+
mask = pd.Series([True, True, False], index=["z", "y", "x"])
|
| 313 |
+
result = df.filter(cond=mask)
|
| 314 |
+
expected = df.iloc[1:]
|
| 315 |
+
tm.assert_frame_equal(result, expected)
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
def test_filter_cond_series_unalignable(df):
|
| 319 |
+
# GH#61317
|
| 320 |
+
mask = pd.Series([True, True, False], index=["z", "y", "w"])
|
| 321 |
+
msg = "Unalignable boolean Series provided as indexer"
|
| 322 |
+
with pytest.raises(pd.errors.IndexingError, match=msg):
|
| 323 |
+
df.filter(cond=mask)
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
def test_filter_cond_wrong_length(df):
|
| 327 |
+
# GH#61317
|
| 328 |
+
msg = "Boolean index has wrong length: 2 instead of 3"
|
| 329 |
+
with pytest.raises(IndexError, match=msg):
|
| 330 |
+
df.filter(cond=np.array([True, False]))
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
@pytest.mark.parametrize("axis", [1, "columns"])
|
| 334 |
+
def test_filter_cond_columns(df, axis):
|
| 335 |
+
# GH#61317
|
| 336 |
+
result = df.filter(cond=[False, True], axis=axis)
|
| 337 |
+
expected = df[["b"]]
|
| 338 |
+
tm.assert_frame_equal(result, expected)
|
| 339 |
+
|
| 340 |
+
|
| 341 |
+
@pytest.mark.parametrize("axis", [1, "columns"])
|
| 342 |
+
def test_filter_callable_columns(df, axis):
|
| 343 |
+
# GH#61317
|
| 344 |
+
result = df.filter(lambda df: df.columns == "b", axis=axis)
|
| 345 |
+
expected = df[["b"]]
|
| 346 |
+
tm.assert_frame_equal(result, expected)
|
| 347 |
+
|
| 348 |
+
result = df.filter(cond=lambda df: df.columns == "b", axis=axis)
|
| 349 |
+
tm.assert_frame_equal(result, expected)
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
@pytest.mark.parametrize("axis", [1, "columns"])
|
| 353 |
+
def test_filter_expression_columns_raises(df, axis):
|
| 354 |
+
# GH#61317
|
| 355 |
+
cond = pd.col("a") > 1
|
| 356 |
+
msg = (
|
| 357 |
+
"Expressions such as pd.col\\(...\\) are only supported by DataFrame.filter "
|
| 358 |
+
"with axis=0"
|
| 359 |
+
)
|
| 360 |
+
with pytest.raises(ValueError, match=msg):
|
| 361 |
+
df.filter(cond, axis=axis)
|
| 362 |
+
with pytest.raises(ValueError, match=msg):
|
| 363 |
+
df.filter(cond=cond, axis=axis)
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
def test_filter_cond_2d_raises(df):
|
| 367 |
+
# GH#61317
|
| 368 |
+
msg = "cond passed to DataFrame.filter must be a one-dimensional boolean mask"
|
| 369 |
+
with pytest.raises(TypeError, match=msg):
|
| 370 |
+
df.filter(cond=df > 1)
|
| 371 |
+
msg = "must evaluate to a one-dimensional boolean mask"
|
| 372 |
+
with pytest.raises(TypeError, match=msg):
|
| 373 |
+
df.filter(lambda df: df > 1)
|
| 374 |
+
|
| 375 |
+
msg = "The mask passed to DataFrame.filter must be one-dimensional"
|
| 376 |
+
with pytest.raises(ValueError, match=msg):
|
| 377 |
+
df.filter(cond=np.array([[True, False, True]]))
|
| 378 |
+
|
| 379 |
+
|
| 380 |
+
def test_filter_positional_frame_selects_labels(df):
|
| 381 |
+
# GH#61317
|
| 382 |
+
# a DataFrame is not a mask positionally; it fails as a list of labels
|
| 383 |
+
# without warning
|
| 384 |
+
msg = "Index data must be 1-dimensional"
|
| 385 |
+
with pytest.raises(ValueError, match=msg):
|
| 386 |
+
df.filter(df > 1)
|
| 387 |
+
|
| 388 |
+
|
| 389 |
+
def test_filter_callable_must_return_mask(df):
|
| 390 |
+
# GH#61317
|
| 391 |
+
msg = "The callable passed to DataFrame.filter must evaluate to a one-dimensional"
|
| 392 |
+
with pytest.raises(TypeError, match=msg):
|
| 393 |
+
df.filter(lambda df: ["a"])
|
| 394 |
+
with pytest.raises(TypeError, match=msg):
|
| 395 |
+
df.filter(cond=lambda df: ["a"])
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
def test_filter_expression_must_return_mask(df):
|
| 399 |
+
# GH#61317
|
| 400 |
+
msg = "The expression passed to DataFrame.filter must evaluate to a one-dimensional"
|
| 401 |
+
with pytest.raises(TypeError, match=msg):
|
| 402 |
+
df.filter(pd.col("a"))
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
@pytest.mark.parametrize(
|
| 406 |
+
"mask",
|
| 407 |
+
[
|
| 408 |
+
[True, None, False],
|
| 409 |
+
np.array([True, None, False], dtype=object),
|
| 410 |
+
pd.array([True, None, False], dtype="boolean"),
|
| 411 |
+
pd.Series([True, None, False], dtype="boolean", index=["x", "y", "z"]),
|
| 412 |
+
pd.Index([True, None, False], dtype=object),
|
| 413 |
+
],
|
| 414 |
+
)
|
| 415 |
+
def test_filter_cond_na(df, mask):
|
| 416 |
+
# GH#61317
|
| 417 |
+
# missing values are treated as False by default, matching df[mask]
|
| 418 |
+
# for a nullable boolean mask
|
| 419 |
+
result = df.filter(cond=mask)
|
| 420 |
+
expected = df.iloc[[0]]
|
| 421 |
+
tm.assert_frame_equal(result, expected)
|
| 422 |
+
|
| 423 |
+
result = df.filter(cond=mask, na=False)
|
| 424 |
+
tm.assert_frame_equal(result, expected)
|
| 425 |
+
|
| 426 |
+
msg = "The mask contains missing values"
|
| 427 |
+
with pytest.raises(ValueError, match=msg):
|
| 428 |
+
df.filter(cond=mask, na="raise")
|
| 429 |
+
|
| 430 |
+
result = df.filter(cond=mask, na=True)
|
| 431 |
+
expected = df.iloc[[0, 1]]
|
| 432 |
+
tm.assert_frame_equal(result, expected)
|
| 433 |
+
|
| 434 |
+
|
| 435 |
+
@td.skip_if_no("pyarrow")
|
| 436 |
+
def test_filter_cond_na_pyarrow(df):
|
| 437 |
+
# GH#61317
|
| 438 |
+
mask = pd.array([True, None, False], dtype="bool[pyarrow]")
|
| 439 |
+
result = df.filter(cond=mask)
|
| 440 |
+
expected = df.iloc[[0]]
|
| 441 |
+
tm.assert_frame_equal(result, expected)
|
| 442 |
+
|
| 443 |
+
msg = "The mask contains missing values"
|
| 444 |
+
with pytest.raises(ValueError, match=msg):
|
| 445 |
+
df.filter(cond=mask, na="raise")
|
| 446 |
+
|
| 447 |
+
result = df.filter(cond=mask, na=True)
|
| 448 |
+
expected = df.iloc[[0, 1]]
|
| 449 |
+
tm.assert_frame_equal(result, expected)
|
| 450 |
+
|
| 451 |
+
|
| 452 |
+
def test_filter_cond_all_na(df):
|
| 453 |
+
# GH#61317
|
| 454 |
+
result = df.filter(cond=[None, None, None])
|
| 455 |
+
expected = df.iloc[[]]
|
| 456 |
+
tm.assert_frame_equal(result, expected)
|
| 457 |
+
|
| 458 |
+
result = df.filter(cond=[None, None, None], na=True)
|
| 459 |
+
tm.assert_frame_equal(result, df)
|
| 460 |
+
|
| 461 |
+
with pytest.raises(ValueError, match="The mask contains missing values"):
|
| 462 |
+
df.filter(cond=[None, None, None], na="raise")
|
| 463 |
+
|
| 464 |
+
|
| 465 |
+
def test_filter_invalid_na(df):
|
| 466 |
+
# GH#61317
|
| 467 |
+
msg = "na must be 'raise', True, or False, got 'ignore'"
|
| 468 |
+
with pytest.raises(ValueError, match=msg):
|
| 469 |
+
df.filter(cond=[True, False, True], na="ignore")
|
| 470 |
+
|
| 471 |
+
|
| 472 |
+
@pytest.mark.parametrize(
|
| 473 |
+
"kwargs",
|
| 474 |
+
[
|
| 475 |
+
{"items": ["a"]},
|
| 476 |
+
{"items": ["x"], "axis": 0},
|
| 477 |
+
{"like": "a"},
|
| 478 |
+
{"like": "x", "axis": "index"},
|
| 479 |
+
{"regex": "a"},
|
| 480 |
+
{"regex": "x", "axis": 0},
|
| 481 |
+
],
|
| 482 |
+
)
|
| 483 |
+
def test_filter_labels(df, kwargs):
|
| 484 |
+
# GH#61317
|
| 485 |
+
# label-based usage keeps working and defaults to the columns
|
| 486 |
+
result = df.filter(**kwargs)
|
| 487 |
+
if kwargs.get("axis") in (0, "index"):
|
| 488 |
+
expected = df.iloc[[0]]
|
| 489 |
+
else:
|
| 490 |
+
expected = df[["a"]]
|
| 491 |
+
tm.assert_frame_equal(result, expected)
|
| 492 |
+
|
| 493 |
+
|
| 494 |
+
def test_filter_cond_default_axis_is_index(df):
|
| 495 |
+
# GH#61317
|
| 496 |
+
# unlike the label-based usage, a mask defaults to the index
|
| 497 |
+
result = df.filter(cond=[True, False, True])
|
| 498 |
+
expected = df.iloc[[0, 2]]
|
| 499 |
+
tm.assert_frame_equal(result, expected)
|
| 500 |
+
|
| 501 |
+
|
| 502 |
+
def test_filter_like_regex_positional():
|
| 503 |
+
# GH#61317
|
| 504 |
+
# like, regex, and axis remain positional-or-keyword after the
|
| 505 |
+
# positional-only first argument
|
| 506 |
+
df = pd.DataFrame({"a": [1]}, index=["x"])
|
| 507 |
+
result = df.filter(None, "x", None, 0)
|
| 508 |
+
tm.assert_frame_equal(result, df)
|
| 509 |
+
result = df.filter(None, None, "^x", 0)
|
| 510 |
+
tm.assert_frame_equal(result, df)
|
venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_first_valid_index.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Includes test for last_valid_index.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import numpy as np
|
| 6 |
+
import pytest
|
| 7 |
+
|
| 8 |
+
import pandas as pd
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class TestFirstValidIndex:
|
| 12 |
+
def test_first_valid_index_single_nan(self, frame_or_series):
|
| 13 |
+
# GH#9752 Series/DataFrame should both return None, not raise
|
| 14 |
+
obj = frame_or_series([np.nan])
|
| 15 |
+
|
| 16 |
+
assert obj.first_valid_index() is None
|
| 17 |
+
assert obj.iloc[:0].first_valid_index() is None
|
| 18 |
+
|
| 19 |
+
@pytest.mark.parametrize(
|
| 20 |
+
"dtype, expected_type", [("int64", int), ("float64", float), ("Int64", int)]
|
| 21 |
+
)
|
| 22 |
+
@pytest.mark.parametrize("method", ["first_valid_index", "last_valid_index"])
|
| 23 |
+
def test_first_last_valid_result_type(
|
| 24 |
+
self, frame_or_series, dtype, expected_type, method, using_python_scalars
|
| 25 |
+
):
|
| 26 |
+
# GH#64266
|
| 27 |
+
obj = frame_or_series(
|
| 28 |
+
[np.nan, 1.0, np.nan], index=pd.Index([10, 20, 30], dtype=dtype)
|
| 29 |
+
)
|
| 30 |
+
result = getattr(obj, method)()
|
| 31 |
+
assert result == 20
|
| 32 |
+
if using_python_scalars:
|
| 33 |
+
assert type(result) is expected_type
|
| 34 |
+
else:
|
| 35 |
+
assert isinstance(result, np.generic)
|
| 36 |
+
|
| 37 |
+
@pytest.mark.parametrize(
|
| 38 |
+
"empty",
|
| 39 |
+
[
|
| 40 |
+
pd.DataFrame(),
|
| 41 |
+
pd.Series(dtype=object),
|
| 42 |
+
pd.Series([], index=[], dtype=object),
|
| 43 |
+
],
|
| 44 |
+
)
|
| 45 |
+
def test_first_valid_index_empty(self, empty):
|
| 46 |
+
# GH#12800
|
| 47 |
+
assert empty.last_valid_index() is None
|
| 48 |
+
assert empty.first_valid_index() is None
|
| 49 |
+
|
| 50 |
+
@pytest.mark.parametrize(
|
| 51 |
+
"data,idx,expected_first,expected_last",
|
| 52 |
+
[
|
| 53 |
+
({"A": [1, 2, 3]}, [1, 1, 2], 1, 2),
|
| 54 |
+
({"A": [1, 2, 3]}, [1, 2, 2], 1, 2),
|
| 55 |
+
({"A": [1, 2, 3, 4]}, ["d", "d", "d", "d"], "d", "d"),
|
| 56 |
+
({"A": [1, np.nan, 3]}, [1, 1, 2], 1, 2),
|
| 57 |
+
({"A": [np.nan, np.nan, 3]}, [1, 1, 2], 2, 2),
|
| 58 |
+
({"A": [1, np.nan, 3]}, [1, 2, 2], 1, 2),
|
| 59 |
+
],
|
| 60 |
+
)
|
| 61 |
+
def test_first_last_valid_frame(self, data, idx, expected_first, expected_last):
|
| 62 |
+
# GH#21441
|
| 63 |
+
df = pd.DataFrame(data, index=idx)
|
| 64 |
+
assert expected_first == df.first_valid_index()
|
| 65 |
+
assert expected_last == df.last_valid_index()
|
| 66 |
+
|
| 67 |
+
@pytest.mark.parametrize(
|
| 68 |
+
"index",
|
| 69 |
+
[
|
| 70 |
+
pd.Index([str(i) for i in range(20)]),
|
| 71 |
+
pd.date_range("2020-01-01", periods=20),
|
| 72 |
+
],
|
| 73 |
+
)
|
| 74 |
+
def test_first_last_valid(self, index):
|
| 75 |
+
mat = np.random.default_rng(2).standard_normal(len(index))
|
| 76 |
+
mat[:5] = np.nan
|
| 77 |
+
mat[-5:] = np.nan
|
| 78 |
+
|
| 79 |
+
frame = pd.DataFrame({"foo": mat}, index=index)
|
| 80 |
+
assert frame.first_valid_index() == frame.index[5]
|
| 81 |
+
assert frame.last_valid_index() == frame.index[-6]
|
| 82 |
+
|
| 83 |
+
ser = frame["foo"]
|
| 84 |
+
assert ser.first_valid_index() == frame.index[5]
|
| 85 |
+
assert ser.last_valid_index() == frame.index[-6]
|
| 86 |
+
|
| 87 |
+
@pytest.mark.parametrize(
|
| 88 |
+
"index",
|
| 89 |
+
[
|
| 90 |
+
pd.Index([str(i) for i in range(10)]),
|
| 91 |
+
pd.date_range("2020-01-01", periods=10),
|
| 92 |
+
],
|
| 93 |
+
)
|
| 94 |
+
def test_first_last_valid_all_nan(self, index):
|
| 95 |
+
# GH#17400: no valid entries
|
| 96 |
+
frame = pd.DataFrame(np.nan, columns=["foo"], index=index)
|
| 97 |
+
|
| 98 |
+
assert frame.last_valid_index() is None
|
| 99 |
+
assert frame.first_valid_index() is None
|
| 100 |
+
|
| 101 |
+
ser = frame["foo"]
|
| 102 |
+
assert ser.first_valid_index() is None
|
| 103 |
+
assert ser.last_valid_index() is None
|
venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_get_numeric_data.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import pandas._testing as tm
|
| 5 |
+
from pandas.core.arrays import IntervalArray
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class TestGetNumericData:
|
| 9 |
+
def test_get_numeric_data_preserve_dtype(self):
|
| 10 |
+
# get the numeric data
|
| 11 |
+
obj = pd.DataFrame(
|
| 12 |
+
{"A": [1, "2", 3.0]}, columns=pd.Index(["A"], dtype="object")
|
| 13 |
+
)
|
| 14 |
+
result = obj._get_numeric_data()
|
| 15 |
+
expected = pd.DataFrame(dtype=object, index=pd.RangeIndex(3), columns=[])
|
| 16 |
+
tm.assert_frame_equal(result, expected)
|
| 17 |
+
|
| 18 |
+
def test_get_numeric_data(self, using_infer_string):
|
| 19 |
+
datetime64name = np.dtype("M8[s]").name
|
| 20 |
+
objectname = np.dtype(np.object_).name
|
| 21 |
+
|
| 22 |
+
df = pd.DataFrame(
|
| 23 |
+
{"a": 1.0, "b": 2, "c": "foo", "f": pd.Timestamp("20010102").as_unit("s")},
|
| 24 |
+
index=np.arange(10),
|
| 25 |
+
)
|
| 26 |
+
result = df.dtypes
|
| 27 |
+
expected = pd.Series(
|
| 28 |
+
[
|
| 29 |
+
np.dtype("float64"),
|
| 30 |
+
np.dtype("int64"),
|
| 31 |
+
np.dtype(objectname)
|
| 32 |
+
if not using_infer_string
|
| 33 |
+
else pd.StringDtype(na_value=np.nan),
|
| 34 |
+
np.dtype(datetime64name),
|
| 35 |
+
],
|
| 36 |
+
index=["a", "b", "c", "f"],
|
| 37 |
+
)
|
| 38 |
+
tm.assert_series_equal(result, expected)
|
| 39 |
+
|
| 40 |
+
df = pd.DataFrame(
|
| 41 |
+
{
|
| 42 |
+
"a": 1.0,
|
| 43 |
+
"b": 2,
|
| 44 |
+
"c": "foo",
|
| 45 |
+
"d": np.array([1.0] * 10, dtype="float32"),
|
| 46 |
+
"e": np.array([1] * 10, dtype="int32"),
|
| 47 |
+
"f": np.array([1] * 10, dtype="int16"),
|
| 48 |
+
"g": pd.Timestamp("20010102"),
|
| 49 |
+
},
|
| 50 |
+
index=np.arange(10),
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
result = df._get_numeric_data()
|
| 54 |
+
expected = df.loc[:, ["a", "b", "d", "e", "f"]]
|
| 55 |
+
tm.assert_frame_equal(result, expected)
|
| 56 |
+
|
| 57 |
+
only_obj = df.loc[:, ["c", "g"]]
|
| 58 |
+
result = only_obj._get_numeric_data()
|
| 59 |
+
expected = df.loc[:, []]
|
| 60 |
+
tm.assert_frame_equal(result, expected)
|
| 61 |
+
|
| 62 |
+
df = pd.DataFrame.from_dict(
|
| 63 |
+
{"a": [1, 2], "b": ["foo", "bar"], "c": [np.pi, np.e]}
|
| 64 |
+
)
|
| 65 |
+
result = df._get_numeric_data()
|
| 66 |
+
expected = pd.DataFrame.from_dict({"a": [1, 2], "c": [np.pi, np.e]})
|
| 67 |
+
tm.assert_frame_equal(result, expected)
|
| 68 |
+
|
| 69 |
+
df = result.copy()
|
| 70 |
+
result = df._get_numeric_data()
|
| 71 |
+
expected = df
|
| 72 |
+
tm.assert_frame_equal(result, expected)
|
| 73 |
+
|
| 74 |
+
def test_get_numeric_data_mixed_dtype(self):
|
| 75 |
+
# numeric and object columns
|
| 76 |
+
|
| 77 |
+
df = pd.DataFrame(
|
| 78 |
+
{
|
| 79 |
+
"a": [1, 2, 3],
|
| 80 |
+
"b": [True, False, True],
|
| 81 |
+
"c": ["foo", "bar", "baz"],
|
| 82 |
+
"d": [None, None, None],
|
| 83 |
+
"e": [3.14, 0.577, 2.773],
|
| 84 |
+
}
|
| 85 |
+
)
|
| 86 |
+
result = df._get_numeric_data()
|
| 87 |
+
tm.assert_index_equal(result.columns, pd.Index(["a", "b", "e"]))
|
| 88 |
+
|
| 89 |
+
def test_get_numeric_data_extension_dtype(self):
|
| 90 |
+
# GH#22290
|
| 91 |
+
df = pd.DataFrame(
|
| 92 |
+
{
|
| 93 |
+
"A": pd.array([-10, pd.NA, 0, 10, 20, 30], dtype="Int64"),
|
| 94 |
+
"B": pd.Categorical(list("abcabc")),
|
| 95 |
+
"C": pd.array([0, 1, 2, 3, pd.NA, 5], dtype="UInt8"),
|
| 96 |
+
"D": IntervalArray.from_breaks(range(7)),
|
| 97 |
+
}
|
| 98 |
+
)
|
| 99 |
+
result = df._get_numeric_data()
|
| 100 |
+
expected = df.loc[:, ["A", "C"]]
|
| 101 |
+
tm.assert_frame_equal(result, expected)
|
venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_head_tail.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import pandas._testing as tm
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def test_head_tail_generic(index, frame_or_series):
|
| 8 |
+
# GH#5370
|
| 9 |
+
|
| 10 |
+
ndim = 2 if frame_or_series is pd.DataFrame else 1
|
| 11 |
+
shape = (len(index),) * ndim
|
| 12 |
+
vals = np.random.default_rng(2).standard_normal(shape)
|
| 13 |
+
obj = frame_or_series(vals, index=index)
|
| 14 |
+
|
| 15 |
+
tm.assert_equal(obj.head(), obj.iloc[:5])
|
| 16 |
+
tm.assert_equal(obj.tail(), obj.iloc[-5:])
|
| 17 |
+
|
| 18 |
+
# 0-len
|
| 19 |
+
tm.assert_equal(obj.head(0), obj.iloc[0:0])
|
| 20 |
+
tm.assert_equal(obj.tail(0), obj.iloc[0:0])
|
| 21 |
+
|
| 22 |
+
# bounded
|
| 23 |
+
tm.assert_equal(obj.head(len(obj) + 1), obj)
|
| 24 |
+
tm.assert_equal(obj.tail(len(obj) + 1), obj)
|
| 25 |
+
|
| 26 |
+
# neg index
|
| 27 |
+
tm.assert_equal(obj.head(-3), obj.head(len(index) - 3))
|
| 28 |
+
tm.assert_equal(obj.tail(-3), obj.tail(len(index) - 3))
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def test_head_tail(float_frame):
|
| 32 |
+
tm.assert_frame_equal(float_frame.head(), float_frame[:5])
|
| 33 |
+
tm.assert_frame_equal(float_frame.tail(), float_frame[-5:])
|
| 34 |
+
|
| 35 |
+
tm.assert_frame_equal(float_frame.head(0), float_frame[0:0])
|
| 36 |
+
tm.assert_frame_equal(float_frame.tail(0), float_frame[0:0])
|
| 37 |
+
|
| 38 |
+
tm.assert_frame_equal(float_frame.head(-1), float_frame[:-1])
|
| 39 |
+
tm.assert_frame_equal(float_frame.tail(-1), float_frame[1:])
|
| 40 |
+
tm.assert_frame_equal(float_frame.head(1), float_frame[:1])
|
| 41 |
+
tm.assert_frame_equal(float_frame.tail(1), float_frame[-1:])
|
| 42 |
+
# with a float index
|
| 43 |
+
df = float_frame.copy()
|
| 44 |
+
df.index = np.arange(len(float_frame)) + 0.1
|
| 45 |
+
tm.assert_frame_equal(df.head(), df.iloc[:5])
|
| 46 |
+
tm.assert_frame_equal(df.tail(), df.iloc[-5:])
|
| 47 |
+
tm.assert_frame_equal(df.head(0), df[0:0])
|
| 48 |
+
tm.assert_frame_equal(df.tail(0), df[0:0])
|
| 49 |
+
tm.assert_frame_equal(df.head(-1), df.iloc[:-1])
|
| 50 |
+
tm.assert_frame_equal(df.tail(-1), df.iloc[1:])
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def test_head_tail_empty():
|
| 54 |
+
# test empty dataframe
|
| 55 |
+
empty_df = pd.DataFrame()
|
| 56 |
+
tm.assert_frame_equal(empty_df.tail(), empty_df)
|
| 57 |
+
tm.assert_frame_equal(empty_df.head(), empty_df)
|
venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_infer_objects.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from datetime import datetime
|
| 2 |
+
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import pandas._testing as tm
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class TestInferObjects:
|
| 8 |
+
def test_infer_objects(self):
|
| 9 |
+
# GH#11221
|
| 10 |
+
df = pd.DataFrame(
|
| 11 |
+
{
|
| 12 |
+
"a": ["a", 1, 2, 3],
|
| 13 |
+
"b": ["b", 2.0, 3.0, 4.1],
|
| 14 |
+
"c": [
|
| 15 |
+
"c",
|
| 16 |
+
datetime(2016, 1, 1),
|
| 17 |
+
datetime(2016, 1, 2),
|
| 18 |
+
datetime(2016, 1, 3),
|
| 19 |
+
],
|
| 20 |
+
"d": [1, 2, 3, "d"],
|
| 21 |
+
},
|
| 22 |
+
columns=["a", "b", "c", "d"],
|
| 23 |
+
)
|
| 24 |
+
df = df.iloc[1:].infer_objects()
|
| 25 |
+
|
| 26 |
+
assert df["a"].dtype == "int64"
|
| 27 |
+
assert df["b"].dtype == "float64"
|
| 28 |
+
assert df["c"].dtype == "M8[us]"
|
| 29 |
+
assert df["d"].dtype == "object"
|
| 30 |
+
|
| 31 |
+
expected = pd.DataFrame(
|
| 32 |
+
{
|
| 33 |
+
"a": [1, 2, 3],
|
| 34 |
+
"b": [2.0, 3.0, 4.1],
|
| 35 |
+
"c": [datetime(2016, 1, 1), datetime(2016, 1, 2), datetime(2016, 1, 3)],
|
| 36 |
+
"d": [2, 3, "d"],
|
| 37 |
+
},
|
| 38 |
+
columns=["a", "b", "c", "d"],
|
| 39 |
+
)
|
| 40 |
+
# reconstruct frame to verify inference is same
|
| 41 |
+
result = df.reset_index(drop=True)
|
| 42 |
+
tm.assert_frame_equal(result, expected)
|
venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_info.py
ADDED
|
@@ -0,0 +1,619 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from io import StringIO
|
| 2 |
+
import re
|
| 3 |
+
from string import ascii_uppercase
|
| 4 |
+
import sys
|
| 5 |
+
import textwrap
|
| 6 |
+
|
| 7 |
+
import numpy as np
|
| 8 |
+
import pytest
|
| 9 |
+
|
| 10 |
+
from pandas.compat import (
|
| 11 |
+
HAS_PYARROW,
|
| 12 |
+
IS64,
|
| 13 |
+
PYPY,
|
| 14 |
+
is_platform_arm,
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
import pandas as pd
|
| 18 |
+
import pandas._testing as tm
|
| 19 |
+
from pandas.util.version import Version
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
@pytest.fixture
|
| 23 |
+
def duplicate_columns_frame():
|
| 24 |
+
"""Dataframe with duplicate column names."""
|
| 25 |
+
return pd.DataFrame(
|
| 26 |
+
np.random.default_rng(2).standard_normal((1500, 4)),
|
| 27 |
+
columns=["a", "a", "b", "b"],
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def test_info_empty():
|
| 32 |
+
# GH #45494
|
| 33 |
+
df = pd.DataFrame()
|
| 34 |
+
buf = StringIO()
|
| 35 |
+
df.info(buf=buf)
|
| 36 |
+
result = buf.getvalue()
|
| 37 |
+
expected = textwrap.dedent(
|
| 38 |
+
"""\
|
| 39 |
+
<class 'pandas.DataFrame'>
|
| 40 |
+
RangeIndex: 0 entries
|
| 41 |
+
Empty DataFrame\n"""
|
| 42 |
+
)
|
| 43 |
+
assert result == expected
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def test_info_categorical_column_smoke_test():
|
| 47 |
+
n = 2500
|
| 48 |
+
df = pd.DataFrame(
|
| 49 |
+
{"int64": np.random.default_rng(2).integers(100, size=n, dtype=int)}
|
| 50 |
+
)
|
| 51 |
+
df["category"] = pd.Series(
|
| 52 |
+
np.array(list("abcdefghij")).take(
|
| 53 |
+
np.random.default_rng(2).integers(0, 10, size=n, dtype=int)
|
| 54 |
+
)
|
| 55 |
+
).astype("category")
|
| 56 |
+
df.isna()
|
| 57 |
+
buf = StringIO()
|
| 58 |
+
df.info(buf=buf)
|
| 59 |
+
|
| 60 |
+
df2 = df[df["category"] == "d"]
|
| 61 |
+
buf = StringIO()
|
| 62 |
+
df2.info(buf=buf)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
@pytest.mark.parametrize(
|
| 66 |
+
"fixture_func_name",
|
| 67 |
+
[
|
| 68 |
+
"int_frame",
|
| 69 |
+
"float_frame",
|
| 70 |
+
"datetime_frame",
|
| 71 |
+
"duplicate_columns_frame",
|
| 72 |
+
"float_string_frame",
|
| 73 |
+
],
|
| 74 |
+
)
|
| 75 |
+
def test_info_smoke_test(fixture_func_name, request):
|
| 76 |
+
frame = request.getfixturevalue(fixture_func_name)
|
| 77 |
+
buf = StringIO()
|
| 78 |
+
frame.info(buf=buf)
|
| 79 |
+
result = buf.getvalue().splitlines()
|
| 80 |
+
assert len(result) > 10
|
| 81 |
+
|
| 82 |
+
buf = StringIO()
|
| 83 |
+
frame.info(buf=buf, verbose=False)
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def test_info_smoke_test2(float_frame):
|
| 87 |
+
# pretty useless test, used to be mixed into the repr tests
|
| 88 |
+
buf = StringIO()
|
| 89 |
+
float_frame.reindex(columns=["A"]).info(verbose=False, buf=buf)
|
| 90 |
+
float_frame.reindex(columns=["A", "B"]).info(verbose=False, buf=buf)
|
| 91 |
+
|
| 92 |
+
# no columns or index
|
| 93 |
+
pd.DataFrame().info(buf=buf)
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
@pytest.mark.parametrize(
|
| 97 |
+
"num_columns, max_info_columns, verbose",
|
| 98 |
+
[
|
| 99 |
+
(10, 100, True),
|
| 100 |
+
(10, 11, True),
|
| 101 |
+
(10, 10, True),
|
| 102 |
+
(10, 9, False),
|
| 103 |
+
(10, 1, False),
|
| 104 |
+
],
|
| 105 |
+
)
|
| 106 |
+
def test_info_default_verbose_selection(num_columns, max_info_columns, verbose):
|
| 107 |
+
frame = pd.DataFrame(np.random.default_rng(2).standard_normal((5, num_columns)))
|
| 108 |
+
with pd.option_context("display.max_info_columns", max_info_columns):
|
| 109 |
+
io_default = StringIO()
|
| 110 |
+
frame.info(buf=io_default)
|
| 111 |
+
result = io_default.getvalue()
|
| 112 |
+
|
| 113 |
+
io_explicit = StringIO()
|
| 114 |
+
frame.info(buf=io_explicit, verbose=verbose)
|
| 115 |
+
expected = io_explicit.getvalue()
|
| 116 |
+
|
| 117 |
+
assert result == expected
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def test_info_verbose_check_header_separator_body():
|
| 121 |
+
buf = StringIO()
|
| 122 |
+
size = 1001
|
| 123 |
+
start = 5
|
| 124 |
+
frame = pd.DataFrame(np.random.default_rng(2).standard_normal((3, size)))
|
| 125 |
+
frame.info(verbose=True, buf=buf)
|
| 126 |
+
|
| 127 |
+
res = buf.getvalue()
|
| 128 |
+
header = " # Column Dtype \n--- ------ ----- "
|
| 129 |
+
assert header in res
|
| 130 |
+
|
| 131 |
+
frame.info(verbose=True, buf=buf)
|
| 132 |
+
buf.seek(0)
|
| 133 |
+
lines = buf.readlines()
|
| 134 |
+
assert len(lines) > 0
|
| 135 |
+
|
| 136 |
+
for i, line in enumerate(lines):
|
| 137 |
+
if start <= i < start + size:
|
| 138 |
+
line_nr = f" {i - start} "
|
| 139 |
+
assert line.startswith(line_nr)
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
@pytest.mark.parametrize(
|
| 143 |
+
"size, header_exp, separator_exp, first_line_exp, last_line_exp",
|
| 144 |
+
[
|
| 145 |
+
(
|
| 146 |
+
4,
|
| 147 |
+
" # Column Non-Null Count Dtype ",
|
| 148 |
+
"--- ------ -------------- ----- ",
|
| 149 |
+
" 0 0 3 non-null float64",
|
| 150 |
+
" 3 3 3 non-null float64",
|
| 151 |
+
),
|
| 152 |
+
(
|
| 153 |
+
11,
|
| 154 |
+
" # Column Non-Null Count Dtype ",
|
| 155 |
+
"--- ------ -------------- ----- ",
|
| 156 |
+
" 0 0 3 non-null float64",
|
| 157 |
+
" 10 10 3 non-null float64",
|
| 158 |
+
),
|
| 159 |
+
(
|
| 160 |
+
101,
|
| 161 |
+
" # Column Non-Null Count Dtype ",
|
| 162 |
+
"--- ------ -------------- ----- ",
|
| 163 |
+
" 0 0 3 non-null float64",
|
| 164 |
+
" 100 100 3 non-null float64",
|
| 165 |
+
),
|
| 166 |
+
(
|
| 167 |
+
1001,
|
| 168 |
+
" # Column Non-Null Count Dtype ",
|
| 169 |
+
"--- ------ -------------- ----- ",
|
| 170 |
+
" 0 0 3 non-null float64",
|
| 171 |
+
" 1000 1000 3 non-null float64",
|
| 172 |
+
),
|
| 173 |
+
(
|
| 174 |
+
10001,
|
| 175 |
+
" # Column Non-Null Count Dtype ",
|
| 176 |
+
"--- ------ -------------- ----- ",
|
| 177 |
+
" 0 0 3 non-null float64",
|
| 178 |
+
" 10000 10000 3 non-null float64",
|
| 179 |
+
),
|
| 180 |
+
],
|
| 181 |
+
)
|
| 182 |
+
def test_info_verbose_with_counts_spacing(
|
| 183 |
+
size, header_exp, separator_exp, first_line_exp, last_line_exp
|
| 184 |
+
):
|
| 185 |
+
"""Test header column, spacer, first line and last line in verbose mode."""
|
| 186 |
+
frame = pd.DataFrame(np.random.default_rng(2).standard_normal((3, size)))
|
| 187 |
+
with StringIO() as buf:
|
| 188 |
+
frame.info(verbose=True, show_counts=True, buf=buf)
|
| 189 |
+
all_lines = buf.getvalue().splitlines()
|
| 190 |
+
# Here table would contain only header, separator and table lines
|
| 191 |
+
# dframe repr, index summary, memory usage and dtypes are excluded
|
| 192 |
+
table = all_lines[3:-2]
|
| 193 |
+
header, separator, first_line, *rest, last_line = table
|
| 194 |
+
assert header == header_exp
|
| 195 |
+
assert separator == separator_exp
|
| 196 |
+
assert first_line == first_line_exp
|
| 197 |
+
assert last_line == last_line_exp
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
def test_info_memory():
|
| 201 |
+
# https://github.com/pandas-dev/pandas/issues/21056
|
| 202 |
+
df = pd.DataFrame({"a": pd.Series([1, 2], dtype="i8")})
|
| 203 |
+
buf = StringIO()
|
| 204 |
+
df.info(buf=buf)
|
| 205 |
+
result = buf.getvalue()
|
| 206 |
+
bytes = float(df.memory_usage().sum())
|
| 207 |
+
expected = textwrap.dedent(
|
| 208 |
+
f"""\
|
| 209 |
+
<class 'pandas.DataFrame'>
|
| 210 |
+
RangeIndex: 2 entries, 0 to 1
|
| 211 |
+
Data columns (total 1 columns):
|
| 212 |
+
# Column Non-Null Count Dtype
|
| 213 |
+
--- ------ -------------- -----
|
| 214 |
+
0 a 2 non-null int64
|
| 215 |
+
dtypes: int64(1)
|
| 216 |
+
memory usage: {bytes} bytes
|
| 217 |
+
"""
|
| 218 |
+
)
|
| 219 |
+
assert result == expected
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
def test_info_wide():
|
| 223 |
+
io = StringIO()
|
| 224 |
+
df = pd.DataFrame(np.random.default_rng(2).standard_normal((5, 101)))
|
| 225 |
+
df.info(buf=io)
|
| 226 |
+
|
| 227 |
+
io = StringIO()
|
| 228 |
+
df.info(buf=io, max_cols=101)
|
| 229 |
+
result = io.getvalue()
|
| 230 |
+
assert len(result.splitlines()) > 100
|
| 231 |
+
|
| 232 |
+
expected = result
|
| 233 |
+
with pd.option_context("display.max_info_columns", 101):
|
| 234 |
+
io = StringIO()
|
| 235 |
+
df.info(buf=io)
|
| 236 |
+
result = io.getvalue()
|
| 237 |
+
assert result == expected
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
def test_info_duplicate_columns_shows_correct_dtypes():
|
| 241 |
+
# GH11761
|
| 242 |
+
io = StringIO()
|
| 243 |
+
frame = pd.DataFrame([[1, 2.0]], columns=["a", "a"])
|
| 244 |
+
frame.info(buf=io)
|
| 245 |
+
lines = io.getvalue().splitlines(True)
|
| 246 |
+
assert " 0 a 1 non-null int64 \n" == lines[5]
|
| 247 |
+
assert " 1 a 1 non-null float64\n" == lines[6]
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
def test_info_shows_column_dtypes():
|
| 251 |
+
dtypes = [
|
| 252 |
+
"int64",
|
| 253 |
+
"float64",
|
| 254 |
+
"datetime64[ns]",
|
| 255 |
+
"timedelta64[ns]",
|
| 256 |
+
"complex128",
|
| 257 |
+
"object",
|
| 258 |
+
"bool",
|
| 259 |
+
]
|
| 260 |
+
data = {}
|
| 261 |
+
n = 10
|
| 262 |
+
for i, dtype in enumerate(dtypes):
|
| 263 |
+
data[i] = np.random.default_rng(2).integers(2, size=n).astype(dtype)
|
| 264 |
+
df = pd.DataFrame(data)
|
| 265 |
+
buf = StringIO()
|
| 266 |
+
df.info(buf=buf)
|
| 267 |
+
res = buf.getvalue()
|
| 268 |
+
header = (
|
| 269 |
+
" # Column Non-Null Count Dtype \n"
|
| 270 |
+
"--- ------ -------------- ----- "
|
| 271 |
+
)
|
| 272 |
+
assert header in res
|
| 273 |
+
for i, dtype in enumerate(dtypes):
|
| 274 |
+
name = f" {i:d} {i:d} {n:d} non-null {dtype}"
|
| 275 |
+
assert name in res
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
def test_info_max_cols():
|
| 279 |
+
df = pd.DataFrame(np.random.default_rng(2).standard_normal((10, 5)))
|
| 280 |
+
for len_, verbose in [(5, None), (5, False), (12, True)]:
|
| 281 |
+
# For verbose always ^ setting ^ summarize ^ full output
|
| 282 |
+
with pd.option_context("max_info_columns", 4):
|
| 283 |
+
buf = StringIO()
|
| 284 |
+
df.info(buf=buf, verbose=verbose)
|
| 285 |
+
res = buf.getvalue()
|
| 286 |
+
assert len(res.strip().split("\n")) == len_
|
| 287 |
+
|
| 288 |
+
for len_, verbose in [(12, None), (5, False), (12, True)]:
|
| 289 |
+
# max_cols not exceeded
|
| 290 |
+
with pd.option_context("max_info_columns", 5):
|
| 291 |
+
buf = StringIO()
|
| 292 |
+
df.info(buf=buf, verbose=verbose)
|
| 293 |
+
res = buf.getvalue()
|
| 294 |
+
assert len(res.strip().split("\n")) == len_
|
| 295 |
+
|
| 296 |
+
for len_, max_cols in [(12, 5), (5, 4)]:
|
| 297 |
+
# setting truncates
|
| 298 |
+
with pd.option_context("max_info_columns", 4):
|
| 299 |
+
buf = StringIO()
|
| 300 |
+
df.info(buf=buf, max_cols=max_cols)
|
| 301 |
+
res = buf.getvalue()
|
| 302 |
+
assert len(res.strip().split("\n")) == len_
|
| 303 |
+
|
| 304 |
+
# setting wouldn't truncate
|
| 305 |
+
with pd.option_context("max_info_columns", 5):
|
| 306 |
+
buf = StringIO()
|
| 307 |
+
df.info(buf=buf, max_cols=max_cols)
|
| 308 |
+
res = buf.getvalue()
|
| 309 |
+
assert len(res.strip().split("\n")) == len_
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
def test_info_memory_usage():
|
| 313 |
+
# Ensure memory usage is displayed, when asserted, on the last line
|
| 314 |
+
dtypes = [
|
| 315 |
+
"int64",
|
| 316 |
+
"float64",
|
| 317 |
+
"datetime64[ns]",
|
| 318 |
+
"timedelta64[ns]",
|
| 319 |
+
"complex128",
|
| 320 |
+
"object",
|
| 321 |
+
"bool",
|
| 322 |
+
]
|
| 323 |
+
data = {}
|
| 324 |
+
n = 10
|
| 325 |
+
for i, dtype in enumerate(dtypes):
|
| 326 |
+
data[i] = np.random.default_rng(2).integers(2, size=n).astype(dtype)
|
| 327 |
+
df = pd.DataFrame(data)
|
| 328 |
+
buf = StringIO()
|
| 329 |
+
|
| 330 |
+
# display memory usage case
|
| 331 |
+
df.info(buf=buf, memory_usage=True)
|
| 332 |
+
res = buf.getvalue().splitlines()
|
| 333 |
+
assert "memory usage: " in res[-1]
|
| 334 |
+
|
| 335 |
+
# do not display memory usage case
|
| 336 |
+
df.info(buf=buf, memory_usage=False)
|
| 337 |
+
res = buf.getvalue().splitlines()
|
| 338 |
+
assert "memory usage: " not in res[-1]
|
| 339 |
+
|
| 340 |
+
df.info(buf=buf, memory_usage=True)
|
| 341 |
+
res = buf.getvalue().splitlines()
|
| 342 |
+
|
| 343 |
+
# memory usage is a lower bound, so print it as XYZ+ MB
|
| 344 |
+
assert re.match(r"memory usage: [^+]+\+", res[-1])
|
| 345 |
+
|
| 346 |
+
df.iloc[:, :5].info(buf=buf, memory_usage=True)
|
| 347 |
+
res = buf.getvalue().splitlines()
|
| 348 |
+
|
| 349 |
+
# excluded column with object dtype, so estimate is accurate
|
| 350 |
+
assert not re.match(r"memory usage: [^+]+\+", res[-1])
|
| 351 |
+
|
| 352 |
+
# Test a DataFrame with duplicate columns
|
| 353 |
+
dtypes = ["int64", "int64", "int64", "float64"]
|
| 354 |
+
data = {}
|
| 355 |
+
n = 100
|
| 356 |
+
for i, dtype in enumerate(dtypes):
|
| 357 |
+
data[i] = np.random.default_rng(2).integers(2, size=n).astype(dtype)
|
| 358 |
+
df = pd.DataFrame(data)
|
| 359 |
+
df.columns = dtypes
|
| 360 |
+
|
| 361 |
+
df_with_object_index = pd.DataFrame(
|
| 362 |
+
{"a": [1]}, index=pd.Index(["foo"], dtype=object)
|
| 363 |
+
)
|
| 364 |
+
df_with_object_index.info(buf=buf, memory_usage=True)
|
| 365 |
+
res = buf.getvalue().splitlines()
|
| 366 |
+
assert re.match(r"memory usage: [^+]+\+", res[-1])
|
| 367 |
+
|
| 368 |
+
df_with_object_index.info(buf=buf, memory_usage="deep")
|
| 369 |
+
res = buf.getvalue().splitlines()
|
| 370 |
+
assert re.match(r"memory usage: [^+]+$", res[-1])
|
| 371 |
+
|
| 372 |
+
# Ensure df size is as expected
|
| 373 |
+
# (cols * rows * bytes) + index size
|
| 374 |
+
df_size = df.memory_usage().sum()
|
| 375 |
+
exp_size = len(dtypes) * n * 8 + df.index.nbytes
|
| 376 |
+
assert df_size == exp_size
|
| 377 |
+
|
| 378 |
+
# Ensure number of cols in memory_usage is the same as df
|
| 379 |
+
size_df = np.size(df.columns.values) + 1 # index=True; default
|
| 380 |
+
assert size_df == np.size(df.memory_usage())
|
| 381 |
+
|
| 382 |
+
# assert deep works only on object
|
| 383 |
+
assert df.memory_usage().sum() == df.memory_usage(deep=True).sum()
|
| 384 |
+
|
| 385 |
+
# test for validity
|
| 386 |
+
pd.DataFrame(1, index=["a"], columns=["A"]).memory_usage(index=True)
|
| 387 |
+
pd.DataFrame(1, index=["a"], columns=["A"]).index.nbytes
|
| 388 |
+
df = pd.DataFrame(
|
| 389 |
+
data=1, index=pd.MultiIndex.from_product([["a"], range(1000)]), columns=["A"]
|
| 390 |
+
)
|
| 391 |
+
df.index.nbytes
|
| 392 |
+
df.memory_usage(index=True)
|
| 393 |
+
df.index.values.nbytes
|
| 394 |
+
|
| 395 |
+
mem = df.memory_usage(deep=True).sum()
|
| 396 |
+
assert mem > 0
|
| 397 |
+
|
| 398 |
+
|
| 399 |
+
@pytest.mark.skipif(PYPY, reason="on PyPy deep=True doesn't change result")
|
| 400 |
+
def test_info_memory_usage_deep_not_pypy():
|
| 401 |
+
df_with_object_index = pd.DataFrame(
|
| 402 |
+
{"a": [1]}, index=pd.Index(["foo"], dtype=object)
|
| 403 |
+
)
|
| 404 |
+
assert (
|
| 405 |
+
df_with_object_index.memory_usage(index=True, deep=True).sum()
|
| 406 |
+
> df_with_object_index.memory_usage(index=True).sum()
|
| 407 |
+
)
|
| 408 |
+
|
| 409 |
+
df_object = pd.DataFrame({"a": pd.Series(["a"], dtype=object)})
|
| 410 |
+
assert df_object.memory_usage(deep=True).sum() > df_object.memory_usage().sum()
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
@pytest.mark.xfail(not PYPY, reason="on PyPy deep=True does not change result")
|
| 414 |
+
def test_info_memory_usage_deep_pypy():
|
| 415 |
+
df_with_object_index = pd.DataFrame(
|
| 416 |
+
{"a": [1]}, index=pd.Index(["foo"], dtype=object)
|
| 417 |
+
)
|
| 418 |
+
assert (
|
| 419 |
+
df_with_object_index.memory_usage(index=True, deep=True).sum()
|
| 420 |
+
== df_with_object_index.memory_usage(index=True).sum()
|
| 421 |
+
)
|
| 422 |
+
|
| 423 |
+
df_object = pd.DataFrame({"a": pd.Series(["a"], dtype=object)})
|
| 424 |
+
assert df_object.memory_usage(deep=True).sum() == df_object.memory_usage().sum()
|
| 425 |
+
|
| 426 |
+
|
| 427 |
+
@pytest.mark.skipif(PYPY, reason="PyPy getsizeof() fails by design")
|
| 428 |
+
def test_usage_via_getsizeof():
|
| 429 |
+
df = pd.DataFrame(
|
| 430 |
+
data=1, index=pd.MultiIndex.from_product([["a"], range(1000)]), columns=["A"]
|
| 431 |
+
)
|
| 432 |
+
mem = df.memory_usage(deep=True).sum()
|
| 433 |
+
# sys.getsizeof will call the .memory_usage with
|
| 434 |
+
# deep=True, and add on some GC overhead
|
| 435 |
+
diff = mem - sys.getsizeof(df)
|
| 436 |
+
assert abs(diff) < 100
|
| 437 |
+
|
| 438 |
+
|
| 439 |
+
def test_info_memory_usage_qualified(using_infer_string):
|
| 440 |
+
buf = StringIO()
|
| 441 |
+
df = pd.DataFrame(1, columns=list("ab"), index=[1, 2, 3])
|
| 442 |
+
df.info(buf=buf)
|
| 443 |
+
assert "+" not in buf.getvalue()
|
| 444 |
+
|
| 445 |
+
buf = StringIO()
|
| 446 |
+
df = pd.DataFrame(1, columns=list("ab"), index=pd.Index(list("ABC"), dtype=object))
|
| 447 |
+
df.info(buf=buf)
|
| 448 |
+
assert "+" in buf.getvalue()
|
| 449 |
+
|
| 450 |
+
buf = StringIO()
|
| 451 |
+
df = pd.DataFrame(1, columns=list("ab"), index=pd.Index(list("ABC"), dtype="str"))
|
| 452 |
+
df.info(buf=buf)
|
| 453 |
+
if using_infer_string and HAS_PYARROW:
|
| 454 |
+
assert "+" not in buf.getvalue()
|
| 455 |
+
else:
|
| 456 |
+
assert "+" in buf.getvalue()
|
| 457 |
+
|
| 458 |
+
buf = StringIO()
|
| 459 |
+
df = pd.DataFrame(
|
| 460 |
+
1, columns=list("ab"), index=pd.MultiIndex.from_product([range(3), range(3)])
|
| 461 |
+
)
|
| 462 |
+
df.info(buf=buf)
|
| 463 |
+
assert "+" not in buf.getvalue()
|
| 464 |
+
|
| 465 |
+
buf = StringIO()
|
| 466 |
+
df = pd.DataFrame(
|
| 467 |
+
1,
|
| 468 |
+
columns=list("ab"),
|
| 469 |
+
index=pd.MultiIndex.from_product([range(3), ["foo", "bar"]]),
|
| 470 |
+
)
|
| 471 |
+
df.info(buf=buf)
|
| 472 |
+
if using_infer_string and HAS_PYARROW:
|
| 473 |
+
assert "+" not in buf.getvalue()
|
| 474 |
+
else:
|
| 475 |
+
assert "+" in buf.getvalue()
|
| 476 |
+
|
| 477 |
+
|
| 478 |
+
def test_info_memory_usage_bug_on_multiindex():
|
| 479 |
+
# GH 14308
|
| 480 |
+
# memory usage introspection should not materialize .values
|
| 481 |
+
|
| 482 |
+
def memory_usage(f):
|
| 483 |
+
return f.memory_usage(deep=True).sum()
|
| 484 |
+
|
| 485 |
+
N = 100
|
| 486 |
+
M = len(ascii_uppercase)
|
| 487 |
+
index = pd.MultiIndex.from_product(
|
| 488 |
+
[list(ascii_uppercase), pd.date_range("20160101", periods=N)],
|
| 489 |
+
names=["id", "date"],
|
| 490 |
+
)
|
| 491 |
+
df = pd.DataFrame(
|
| 492 |
+
{"value": np.random.default_rng(2).standard_normal(N * M)}, index=index
|
| 493 |
+
)
|
| 494 |
+
|
| 495 |
+
unstacked = df.unstack("id")
|
| 496 |
+
assert df.values.nbytes == unstacked.values.nbytes
|
| 497 |
+
assert memory_usage(df) > memory_usage(unstacked)
|
| 498 |
+
|
| 499 |
+
# high upper bound
|
| 500 |
+
assert memory_usage(unstacked) - memory_usage(df) < 2000
|
| 501 |
+
|
| 502 |
+
|
| 503 |
+
def test_info_categorical():
|
| 504 |
+
# GH14298
|
| 505 |
+
idx = pd.CategoricalIndex(["a", "b"])
|
| 506 |
+
df = pd.DataFrame(np.zeros((2, 2)), index=idx, columns=idx)
|
| 507 |
+
|
| 508 |
+
buf = StringIO()
|
| 509 |
+
df.info(buf=buf)
|
| 510 |
+
|
| 511 |
+
|
| 512 |
+
@pytest.mark.xfail(not IS64, reason="GH 36579: fail on 32-bit system")
|
| 513 |
+
def test_info_int_columns(using_infer_string):
|
| 514 |
+
# GH#37245
|
| 515 |
+
df = pd.DataFrame({1: [1, 2], 2: [2, 3]}, index=["A", "B"])
|
| 516 |
+
buf = StringIO()
|
| 517 |
+
df.info(show_counts=True, buf=buf)
|
| 518 |
+
result = buf.getvalue()
|
| 519 |
+
expected = textwrap.dedent(
|
| 520 |
+
f"""\
|
| 521 |
+
<class 'pandas.DataFrame'>
|
| 522 |
+
Index: 2 entries, A to B
|
| 523 |
+
Data columns (total 2 columns):
|
| 524 |
+
# Column Non-Null Count Dtype
|
| 525 |
+
--- ------ -------------- -----
|
| 526 |
+
0 1 2 non-null int64
|
| 527 |
+
1 2 2 non-null int64
|
| 528 |
+
dtypes: int64(2)
|
| 529 |
+
memory usage: {"50.0" if using_infer_string and HAS_PYARROW else "48.0+"} bytes
|
| 530 |
+
"""
|
| 531 |
+
)
|
| 532 |
+
assert result == expected
|
| 533 |
+
|
| 534 |
+
|
| 535 |
+
def test_memory_usage_empty_no_warning(using_infer_string):
|
| 536 |
+
# GH#50066
|
| 537 |
+
df = pd.DataFrame(index=["a", "b"])
|
| 538 |
+
with tm.assert_produces_warning(None):
|
| 539 |
+
result = df.memory_usage()
|
| 540 |
+
if using_infer_string and HAS_PYARROW:
|
| 541 |
+
value = 18
|
| 542 |
+
else:
|
| 543 |
+
value = 16 if IS64 else 8
|
| 544 |
+
expected = pd.Series(value, index=["Index"])
|
| 545 |
+
tm.assert_series_equal(result, expected)
|
| 546 |
+
|
| 547 |
+
|
| 548 |
+
@pytest.mark.single_cpu
|
| 549 |
+
def test_info_compute_numba():
|
| 550 |
+
# GH#51922
|
| 551 |
+
numba = pytest.importorskip("numba")
|
| 552 |
+
if Version(numba.__version__) == Version("0.61") and is_platform_arm():
|
| 553 |
+
pytest.skip(f"Segfaults on ARM platforms with numba {numba.__version__}")
|
| 554 |
+
df = pd.DataFrame([[1, 2], [3, 4]])
|
| 555 |
+
|
| 556 |
+
with pd.option_context("compute.use_numba", True):
|
| 557 |
+
buf = StringIO()
|
| 558 |
+
df.info(buf=buf)
|
| 559 |
+
result = buf.getvalue()
|
| 560 |
+
|
| 561 |
+
buf = StringIO()
|
| 562 |
+
df.info(buf=buf)
|
| 563 |
+
expected = buf.getvalue()
|
| 564 |
+
assert result == expected
|
| 565 |
+
|
| 566 |
+
|
| 567 |
+
@pytest.mark.parametrize(
|
| 568 |
+
"row, columns, show_counts, result",
|
| 569 |
+
[
|
| 570 |
+
[20, 20, None, True],
|
| 571 |
+
[20, 20, True, True],
|
| 572 |
+
[20, 20, False, False],
|
| 573 |
+
[5, 5, None, False],
|
| 574 |
+
[5, 5, True, False],
|
| 575 |
+
[5, 5, False, False],
|
| 576 |
+
],
|
| 577 |
+
)
|
| 578 |
+
def test_info_show_counts(row, columns, show_counts, result):
|
| 579 |
+
# Explicit cast to float to avoid implicit cast when setting nan
|
| 580 |
+
df = pd.DataFrame(1, columns=range(10), index=range(10)).astype({1: "float"})
|
| 581 |
+
df.iloc[1, 1] = np.nan
|
| 582 |
+
|
| 583 |
+
with pd.option_context(
|
| 584 |
+
"display.max_info_rows", row, "display.max_info_columns", columns
|
| 585 |
+
):
|
| 586 |
+
with StringIO() as buf:
|
| 587 |
+
df.info(buf=buf, show_counts=show_counts)
|
| 588 |
+
assert ("non-null" in buf.getvalue()) is result
|
| 589 |
+
|
| 590 |
+
|
| 591 |
+
def test_info_dtype_after_datetime_to_pydatetime():
|
| 592 |
+
# GH#55136
|
| 593 |
+
# After converting datetime64 column to python datetime objects,
|
| 594 |
+
# .info() should report dtype as object, not datetime64
|
| 595 |
+
df = pd.DataFrame({"a": pd.to_datetime(["2023-01-01", "2023-01-02"])})
|
| 596 |
+
df["a"] = df["a"].dt.to_pydatetime()
|
| 597 |
+
assert df["a"].dtype == np.dtype("object")
|
| 598 |
+
with StringIO() as buf:
|
| 599 |
+
df.info(buf=buf)
|
| 600 |
+
info_str = buf.getvalue()
|
| 601 |
+
assert "object" in info_str
|
| 602 |
+
assert "datetime64" not in info_str
|
| 603 |
+
|
| 604 |
+
|
| 605 |
+
def test_info_east_asian_width():
|
| 606 |
+
# GH#46082
|
| 607 |
+
df = pd.DataFrame({"열이름": [1], "列名": [2], "column": [3]})
|
| 608 |
+
with pd.option_context("display.unicode.east_asian_width", True):
|
| 609 |
+
with StringIO() as buf:
|
| 610 |
+
df.info(buf=buf)
|
| 611 |
+
lines = buf.getvalue().splitlines()
|
| 612 |
+
expected = [
|
| 613 |
+
" # Column Non-Null Count Dtype",
|
| 614 |
+
"--- ------ -------------- -----",
|
| 615 |
+
" 0 열이름 1 non-null int64",
|
| 616 |
+
" 1 列名 1 non-null int64",
|
| 617 |
+
" 2 column 1 non-null int64",
|
| 618 |
+
]
|
| 619 |
+
assert lines[3:8] == expected
|
venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_interpolate.py
ADDED
|
@@ -0,0 +1,492 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import pytest
|
| 3 |
+
|
| 4 |
+
import pandas.util._test_decorators as td
|
| 5 |
+
|
| 6 |
+
import pandas as pd
|
| 7 |
+
import pandas._testing as tm
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class TestDataFrameInterpolate:
|
| 11 |
+
def test_interpolate_complex(self):
|
| 12 |
+
# GH#53635
|
| 13 |
+
ser = pd.Series([complex("1+1j"), float("nan"), complex("2+2j")])
|
| 14 |
+
assert ser.dtype.kind == "c"
|
| 15 |
+
|
| 16 |
+
res = ser.interpolate()
|
| 17 |
+
expected = pd.Series([ser[0], ser[0] * 1.5, ser[2]])
|
| 18 |
+
tm.assert_series_equal(res, expected)
|
| 19 |
+
|
| 20 |
+
df = ser.to_frame()
|
| 21 |
+
res = df.interpolate()
|
| 22 |
+
expected = expected.to_frame()
|
| 23 |
+
tm.assert_frame_equal(res, expected)
|
| 24 |
+
|
| 25 |
+
def test_interpolate_datetimelike_values(self, frame_or_series):
|
| 26 |
+
# GH#11312, GH#51005
|
| 27 |
+
orig = pd.Series(pd.date_range("2012-01-01", periods=5))
|
| 28 |
+
ser = orig.copy()
|
| 29 |
+
ser[2] = pd.NaT
|
| 30 |
+
|
| 31 |
+
res = frame_or_series(ser).interpolate()
|
| 32 |
+
expected = frame_or_series(orig)
|
| 33 |
+
tm.assert_equal(res, expected)
|
| 34 |
+
|
| 35 |
+
# datetime64tz cast
|
| 36 |
+
ser_tz = ser.dt.tz_localize("US/Pacific")
|
| 37 |
+
res_tz = frame_or_series(ser_tz).interpolate()
|
| 38 |
+
expected_tz = frame_or_series(orig.dt.tz_localize("US/Pacific"))
|
| 39 |
+
tm.assert_equal(res_tz, expected_tz)
|
| 40 |
+
|
| 41 |
+
# timedelta64 cast
|
| 42 |
+
ser_td = ser - ser[0]
|
| 43 |
+
res_td = frame_or_series(ser_td).interpolate()
|
| 44 |
+
expected_td = frame_or_series(orig - orig[0])
|
| 45 |
+
tm.assert_equal(res_td, expected_td)
|
| 46 |
+
|
| 47 |
+
def test_interpolate_inplace(self, frame_or_series, request):
|
| 48 |
+
# GH#44749
|
| 49 |
+
obj = frame_or_series([1, np.nan, 2])
|
| 50 |
+
orig = obj.values
|
| 51 |
+
|
| 52 |
+
result = obj.interpolate(inplace=True)
|
| 53 |
+
assert result is obj
|
| 54 |
+
expected = frame_or_series([1, 1.5, 2])
|
| 55 |
+
tm.assert_equal(obj, expected)
|
| 56 |
+
|
| 57 |
+
# check we operated *actually* inplace
|
| 58 |
+
assert np.shares_memory(orig, obj.values)
|
| 59 |
+
assert orig.squeeze()[1] == 1.5
|
| 60 |
+
|
| 61 |
+
@pytest.mark.parametrize("dtype", ["str", "object"])
|
| 62 |
+
def test_interp_with_non_numeric(self, dtype, using_infer_string):
|
| 63 |
+
if not using_infer_string:
|
| 64 |
+
dtype = "object"
|
| 65 |
+
df = pd.DataFrame(
|
| 66 |
+
{
|
| 67 |
+
"A": [1, 2, np.nan, 4],
|
| 68 |
+
"B": [1, 4, 9, np.nan],
|
| 69 |
+
"C": [1, 2, 3, 5],
|
| 70 |
+
"D": list("abcd"),
|
| 71 |
+
}
|
| 72 |
+
)
|
| 73 |
+
df["D"] = df["D"].astype(dtype)
|
| 74 |
+
df_orig = df.copy()
|
| 75 |
+
expected = pd.DataFrame(
|
| 76 |
+
{
|
| 77 |
+
"A": [1.0, 2.0, 3.0, 4.0],
|
| 78 |
+
"B": [1.0, 4.0, 9.0, 9.0],
|
| 79 |
+
"C": [1, 2, 3, 5],
|
| 80 |
+
"D": list("abcd"),
|
| 81 |
+
}
|
| 82 |
+
)
|
| 83 |
+
expected["D"] = expected["D"].astype(dtype)
|
| 84 |
+
|
| 85 |
+
# the EA path (str dtype) and the object-block path word the error
|
| 86 |
+
# differently; pin each to its dtype rather than hedging the case
|
| 87 |
+
if dtype == "object":
|
| 88 |
+
msg = "cannot interpolate with object dtype"
|
| 89 |
+
else:
|
| 90 |
+
msg = f"Cannot interpolate with {dtype} dtype"
|
| 91 |
+
with pytest.raises(TypeError, match=msg):
|
| 92 |
+
df.interpolate()
|
| 93 |
+
tm.assert_frame_equal(df, df_orig)
|
| 94 |
+
|
| 95 |
+
with pytest.raises(TypeError, match=msg):
|
| 96 |
+
df.interpolate(inplace=True)
|
| 97 |
+
# columns A and B already get interpolated before we hit the error
|
| 98 |
+
tm.assert_frame_equal(df, expected)
|
| 99 |
+
|
| 100 |
+
def test_interp_basic(self):
|
| 101 |
+
df = pd.DataFrame(
|
| 102 |
+
{
|
| 103 |
+
"A": [1, 2, np.nan, 4],
|
| 104 |
+
"B": [1, 4, 9, np.nan],
|
| 105 |
+
"C": [1, 2, 3, 5],
|
| 106 |
+
}
|
| 107 |
+
)
|
| 108 |
+
df_orig = df.copy()
|
| 109 |
+
expected = pd.DataFrame(
|
| 110 |
+
{
|
| 111 |
+
"A": [1.0, 2.0, 3.0, 4.0],
|
| 112 |
+
"B": [1.0, 4.0, 9.0, 9.0],
|
| 113 |
+
"C": [1, 2, 3, 5],
|
| 114 |
+
}
|
| 115 |
+
)
|
| 116 |
+
result = df.interpolate()
|
| 117 |
+
tm.assert_frame_equal(result, expected)
|
| 118 |
+
|
| 119 |
+
# check we didn't operate inplace GH#45791
|
| 120 |
+
tm.assert_frame_equal(df, df_orig)
|
| 121 |
+
bvalues = df["B"]._values
|
| 122 |
+
cvalues = df["C"]._values
|
| 123 |
+
assert not tm.shares_memory(bvalues, result["B"]._values)
|
| 124 |
+
assert tm.shares_memory(cvalues, result["C"]._values)
|
| 125 |
+
|
| 126 |
+
res = df.interpolate(inplace=True)
|
| 127 |
+
assert res is df
|
| 128 |
+
tm.assert_frame_equal(df, expected)
|
| 129 |
+
|
| 130 |
+
# check we DID operate inplace
|
| 131 |
+
assert tm.shares_memory(df["B"]._values, bvalues)
|
| 132 |
+
assert tm.shares_memory(df["C"]._values, cvalues)
|
| 133 |
+
|
| 134 |
+
def test_interp_basic_with_non_range_index(self):
|
| 135 |
+
df = pd.DataFrame(
|
| 136 |
+
{
|
| 137 |
+
"A": [1, 2, np.nan, 4],
|
| 138 |
+
"B": [1, 4, 9, np.nan],
|
| 139 |
+
"C": [1, 2, 3, 5],
|
| 140 |
+
}
|
| 141 |
+
)
|
| 142 |
+
result = df.set_index("C").interpolate()
|
| 143 |
+
expected = df.set_index("C")
|
| 144 |
+
expected.loc[3, "A"] = 3
|
| 145 |
+
expected.loc[5, "B"] = 9
|
| 146 |
+
tm.assert_frame_equal(result, expected)
|
| 147 |
+
|
| 148 |
+
def test_interp_empty(self):
|
| 149 |
+
# https://github.com/pandas-dev/pandas/issues/35598
|
| 150 |
+
df = pd.DataFrame()
|
| 151 |
+
result = df.interpolate()
|
| 152 |
+
assert result is not df
|
| 153 |
+
expected = df
|
| 154 |
+
tm.assert_frame_equal(result, expected)
|
| 155 |
+
|
| 156 |
+
def test_interp_bad_method(self):
|
| 157 |
+
df = pd.DataFrame(
|
| 158 |
+
{
|
| 159 |
+
"A": [1, 2, np.nan, 4],
|
| 160 |
+
"B": [1, 4, 9, np.nan],
|
| 161 |
+
"C": [1, 2, 3, 5],
|
| 162 |
+
}
|
| 163 |
+
)
|
| 164 |
+
msg = "Can not interpolate with method=not_a_method"
|
| 165 |
+
with pytest.raises(ValueError, match=msg):
|
| 166 |
+
df.interpolate(method="not_a_method")
|
| 167 |
+
|
| 168 |
+
def test_interp_combo(self):
|
| 169 |
+
df = pd.DataFrame(
|
| 170 |
+
{
|
| 171 |
+
"A": [1.0, 2.0, np.nan, 4.0],
|
| 172 |
+
"B": [1, 4, 9, np.nan],
|
| 173 |
+
"C": [1, 2, 3, 5],
|
| 174 |
+
"D": list("abcd"),
|
| 175 |
+
}
|
| 176 |
+
)
|
| 177 |
+
|
| 178 |
+
result = df["A"].interpolate()
|
| 179 |
+
expected = pd.Series([1.0, 2.0, 3.0, 4.0], name="A")
|
| 180 |
+
tm.assert_series_equal(result, expected)
|
| 181 |
+
|
| 182 |
+
def test_interp_nan_idx(self):
|
| 183 |
+
df = pd.DataFrame({"A": [1, 2, np.nan, 4], "B": [np.nan, 2, 3, 4]})
|
| 184 |
+
df = df.set_index("A")
|
| 185 |
+
msg = (
|
| 186 |
+
"Interpolation with NaNs in the index has not been implemented. "
|
| 187 |
+
"Try filling those NaNs before interpolating."
|
| 188 |
+
)
|
| 189 |
+
with pytest.raises(NotImplementedError, match=msg):
|
| 190 |
+
df.interpolate(method="values")
|
| 191 |
+
|
| 192 |
+
def test_interp_various(self):
|
| 193 |
+
pytest.importorskip("scipy")
|
| 194 |
+
df = pd.DataFrame(
|
| 195 |
+
{"A": [1, 2, np.nan, 4, 5, np.nan, 7], "C": [1, 2, 3, 5, 8, 13, 21]}
|
| 196 |
+
)
|
| 197 |
+
df = df.set_index("C")
|
| 198 |
+
expected = df.copy()
|
| 199 |
+
result = df.interpolate(method="polynomial", order=1)
|
| 200 |
+
|
| 201 |
+
expected.loc[3, "A"] = 2.66666667
|
| 202 |
+
expected.loc[13, "A"] = 5.76923076
|
| 203 |
+
tm.assert_frame_equal(result, expected)
|
| 204 |
+
|
| 205 |
+
result = df.interpolate(method="cubic")
|
| 206 |
+
# GH #15662.
|
| 207 |
+
expected.loc[3, "A"] = 2.81547781
|
| 208 |
+
expected.loc[13, "A"] = 5.52964175
|
| 209 |
+
tm.assert_frame_equal(result, expected)
|
| 210 |
+
|
| 211 |
+
result = df.interpolate(method="nearest")
|
| 212 |
+
expected.loc[3, "A"] = 2
|
| 213 |
+
expected.loc[13, "A"] = 5
|
| 214 |
+
tm.assert_frame_equal(result, expected, check_dtype=False)
|
| 215 |
+
|
| 216 |
+
result = df.interpolate(method="quadratic")
|
| 217 |
+
expected.loc[3, "A"] = 2.82150771
|
| 218 |
+
expected.loc[13, "A"] = 6.12648668
|
| 219 |
+
tm.assert_frame_equal(result, expected)
|
| 220 |
+
|
| 221 |
+
result = df.interpolate(method="slinear")
|
| 222 |
+
expected.loc[3, "A"] = 2.66666667
|
| 223 |
+
expected.loc[13, "A"] = 5.76923077
|
| 224 |
+
tm.assert_frame_equal(result, expected)
|
| 225 |
+
|
| 226 |
+
result = df.interpolate(method="zero")
|
| 227 |
+
expected.loc[3, "A"] = 2.0
|
| 228 |
+
expected.loc[13, "A"] = 5
|
| 229 |
+
tm.assert_frame_equal(result, expected, check_dtype=False)
|
| 230 |
+
|
| 231 |
+
def test_interp_alt_scipy(self):
|
| 232 |
+
pytest.importorskip("scipy")
|
| 233 |
+
df = pd.DataFrame(
|
| 234 |
+
{"A": [1, 2, np.nan, 4, 5, np.nan, 7], "C": [1, 2, 3, 5, 8, 13, 21]}
|
| 235 |
+
)
|
| 236 |
+
result = df.interpolate(method="barycentric")
|
| 237 |
+
expected = df.copy()
|
| 238 |
+
expected.loc[2, "A"] = 3
|
| 239 |
+
expected.loc[5, "A"] = 6
|
| 240 |
+
tm.assert_frame_equal(result, expected)
|
| 241 |
+
|
| 242 |
+
result = df.interpolate(method="krogh")
|
| 243 |
+
expectedk = df.copy()
|
| 244 |
+
expectedk["A"] = expected["A"]
|
| 245 |
+
tm.assert_frame_equal(result, expectedk)
|
| 246 |
+
|
| 247 |
+
result = df.interpolate(method="pchip")
|
| 248 |
+
expected.loc[2, "A"] = 3
|
| 249 |
+
expected.loc[5, "A"] = 6.0
|
| 250 |
+
|
| 251 |
+
tm.assert_frame_equal(result, expected)
|
| 252 |
+
|
| 253 |
+
def test_interp_rowwise(self):
|
| 254 |
+
df = pd.DataFrame(
|
| 255 |
+
{
|
| 256 |
+
0: [1, 2, np.nan, 4],
|
| 257 |
+
1: [2, 3, 4, np.nan],
|
| 258 |
+
2: [np.nan, 4, 5, 6],
|
| 259 |
+
3: [4, np.nan, 6, 7],
|
| 260 |
+
4: [1, 2, 3, 4],
|
| 261 |
+
}
|
| 262 |
+
)
|
| 263 |
+
result = df.interpolate(axis=1)
|
| 264 |
+
expected = df.copy()
|
| 265 |
+
expected.loc[3, 1] = 5
|
| 266 |
+
expected.loc[0, 2] = 3
|
| 267 |
+
expected.loc[1, 3] = 3
|
| 268 |
+
expected[4] = expected[4].astype(np.float64)
|
| 269 |
+
tm.assert_frame_equal(result, expected)
|
| 270 |
+
|
| 271 |
+
result = df.interpolate(axis=1, method="values")
|
| 272 |
+
tm.assert_frame_equal(result, expected)
|
| 273 |
+
|
| 274 |
+
result = df.interpolate(axis=0)
|
| 275 |
+
expected = df.interpolate()
|
| 276 |
+
tm.assert_frame_equal(result, expected)
|
| 277 |
+
|
| 278 |
+
@pytest.mark.parametrize(
|
| 279 |
+
"axis_name, axis_number",
|
| 280 |
+
[
|
| 281 |
+
pytest.param("rows", 0, id="rows_0"),
|
| 282 |
+
pytest.param("index", 0, id="index_0"),
|
| 283 |
+
pytest.param("columns", 1, id="columns_1"),
|
| 284 |
+
],
|
| 285 |
+
)
|
| 286 |
+
def test_interp_axis_names(self, axis_name, axis_number):
|
| 287 |
+
# GH 29132: test axis names
|
| 288 |
+
data = {0: [0, np.nan, 6], 1: [1, np.nan, 7], 2: [2, 5, 8]}
|
| 289 |
+
|
| 290 |
+
df = pd.DataFrame(data, dtype=np.float64)
|
| 291 |
+
result = df.interpolate(axis=axis_name, method="linear")
|
| 292 |
+
expected = df.interpolate(axis=axis_number, method="linear")
|
| 293 |
+
tm.assert_frame_equal(result, expected)
|
| 294 |
+
|
| 295 |
+
def test_rowwise_alt(self):
|
| 296 |
+
df = pd.DataFrame(
|
| 297 |
+
{
|
| 298 |
+
0: [0, 0.5, 1.0, np.nan, 4, 8, np.nan, np.nan, 64],
|
| 299 |
+
1: [1, 2, 3, 4, 3, 2, 1, 0, -1],
|
| 300 |
+
}
|
| 301 |
+
)
|
| 302 |
+
df.interpolate(axis=0)
|
| 303 |
+
# TODO: assert something?
|
| 304 |
+
|
| 305 |
+
@pytest.mark.parametrize(
|
| 306 |
+
"check_scipy", [False, pytest.param(True, marks=td.skip_if_no("scipy"))]
|
| 307 |
+
)
|
| 308 |
+
def test_interp_leading_nans(self, check_scipy):
|
| 309 |
+
df = pd.DataFrame(
|
| 310 |
+
{"A": [np.nan, np.nan, 0.5, 0.25, 0], "B": [np.nan, -3, -3.5, np.nan, -4]}
|
| 311 |
+
)
|
| 312 |
+
result = df.interpolate()
|
| 313 |
+
expected = df.copy()
|
| 314 |
+
expected.loc[3, "B"] = -3.75
|
| 315 |
+
tm.assert_frame_equal(result, expected)
|
| 316 |
+
|
| 317 |
+
if check_scipy:
|
| 318 |
+
result = df.interpolate(method="polynomial", order=1)
|
| 319 |
+
tm.assert_frame_equal(result, expected)
|
| 320 |
+
|
| 321 |
+
def test_interp_raise_on_only_mixed(self, axis):
|
| 322 |
+
df = pd.DataFrame(
|
| 323 |
+
{
|
| 324 |
+
"A": [1, 2, np.nan, 4],
|
| 325 |
+
"B": ["a", "b", "c", "d"],
|
| 326 |
+
"C": [np.nan, 2, 5, 7],
|
| 327 |
+
"D": [np.nan, np.nan, 9, 9],
|
| 328 |
+
"E": [1, 2, 3, 4],
|
| 329 |
+
}
|
| 330 |
+
)
|
| 331 |
+
msg = "DataFrame cannot interpolate with object dtype"
|
| 332 |
+
with pytest.raises(TypeError, match=msg):
|
| 333 |
+
df.astype("object").interpolate(axis=axis)
|
| 334 |
+
|
| 335 |
+
def test_interp_raise_on_all_object_dtype(self):
|
| 336 |
+
# GH 22985
|
| 337 |
+
df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}, dtype="object")
|
| 338 |
+
msg = "DataFrame cannot interpolate with object dtype"
|
| 339 |
+
with pytest.raises(TypeError, match=msg):
|
| 340 |
+
df.interpolate()
|
| 341 |
+
|
| 342 |
+
def test_interp_inplace(self):
|
| 343 |
+
df = pd.DataFrame({"a": [1.0, 2.0, np.nan, 4.0]})
|
| 344 |
+
df_orig = df.copy()
|
| 345 |
+
expected = df.copy().interpolate()
|
| 346 |
+
|
| 347 |
+
with tm.raises_chained_assignment_error():
|
| 348 |
+
result = df["a"].interpolate(inplace=True)
|
| 349 |
+
tm.assert_series_equal(result, expected["a"])
|
| 350 |
+
tm.assert_frame_equal(df, df_orig)
|
| 351 |
+
|
| 352 |
+
def test_interp_inplace_row(self):
|
| 353 |
+
# GH 10395
|
| 354 |
+
df = pd.DataFrame(
|
| 355 |
+
{"a": [1.0, 2.0, 3.0, 4.0], "b": [np.nan, 2.0, 3.0, 4.0], "c": [3, 2, 2, 2]}
|
| 356 |
+
)
|
| 357 |
+
expected = df.interpolate(method="linear", axis=1, inplace=False)
|
| 358 |
+
result = df.interpolate(method="linear", axis=1, inplace=True)
|
| 359 |
+
assert result is df
|
| 360 |
+
tm.assert_frame_equal(result, expected)
|
| 361 |
+
|
| 362 |
+
def test_interp_ignore_all_good(self):
|
| 363 |
+
# GH#6290
|
| 364 |
+
df = pd.DataFrame(
|
| 365 |
+
{
|
| 366 |
+
"A": [1, 2, np.nan, 4],
|
| 367 |
+
"B": [1, 2, 3, 4],
|
| 368 |
+
"C": [1.0, 2.0, np.nan, 4.0],
|
| 369 |
+
"D": [1.0, 2.0, 3.0, 4.0],
|
| 370 |
+
}
|
| 371 |
+
)
|
| 372 |
+
expected = pd.DataFrame(
|
| 373 |
+
{
|
| 374 |
+
"A": np.array([1, 2, 3, 4], dtype="float64"),
|
| 375 |
+
"B": np.array([1, 2, 3, 4], dtype="int64"),
|
| 376 |
+
"C": np.array([1.0, 2.0, 3, 4.0], dtype="float64"),
|
| 377 |
+
"D": np.array([1.0, 2.0, 3.0, 4.0], dtype="float64"),
|
| 378 |
+
}
|
| 379 |
+
)
|
| 380 |
+
result = df.interpolate()
|
| 381 |
+
tm.assert_frame_equal(result, expected)
|
| 382 |
+
|
| 383 |
+
# all good
|
| 384 |
+
result = df[["B", "D"]].interpolate()
|
| 385 |
+
tm.assert_frame_equal(result, df[["B", "D"]])
|
| 386 |
+
|
| 387 |
+
def test_interp_time_inplace_axis(self):
|
| 388 |
+
# GH 9687
|
| 389 |
+
periods = 5
|
| 390 |
+
idx = pd.date_range(start="2014-01-01", periods=periods)
|
| 391 |
+
data = np.random.default_rng(2).random((periods, periods))
|
| 392 |
+
data[data < 0.5] = np.nan
|
| 393 |
+
df = pd.DataFrame(index=idx, columns=idx, data=data)
|
| 394 |
+
|
| 395 |
+
expected = df.interpolate(axis=0, method="time")
|
| 396 |
+
result = df.interpolate(axis=0, method="time", inplace=True)
|
| 397 |
+
assert result is df
|
| 398 |
+
tm.assert_frame_equal(result, expected)
|
| 399 |
+
|
| 400 |
+
@pytest.mark.parametrize("axis_name, axis_number", [("index", 0), ("columns", 1)])
|
| 401 |
+
def test_interp_string_axis(self, axis_name, axis_number):
|
| 402 |
+
# https://github.com/pandas-dev/pandas/issues/25190
|
| 403 |
+
x = np.linspace(0, 100, 3)
|
| 404 |
+
y = np.sin(x)
|
| 405 |
+
df = pd.DataFrame(
|
| 406 |
+
data=np.tile(y, (10, 1)), index=np.arange(10), columns=x
|
| 407 |
+
).reindex(columns=x * 1.005)
|
| 408 |
+
result = df.interpolate(method="linear", axis=axis_name)
|
| 409 |
+
expected = df.interpolate(method="linear", axis=axis_number)
|
| 410 |
+
tm.assert_frame_equal(result, expected)
|
| 411 |
+
|
| 412 |
+
@pytest.mark.parametrize("multiblock", [True, False])
|
| 413 |
+
@pytest.mark.parametrize("method", ["ffill", "bfill", "pad"])
|
| 414 |
+
def test_interp_fillna_methods(self, axis, multiblock, method):
|
| 415 |
+
# GH 12918
|
| 416 |
+
df = pd.DataFrame(
|
| 417 |
+
{
|
| 418 |
+
"A": [1.0, 2.0, 3.0, 4.0, np.nan, 5.0],
|
| 419 |
+
"B": [2.0, 4.0, 6.0, np.nan, 8.0, 10.0],
|
| 420 |
+
"C": [3.0, 6.0, 9.0, np.nan, np.nan, 30.0],
|
| 421 |
+
}
|
| 422 |
+
)
|
| 423 |
+
if multiblock:
|
| 424 |
+
df["D"] = np.nan
|
| 425 |
+
df["E"] = 1.0
|
| 426 |
+
|
| 427 |
+
msg = f"Can not interpolate with method={method}"
|
| 428 |
+
with pytest.raises(ValueError, match=msg):
|
| 429 |
+
df.interpolate(method=method, axis=axis)
|
| 430 |
+
|
| 431 |
+
def test_interpolate_empty_df(self):
|
| 432 |
+
# GH#53199
|
| 433 |
+
df = pd.DataFrame()
|
| 434 |
+
expected = df.copy()
|
| 435 |
+
result = df.interpolate(inplace=True)
|
| 436 |
+
assert result is df
|
| 437 |
+
tm.assert_frame_equal(result, expected)
|
| 438 |
+
|
| 439 |
+
def test_interpolate_ea(self, any_int_ea_dtype):
|
| 440 |
+
# GH#55347
|
| 441 |
+
df = pd.DataFrame({"a": [1, None, None, None, 3]}, dtype=any_int_ea_dtype)
|
| 442 |
+
orig = df.copy()
|
| 443 |
+
result = df.interpolate(limit=2)
|
| 444 |
+
expected = pd.DataFrame({"a": [1, 1.5, 2.0, None, 3]}, dtype="Float64")
|
| 445 |
+
tm.assert_frame_equal(result, expected)
|
| 446 |
+
tm.assert_frame_equal(df, orig)
|
| 447 |
+
|
| 448 |
+
@pytest.mark.parametrize(
|
| 449 |
+
"dtype",
|
| 450 |
+
[
|
| 451 |
+
"Float64",
|
| 452 |
+
"Float32",
|
| 453 |
+
pytest.param("float32[pyarrow]", marks=td.skip_if_no("pyarrow")),
|
| 454 |
+
pytest.param("float64[pyarrow]", marks=td.skip_if_no("pyarrow")),
|
| 455 |
+
],
|
| 456 |
+
)
|
| 457 |
+
def test_interpolate_ea_float(self, dtype):
|
| 458 |
+
# GH#55347
|
| 459 |
+
df = pd.DataFrame({"a": [1, None, None, None, 3]}, dtype=dtype)
|
| 460 |
+
orig = df.copy()
|
| 461 |
+
result = df.interpolate(limit=2)
|
| 462 |
+
expected = pd.DataFrame({"a": [1, 1.5, 2.0, None, 3]}, dtype=dtype)
|
| 463 |
+
tm.assert_frame_equal(result, expected)
|
| 464 |
+
tm.assert_frame_equal(df, orig)
|
| 465 |
+
|
| 466 |
+
@pytest.mark.parametrize(
|
| 467 |
+
"dtype",
|
| 468 |
+
["int64", "uint64", "int32", "int16", "int8", "uint32", "uint16", "uint8"],
|
| 469 |
+
)
|
| 470 |
+
def test_interpolate_arrow(self, dtype):
|
| 471 |
+
# GH#55347
|
| 472 |
+
pytest.importorskip("pyarrow")
|
| 473 |
+
df = pd.DataFrame({"a": [1, None, None, None, 3]}, dtype=dtype + "[pyarrow]")
|
| 474 |
+
result = df.interpolate(limit=2)
|
| 475 |
+
expected = pd.DataFrame({"a": [1, 1.5, 2.0, None, 3]}, dtype="float64[pyarrow]")
|
| 476 |
+
tm.assert_frame_equal(result, expected)
|
| 477 |
+
|
| 478 |
+
@pytest.mark.parametrize(
|
| 479 |
+
"dtype",
|
| 480 |
+
[
|
| 481 |
+
"Int64",
|
| 482 |
+
"Float64",
|
| 483 |
+
],
|
| 484 |
+
)
|
| 485 |
+
def test_interpolate_time_nullable_int_float(self, dtype):
|
| 486 |
+
# GH#40252
|
| 487 |
+
idx = pd.date_range("1970-01-02", periods=3, freq="D")
|
| 488 |
+
|
| 489 |
+
df = pd.DataFrame({"a": [1, None, 2]}, index=idx, dtype=dtype)
|
| 490 |
+
result = df.interpolate(method="time")
|
| 491 |
+
expected = pd.DataFrame({"a": [1.0, 1.5, 2.0]}, index=idx, dtype="Float64")
|
| 492 |
+
tm.assert_frame_equal(result, expected)
|
venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_is_homogeneous_dtype.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import pytest
|
| 3 |
+
|
| 4 |
+
import pandas as pd
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
@pytest.mark.parametrize(
|
| 8 |
+
"data, expected",
|
| 9 |
+
[
|
| 10 |
+
# empty
|
| 11 |
+
(pd.DataFrame(), True),
|
| 12 |
+
# multi-same
|
| 13 |
+
(pd.DataFrame({"A": [1, 2], "B": [1, 2]}), True),
|
| 14 |
+
# multi-object
|
| 15 |
+
(
|
| 16 |
+
pd.DataFrame(
|
| 17 |
+
{
|
| 18 |
+
"A": np.array([1, 2], dtype=object),
|
| 19 |
+
"B": np.array(["a", "b"], dtype=object),
|
| 20 |
+
},
|
| 21 |
+
dtype="object",
|
| 22 |
+
),
|
| 23 |
+
True,
|
| 24 |
+
),
|
| 25 |
+
# multi-extension
|
| 26 |
+
(
|
| 27 |
+
pd.DataFrame(
|
| 28 |
+
{"A": pd.Categorical(["a", "b"]), "B": pd.Categorical(["a", "b"])}
|
| 29 |
+
),
|
| 30 |
+
True,
|
| 31 |
+
),
|
| 32 |
+
# differ types
|
| 33 |
+
(pd.DataFrame({"A": [1, 2], "B": [1.0, 2.0]}), False),
|
| 34 |
+
# differ sizes
|
| 35 |
+
(
|
| 36 |
+
pd.DataFrame(
|
| 37 |
+
{
|
| 38 |
+
"A": np.array([1, 2], dtype=np.int32),
|
| 39 |
+
"B": np.array([1, 2], dtype=np.int64),
|
| 40 |
+
}
|
| 41 |
+
),
|
| 42 |
+
False,
|
| 43 |
+
),
|
| 44 |
+
# multi-extension differ
|
| 45 |
+
(
|
| 46 |
+
pd.DataFrame(
|
| 47 |
+
{"A": pd.Categorical(["a", "b"]), "B": pd.Categorical(["b", "c"])}
|
| 48 |
+
),
|
| 49 |
+
False,
|
| 50 |
+
),
|
| 51 |
+
],
|
| 52 |
+
)
|
| 53 |
+
def test_is_homogeneous_type(data, expected):
|
| 54 |
+
assert data._is_homogeneous_type is expected
|
venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_isetitem.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import pytest
|
| 3 |
+
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import pandas._testing as tm
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class TestDataFrameSetItem:
|
| 9 |
+
def test_isetitem_ea_df(self):
|
| 10 |
+
# GH#49922
|
| 11 |
+
df = pd.DataFrame([[1, 2, 3], [4, 5, 6]])
|
| 12 |
+
rhs = pd.DataFrame([[11, 12], [13, 14]], dtype="Int64")
|
| 13 |
+
|
| 14 |
+
df.isetitem([0, 1], rhs)
|
| 15 |
+
expected = pd.DataFrame(
|
| 16 |
+
{
|
| 17 |
+
0: pd.Series([11, 13], dtype="Int64"),
|
| 18 |
+
1: pd.Series([12, 14], dtype="Int64"),
|
| 19 |
+
2: [3, 6],
|
| 20 |
+
}
|
| 21 |
+
)
|
| 22 |
+
tm.assert_frame_equal(df, expected)
|
| 23 |
+
|
| 24 |
+
def test_isetitem_ea_df_scalar_indexer(self):
|
| 25 |
+
# GH#49922
|
| 26 |
+
df = pd.DataFrame([[1, 2, 3], [4, 5, 6]])
|
| 27 |
+
rhs = pd.DataFrame([[11], [13]], dtype="Int64")
|
| 28 |
+
|
| 29 |
+
df.isetitem(2, rhs)
|
| 30 |
+
expected = pd.DataFrame(
|
| 31 |
+
{
|
| 32 |
+
0: [1, 4],
|
| 33 |
+
1: [2, 5],
|
| 34 |
+
2: pd.Series([11, 13], dtype="Int64"),
|
| 35 |
+
}
|
| 36 |
+
)
|
| 37 |
+
tm.assert_frame_equal(df, expected)
|
| 38 |
+
|
| 39 |
+
def test_isetitem_dimension_mismatch(self):
|
| 40 |
+
# GH#51701
|
| 41 |
+
df = pd.DataFrame({"a": [1, 2], "b": [3, 4], "c": [5, 6]})
|
| 42 |
+
value = df.copy()
|
| 43 |
+
with pytest.raises(ValueError, match="Got 2 positions but value has 3 columns"):
|
| 44 |
+
df.isetitem([1, 2], value)
|
| 45 |
+
|
| 46 |
+
value = df.copy()
|
| 47 |
+
with pytest.raises(ValueError, match="Got 2 positions but value has 1 columns"):
|
| 48 |
+
df.isetitem([1, 2], value[["a"]])
|
| 49 |
+
|
| 50 |
+
@pytest.mark.parametrize("loc", [[1, 0], [2, 0, 1], [3, 1, 0]])
|
| 51 |
+
def test_isetitem_unsorted_loc(self, loc):
|
| 52 |
+
# GH#68930 Block.delete assumes increasing locs, so an out-of-order loc
|
| 53 |
+
# that replaces only part of a block used to leave stale blocks behind
|
| 54 |
+
df = pd.DataFrame({"a": [1, 2], "b": [3, 4], "c": [5, 6], "d": [7, 8]})
|
| 55 |
+
value = np.arange(100, 100 + 2 * len(loc)).reshape(len(loc), 2).T
|
| 56 |
+
|
| 57 |
+
df.isetitem(loc, value)
|
| 58 |
+
|
| 59 |
+
expected = pd.DataFrame({"a": [1, 2], "b": [3, 4], "c": [5, 6], "d": [7, 8]})
|
| 60 |
+
for i, pos in enumerate(loc):
|
| 61 |
+
expected.isetitem(pos, value[:, i])
|
| 62 |
+
tm.assert_frame_equal(df, expected)
|
| 63 |
+
# values read back fine even when corrupt; this is what fails on revert
|
| 64 |
+
df.describe()
|
venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_isin.py
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
| 3 |
+
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import pandas._testing as tm
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class TestDataFrameIsIn:
|
| 9 |
+
def test_isin(self):
|
| 10 |
+
# GH#4211
|
| 11 |
+
df = pd.DataFrame(
|
| 12 |
+
{
|
| 13 |
+
"vals": [1, 2, 3, 4],
|
| 14 |
+
"ids": ["a", "b", "f", "n"],
|
| 15 |
+
"ids2": ["a", "n", "c", "n"],
|
| 16 |
+
},
|
| 17 |
+
index=["foo", "bar", "baz", "qux"],
|
| 18 |
+
)
|
| 19 |
+
other = ["a", "b", "c"]
|
| 20 |
+
|
| 21 |
+
result = df.isin(other)
|
| 22 |
+
expected = pd.DataFrame([df.loc[s].isin(other) for s in df.index])
|
| 23 |
+
tm.assert_frame_equal(result, expected)
|
| 24 |
+
|
| 25 |
+
@pytest.mark.parametrize("empty", [[], pd.Series(dtype=object), np.array([])])
|
| 26 |
+
def test_isin_empty(self, empty):
|
| 27 |
+
# GH#16991
|
| 28 |
+
df = pd.DataFrame({"A": ["a", "b", "c"], "B": ["a", "e", "f"]})
|
| 29 |
+
expected = pd.DataFrame(False, df.index, df.columns)
|
| 30 |
+
|
| 31 |
+
result = df.isin(empty)
|
| 32 |
+
tm.assert_frame_equal(result, expected)
|
| 33 |
+
|
| 34 |
+
def test_isin_dict(self):
|
| 35 |
+
df = pd.DataFrame({"A": ["a", "b", "c"], "B": ["a", "e", "f"]})
|
| 36 |
+
d = {"A": ["a"]}
|
| 37 |
+
|
| 38 |
+
expected = pd.DataFrame(False, df.index, df.columns)
|
| 39 |
+
expected.loc[0, "A"] = True
|
| 40 |
+
|
| 41 |
+
result = df.isin(d)
|
| 42 |
+
tm.assert_frame_equal(result, expected)
|
| 43 |
+
|
| 44 |
+
# non unique columns
|
| 45 |
+
df = pd.DataFrame({"A": ["a", "b", "c"], "B": ["a", "e", "f"]})
|
| 46 |
+
df.columns = ["A", "A"]
|
| 47 |
+
expected = pd.DataFrame(False, df.index, df.columns)
|
| 48 |
+
expected.loc[0, "A"] = True
|
| 49 |
+
result = df.isin(d)
|
| 50 |
+
tm.assert_frame_equal(result, expected)
|
| 51 |
+
|
| 52 |
+
def test_isin_with_string_scalar(self):
|
| 53 |
+
# GH#4763
|
| 54 |
+
df = pd.DataFrame(
|
| 55 |
+
{
|
| 56 |
+
"vals": [1, 2, 3, 4],
|
| 57 |
+
"ids": ["a", "b", "f", "n"],
|
| 58 |
+
"ids2": ["a", "n", "c", "n"],
|
| 59 |
+
},
|
| 60 |
+
index=["foo", "bar", "baz", "qux"],
|
| 61 |
+
)
|
| 62 |
+
msg = (
|
| 63 |
+
r"only list-like or dict-like objects are allowed "
|
| 64 |
+
r"to be passed to DataFrame.isin\(\), you passed a 'str'"
|
| 65 |
+
)
|
| 66 |
+
with pytest.raises(TypeError, match=msg):
|
| 67 |
+
df.isin("a")
|
| 68 |
+
|
| 69 |
+
with pytest.raises(TypeError, match=msg):
|
| 70 |
+
df.isin("aaa")
|
| 71 |
+
|
| 72 |
+
def test_isin_df(self):
|
| 73 |
+
df1 = pd.DataFrame({"A": [1, 2, 3, 4], "B": [2, np.nan, 4, 4]})
|
| 74 |
+
df2 = pd.DataFrame({"A": [0, 2, 12, 4], "B": [2, np.nan, 4, 5]})
|
| 75 |
+
expected = pd.DataFrame(False, df1.index, df1.columns)
|
| 76 |
+
result = df1.isin(df2)
|
| 77 |
+
expected.loc[[1, 3], "A"] = True
|
| 78 |
+
expected.loc[[0, 2], "B"] = True
|
| 79 |
+
tm.assert_frame_equal(result, expected)
|
| 80 |
+
|
| 81 |
+
# partial overlapping columns
|
| 82 |
+
df2.columns = ["A", "C"]
|
| 83 |
+
result = df1.isin(df2)
|
| 84 |
+
expected["B"] = False
|
| 85 |
+
tm.assert_frame_equal(result, expected)
|
| 86 |
+
|
| 87 |
+
def test_isin_tuples(self):
|
| 88 |
+
# GH#16394
|
| 89 |
+
df = pd.DataFrame({"A": [1, 2, 3], "B": ["a", "b", "f"]})
|
| 90 |
+
df["C"] = list(zip(df["A"], df["B"], strict=True))
|
| 91 |
+
result = df["C"].isin([(1, "a")])
|
| 92 |
+
tm.assert_series_equal(result, pd.Series([True, False, False], name="C"))
|
| 93 |
+
|
| 94 |
+
def test_isin_df_dupe_values(self):
|
| 95 |
+
df1 = pd.DataFrame({"A": [1, 2, 3, 4], "B": [2, np.nan, 4, 4]})
|
| 96 |
+
# just cols duped
|
| 97 |
+
df2 = pd.DataFrame([[0, 2], [12, 4], [2, np.nan], [4, 5]], columns=["B", "B"])
|
| 98 |
+
msg = r"cannot compute isin with a duplicate axis\."
|
| 99 |
+
with pytest.raises(ValueError, match=msg):
|
| 100 |
+
df1.isin(df2)
|
| 101 |
+
|
| 102 |
+
# just index duped
|
| 103 |
+
df2 = pd.DataFrame(
|
| 104 |
+
[[0, 2], [12, 4], [2, np.nan], [4, 5]],
|
| 105 |
+
columns=["A", "B"],
|
| 106 |
+
index=[0, 0, 1, 1],
|
| 107 |
+
)
|
| 108 |
+
with pytest.raises(ValueError, match=msg):
|
| 109 |
+
df1.isin(df2)
|
| 110 |
+
|
| 111 |
+
# cols and index:
|
| 112 |
+
df2.columns = ["B", "B"]
|
| 113 |
+
with pytest.raises(ValueError, match=msg):
|
| 114 |
+
df1.isin(df2)
|
| 115 |
+
|
| 116 |
+
def test_isin_dupe_self(self):
|
| 117 |
+
other = pd.DataFrame({"A": [1, 0, 1, 0], "B": [1, 1, 0, 0]})
|
| 118 |
+
df = pd.DataFrame([[1, 1], [1, 0], [0, 0]], columns=["A", "A"])
|
| 119 |
+
result = df.isin(other)
|
| 120 |
+
expected = pd.DataFrame(False, index=df.index, columns=df.columns)
|
| 121 |
+
expected.loc[0] = True
|
| 122 |
+
expected.iloc[1, 1] = True
|
| 123 |
+
tm.assert_frame_equal(result, expected)
|
| 124 |
+
|
| 125 |
+
def test_isin_against_series(self):
|
| 126 |
+
df = pd.DataFrame(
|
| 127 |
+
{"A": [1, 2, 3, 4], "B": [2, np.nan, 4, 4]}, index=["a", "b", "c", "d"]
|
| 128 |
+
)
|
| 129 |
+
s = pd.Series([1, 3, 11, 4], index=["a", "b", "c", "d"])
|
| 130 |
+
expected = pd.DataFrame(False, index=df.index, columns=df.columns)
|
| 131 |
+
expected.loc["a", "A"] = True
|
| 132 |
+
expected.loc["d"] = True
|
| 133 |
+
result = df.isin(s)
|
| 134 |
+
tm.assert_frame_equal(result, expected)
|
| 135 |
+
|
| 136 |
+
def test_isin_multiIndex(self):
|
| 137 |
+
idx = pd.MultiIndex.from_tuples(
|
| 138 |
+
[
|
| 139 |
+
(0, "a", "foo"),
|
| 140 |
+
(0, "a", "bar"),
|
| 141 |
+
(0, "b", "bar"),
|
| 142 |
+
(0, "b", "baz"),
|
| 143 |
+
(2, "a", "foo"),
|
| 144 |
+
(2, "a", "bar"),
|
| 145 |
+
(2, "c", "bar"),
|
| 146 |
+
(2, "c", "baz"),
|
| 147 |
+
(1, "b", "foo"),
|
| 148 |
+
(1, "b", "bar"),
|
| 149 |
+
(1, "c", "bar"),
|
| 150 |
+
(1, "c", "baz"),
|
| 151 |
+
]
|
| 152 |
+
)
|
| 153 |
+
df1 = pd.DataFrame({"A": np.ones(12), "B": np.zeros(12)}, index=idx)
|
| 154 |
+
df2 = pd.DataFrame(
|
| 155 |
+
{
|
| 156 |
+
"A": [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1],
|
| 157 |
+
"B": [1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1],
|
| 158 |
+
}
|
| 159 |
+
)
|
| 160 |
+
# against regular index
|
| 161 |
+
expected = pd.DataFrame(False, index=df1.index, columns=df1.columns)
|
| 162 |
+
result = df1.isin(df2)
|
| 163 |
+
tm.assert_frame_equal(result, expected)
|
| 164 |
+
|
| 165 |
+
df2.index = idx
|
| 166 |
+
expected = df2.values.astype(bool)
|
| 167 |
+
expected[:, 1] = ~expected[:, 1]
|
| 168 |
+
expected = pd.DataFrame(expected, columns=["A", "B"], index=idx)
|
| 169 |
+
|
| 170 |
+
result = df1.isin(df2)
|
| 171 |
+
tm.assert_frame_equal(result, expected)
|
| 172 |
+
|
| 173 |
+
def test_isin_empty_datetimelike(self):
|
| 174 |
+
# GH#15473
|
| 175 |
+
df1_ts = pd.DataFrame({"date": pd.to_datetime(["2014-01-01", "2014-01-02"])})
|
| 176 |
+
df1_td = pd.DataFrame({"date": [pd.Timedelta(1, "s"), pd.Timedelta(2, "s")]})
|
| 177 |
+
df2 = pd.DataFrame({"date": []})
|
| 178 |
+
df3 = pd.DataFrame()
|
| 179 |
+
|
| 180 |
+
expected = pd.DataFrame({"date": [False, False]})
|
| 181 |
+
|
| 182 |
+
result = df1_ts.isin(df2)
|
| 183 |
+
tm.assert_frame_equal(result, expected)
|
| 184 |
+
result = df1_ts.isin(df3)
|
| 185 |
+
tm.assert_frame_equal(result, expected)
|
| 186 |
+
|
| 187 |
+
result = df1_td.isin(df2)
|
| 188 |
+
tm.assert_frame_equal(result, expected)
|
| 189 |
+
result = df1_td.isin(df3)
|
| 190 |
+
tm.assert_frame_equal(result, expected)
|
| 191 |
+
|
| 192 |
+
@pytest.mark.parametrize(
|
| 193 |
+
"values",
|
| 194 |
+
[
|
| 195 |
+
pd.DataFrame({"a": [1, 2, 3]}, dtype="category"),
|
| 196 |
+
pd.Series([1, 2, 3], dtype="category"),
|
| 197 |
+
],
|
| 198 |
+
)
|
| 199 |
+
def test_isin_category_frame(self, values):
|
| 200 |
+
# GH#34256
|
| 201 |
+
df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
|
| 202 |
+
expected = pd.DataFrame({"a": [True, True, True], "b": [False, False, False]})
|
| 203 |
+
|
| 204 |
+
result = df.isin(values)
|
| 205 |
+
tm.assert_frame_equal(result, expected)
|
| 206 |
+
|
| 207 |
+
def test_isin_read_only(self):
|
| 208 |
+
# https://github.com/pandas-dev/pandas/issues/37174
|
| 209 |
+
arr = np.array([1, 2, 3])
|
| 210 |
+
arr.setflags(write=False)
|
| 211 |
+
df = pd.DataFrame([1, 2, 3])
|
| 212 |
+
result = df.isin(arr)
|
| 213 |
+
expected = pd.DataFrame([True, True, True])
|
| 214 |
+
tm.assert_frame_equal(result, expected)
|
| 215 |
+
|
| 216 |
+
def test_isin_not_lossy(self):
|
| 217 |
+
# GH 53514
|
| 218 |
+
val = 1666880195890293744
|
| 219 |
+
df = pd.DataFrame({"a": [val], "b": [1.0]})
|
| 220 |
+
result = df.isin([val])
|
| 221 |
+
expected = pd.DataFrame({"a": [True], "b": [False]})
|
| 222 |
+
tm.assert_frame_equal(result, expected)
|
venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_iterrows.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def test_no_overflow_of_freq_and_time_in_dataframe():
|
| 5 |
+
# GH 35665
|
| 6 |
+
df = pd.DataFrame(
|
| 7 |
+
{
|
| 8 |
+
"some_string": ["2222Y3"],
|
| 9 |
+
"time": [pd.Timedelta("0 days 00:00:00.990000")],
|
| 10 |
+
}
|
| 11 |
+
)
|
| 12 |
+
for _, row in df.iterrows():
|
| 13 |
+
assert row.dtype == "object"
|
venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_join.py
ADDED
|
@@ -0,0 +1,599 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from datetime import datetime
|
| 2 |
+
import re
|
| 3 |
+
import zoneinfo
|
| 4 |
+
|
| 5 |
+
import numpy as np
|
| 6 |
+
import pytest
|
| 7 |
+
|
| 8 |
+
from pandas.errors import MergeError
|
| 9 |
+
|
| 10 |
+
import pandas as pd
|
| 11 |
+
import pandas._testing as tm
|
| 12 |
+
from pandas.core.reshape.concat import concat
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
@pytest.fixture
|
| 16 |
+
def left_no_dup():
|
| 17 |
+
return pd.DataFrame(
|
| 18 |
+
{"a": ["a", "b", "c", "d"], "b": ["cat", "dog", "weasel", "horse"]},
|
| 19 |
+
index=range(4),
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
@pytest.fixture
|
| 24 |
+
def right_no_dup():
|
| 25 |
+
return pd.DataFrame(
|
| 26 |
+
{
|
| 27 |
+
"a": ["a", "b", "c", "d", "e"],
|
| 28 |
+
"c": ["meow", "bark", "um... weasel noise?", "nay", "chirp"],
|
| 29 |
+
},
|
| 30 |
+
index=range(5),
|
| 31 |
+
).set_index("a")
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
@pytest.fixture
|
| 35 |
+
def left_w_dups(left_no_dup):
|
| 36 |
+
return concat(
|
| 37 |
+
[left_no_dup, pd.DataFrame({"a": ["a"], "b": ["cow"]}, index=[3])], sort=True
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
@pytest.fixture
|
| 42 |
+
def right_w_dups(right_no_dup):
|
| 43 |
+
return concat(
|
| 44 |
+
[right_no_dup, pd.DataFrame({"a": ["e"], "c": ["moo"]}, index=[3])]
|
| 45 |
+
).set_index("a")
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
@pytest.mark.parametrize(
|
| 49 |
+
"how, sort, expected",
|
| 50 |
+
[
|
| 51 |
+
("inner", False, pd.DataFrame({"a": [20, 10], "b": [200, 100]}, index=[2, 1])),
|
| 52 |
+
("inner", True, pd.DataFrame({"a": [10, 20], "b": [100, 200]}, index=[1, 2])),
|
| 53 |
+
(
|
| 54 |
+
"left",
|
| 55 |
+
False,
|
| 56 |
+
pd.DataFrame({"a": [20, 10, 0], "b": [200, 100, np.nan]}, index=[2, 1, 0]),
|
| 57 |
+
),
|
| 58 |
+
(
|
| 59 |
+
"left",
|
| 60 |
+
True,
|
| 61 |
+
pd.DataFrame({"a": [0, 10, 20], "b": [np.nan, 100, 200]}, index=[0, 1, 2]),
|
| 62 |
+
),
|
| 63 |
+
(
|
| 64 |
+
"right",
|
| 65 |
+
False,
|
| 66 |
+
pd.DataFrame(
|
| 67 |
+
{"a": [np.nan, 10, 20], "b": [300, 100, 200]}, index=[3, 1, 2]
|
| 68 |
+
),
|
| 69 |
+
),
|
| 70 |
+
(
|
| 71 |
+
"right",
|
| 72 |
+
True,
|
| 73 |
+
pd.DataFrame(
|
| 74 |
+
{"a": [10, 20, np.nan], "b": [100, 200, 300]}, index=[1, 2, 3]
|
| 75 |
+
),
|
| 76 |
+
),
|
| 77 |
+
(
|
| 78 |
+
"outer",
|
| 79 |
+
False,
|
| 80 |
+
pd.DataFrame(
|
| 81 |
+
{"a": [0, 10, 20, np.nan], "b": [np.nan, 100, 200, 300]},
|
| 82 |
+
index=[0, 1, 2, 3],
|
| 83 |
+
),
|
| 84 |
+
),
|
| 85 |
+
(
|
| 86 |
+
"outer",
|
| 87 |
+
True,
|
| 88 |
+
pd.DataFrame(
|
| 89 |
+
{"a": [0, 10, 20, np.nan], "b": [np.nan, 100, 200, 300]},
|
| 90 |
+
index=[0, 1, 2, 3],
|
| 91 |
+
),
|
| 92 |
+
),
|
| 93 |
+
],
|
| 94 |
+
)
|
| 95 |
+
def test_join(how, sort, expected):
|
| 96 |
+
left = pd.DataFrame({"a": [20, 10, 0]}, index=[2, 1, 0])
|
| 97 |
+
right = pd.DataFrame({"b": [300, 100, 200]}, index=[3, 1, 2])
|
| 98 |
+
result = left.join(right, how=how, sort=sort, validate="1:1")
|
| 99 |
+
tm.assert_frame_equal(result, expected)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def test_suffix_on_list_join():
|
| 103 |
+
first = pd.DataFrame({"key": [1, 2, 3, 4, 5]})
|
| 104 |
+
second = pd.DataFrame({"key": [1, 8, 3, 2, 5], "v1": [1, 2, 3, 4, 5]})
|
| 105 |
+
third = pd.DataFrame({"keys": [5, 2, 3, 4, 1], "v2": [1, 2, 3, 4, 5]})
|
| 106 |
+
|
| 107 |
+
# check proper errors are raised
|
| 108 |
+
msg = "Suffixes not supported when joining multiple DataFrames"
|
| 109 |
+
with pytest.raises(ValueError, match=msg):
|
| 110 |
+
first.join([second], suffixes=("y", ""))
|
| 111 |
+
with pytest.raises(ValueError, match=msg):
|
| 112 |
+
first.join([second, third], suffixes=("", "x"))
|
| 113 |
+
with pytest.raises(ValueError, match=msg):
|
| 114 |
+
first.join([second, third], suffixes=("y", "x"))
|
| 115 |
+
with pytest.raises(ValueError, match="Indexes have overlapping values"):
|
| 116 |
+
first.join([second, third])
|
| 117 |
+
|
| 118 |
+
# no errors should be raised
|
| 119 |
+
arr_joined = first.join([third])
|
| 120 |
+
norm_joined = first.join(third)
|
| 121 |
+
tm.assert_frame_equal(arr_joined, norm_joined)
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def test_join_lsuffix_rsuffix_deprecated():
|
| 125 |
+
# GH#46046, GH#22231
|
| 126 |
+
df1 = pd.DataFrame({"a": [1, 2], "b": [3, 4]})
|
| 127 |
+
df2 = pd.DataFrame({"b": [5, 6], "c": [7, 8]})
|
| 128 |
+
|
| 129 |
+
msg = "The 'lsuffix' and 'rsuffix' keywords in DataFrame.join are deprecated"
|
| 130 |
+
with tm.assert_produces_warning(pd.errors.Pandas4Warning, match=msg):
|
| 131 |
+
result = df1.join(df2, lsuffix="_left", rsuffix="_right")
|
| 132 |
+
expected = df1.join(df2, suffixes=("_left", "_right"))
|
| 133 |
+
tm.assert_frame_equal(result, expected)
|
| 134 |
+
|
| 135 |
+
# only lsuffix
|
| 136 |
+
with tm.assert_produces_warning(pd.errors.Pandas4Warning, match=msg):
|
| 137 |
+
result = df1.join(df2, lsuffix="_left")
|
| 138 |
+
expected = df1.join(df2, suffixes=("_left", ""))
|
| 139 |
+
tm.assert_frame_equal(result, expected)
|
| 140 |
+
|
| 141 |
+
# Cannot specify both
|
| 142 |
+
with pytest.raises(ValueError, match="Cannot specify both"):
|
| 143 |
+
df1.join(df2, lsuffix="_left", suffixes=("_left", "_right"))
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def test_join_invalid_validate(left_no_dup, right_no_dup):
|
| 147 |
+
# GH 46622
|
| 148 |
+
# Check invalid arguments
|
| 149 |
+
msg = (
|
| 150 |
+
'"invalid" is not a valid argument. '
|
| 151 |
+
"Valid arguments are:\n"
|
| 152 |
+
'- "1:1"\n'
|
| 153 |
+
'- "1:m"\n'
|
| 154 |
+
'- "m:1"\n'
|
| 155 |
+
'- "m:m"\n'
|
| 156 |
+
'- "one_to_one"\n'
|
| 157 |
+
'- "one_to_many"\n'
|
| 158 |
+
'- "many_to_one"\n'
|
| 159 |
+
'- "many_to_many"'
|
| 160 |
+
)
|
| 161 |
+
with pytest.raises(ValueError, match=msg):
|
| 162 |
+
left_no_dup.merge(right_no_dup, on="a", validate="invalid")
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
@pytest.mark.parametrize("dtype", ["object", "string[pyarrow]"])
|
| 166 |
+
def test_join_on_single_col_dup_on_right(left_no_dup, right_w_dups, dtype):
|
| 167 |
+
# GH 46622
|
| 168 |
+
# Dups on right allowed by one_to_many constraint
|
| 169 |
+
if dtype == "string[pyarrow]":
|
| 170 |
+
pytest.importorskip("pyarrow")
|
| 171 |
+
left_no_dup = left_no_dup.astype(dtype)
|
| 172 |
+
right_w_dups.index = right_w_dups.index.astype(dtype)
|
| 173 |
+
left_no_dup.join(
|
| 174 |
+
right_w_dups,
|
| 175 |
+
on="a",
|
| 176 |
+
validate="one_to_many",
|
| 177 |
+
)
|
| 178 |
+
|
| 179 |
+
# Dups on right not allowed by one_to_one constraint
|
| 180 |
+
msg = "Merge keys are not unique in right dataset; not a one-to-one merge"
|
| 181 |
+
with pytest.raises(MergeError, match=msg):
|
| 182 |
+
left_no_dup.join(
|
| 183 |
+
right_w_dups,
|
| 184 |
+
on="a",
|
| 185 |
+
validate="one_to_one",
|
| 186 |
+
)
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
def test_join_on_single_col_dup_on_left(left_w_dups, right_no_dup):
|
| 190 |
+
# GH 46622
|
| 191 |
+
# Dups on left allowed by many_to_one constraint
|
| 192 |
+
left_w_dups.join(
|
| 193 |
+
right_no_dup,
|
| 194 |
+
on="a",
|
| 195 |
+
validate="many_to_one",
|
| 196 |
+
)
|
| 197 |
+
|
| 198 |
+
# Dups on left not allowed by one_to_one constraint
|
| 199 |
+
msg = "Merge keys are not unique in left dataset; not a one-to-one merge"
|
| 200 |
+
with pytest.raises(MergeError, match=msg):
|
| 201 |
+
left_w_dups.join(
|
| 202 |
+
right_no_dup,
|
| 203 |
+
on="a",
|
| 204 |
+
validate="one_to_one",
|
| 205 |
+
)
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
def test_join_on_single_col_dup_on_both(left_w_dups, right_w_dups):
|
| 209 |
+
# GH 46622
|
| 210 |
+
# Dups on both allowed by many_to_many constraint
|
| 211 |
+
left_w_dups.join(right_w_dups, on="a", validate="many_to_many")
|
| 212 |
+
|
| 213 |
+
# Dups on both not allowed by many_to_one constraint
|
| 214 |
+
msg = "Merge keys are not unique in right dataset; not a many-to-one merge"
|
| 215 |
+
with pytest.raises(MergeError, match=msg):
|
| 216 |
+
left_w_dups.join(
|
| 217 |
+
right_w_dups,
|
| 218 |
+
on="a",
|
| 219 |
+
validate="many_to_one",
|
| 220 |
+
)
|
| 221 |
+
|
| 222 |
+
# Dups on both not allowed by one_to_many constraint
|
| 223 |
+
msg = "Merge keys are not unique in left dataset; not a one-to-many merge"
|
| 224 |
+
with pytest.raises(MergeError, match=msg):
|
| 225 |
+
left_w_dups.join(
|
| 226 |
+
right_w_dups,
|
| 227 |
+
on="a",
|
| 228 |
+
validate="one_to_many",
|
| 229 |
+
)
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
def test_join_on_multi_col_check_dup():
|
| 233 |
+
# GH 46622
|
| 234 |
+
# Two column join, dups in both, but jointly no dups
|
| 235 |
+
left = pd.DataFrame(
|
| 236 |
+
{
|
| 237 |
+
"a": ["a", "a", "b", "b"],
|
| 238 |
+
"b": [0, 1, 0, 1],
|
| 239 |
+
"c": ["cat", "dog", "weasel", "horse"],
|
| 240 |
+
},
|
| 241 |
+
index=range(4),
|
| 242 |
+
).set_index(["a", "b"])
|
| 243 |
+
|
| 244 |
+
right = pd.DataFrame(
|
| 245 |
+
{
|
| 246 |
+
"a": ["a", "a", "b"],
|
| 247 |
+
"b": [0, 1, 0],
|
| 248 |
+
"d": ["meow", "bark", "um... weasel noise?"],
|
| 249 |
+
},
|
| 250 |
+
index=range(3),
|
| 251 |
+
).set_index(["a", "b"])
|
| 252 |
+
|
| 253 |
+
expected_multi = pd.DataFrame(
|
| 254 |
+
{
|
| 255 |
+
"a": ["a", "a", "b"],
|
| 256 |
+
"b": [0, 1, 0],
|
| 257 |
+
"c": ["cat", "dog", "weasel"],
|
| 258 |
+
"d": ["meow", "bark", "um... weasel noise?"],
|
| 259 |
+
},
|
| 260 |
+
index=range(3),
|
| 261 |
+
).set_index(["a", "b"])
|
| 262 |
+
|
| 263 |
+
# Jointly no dups allowed by one_to_one constraint
|
| 264 |
+
result = left.join(right, how="inner", validate="1:1")
|
| 265 |
+
tm.assert_frame_equal(result, expected_multi)
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
def test_join_index(float_frame):
|
| 269 |
+
# left / right
|
| 270 |
+
|
| 271 |
+
f = float_frame.loc[float_frame.index[:10], ["A", "B"]]
|
| 272 |
+
f2 = float_frame.loc[float_frame.index[5:], ["C", "D"]].iloc[::-1]
|
| 273 |
+
|
| 274 |
+
joined = f.join(f2)
|
| 275 |
+
tm.assert_index_equal(f.index, joined.index)
|
| 276 |
+
expected_columns = pd.Index(["A", "B", "C", "D"])
|
| 277 |
+
tm.assert_index_equal(joined.columns, expected_columns)
|
| 278 |
+
|
| 279 |
+
joined = f.join(f2, how="left")
|
| 280 |
+
tm.assert_index_equal(joined.index, f.index)
|
| 281 |
+
tm.assert_index_equal(joined.columns, expected_columns)
|
| 282 |
+
|
| 283 |
+
joined = f.join(f2, how="right")
|
| 284 |
+
tm.assert_index_equal(joined.index, f2.index)
|
| 285 |
+
tm.assert_index_equal(joined.columns, expected_columns)
|
| 286 |
+
|
| 287 |
+
# inner
|
| 288 |
+
|
| 289 |
+
joined = f.join(f2, how="inner")
|
| 290 |
+
tm.assert_index_equal(joined.index, f.index[5:10])
|
| 291 |
+
tm.assert_index_equal(joined.columns, expected_columns)
|
| 292 |
+
|
| 293 |
+
# outer
|
| 294 |
+
|
| 295 |
+
joined = f.join(f2, how="outer")
|
| 296 |
+
tm.assert_index_equal(joined.index, float_frame.index.sort_values())
|
| 297 |
+
tm.assert_index_equal(joined.columns, expected_columns)
|
| 298 |
+
|
| 299 |
+
# left anti
|
| 300 |
+
joined = f.join(f2, how="left_anti")
|
| 301 |
+
tm.assert_index_equal(joined.index, float_frame.index[:5])
|
| 302 |
+
tm.assert_index_equal(joined.columns, expected_columns)
|
| 303 |
+
|
| 304 |
+
# right anti
|
| 305 |
+
joined = f.join(f2, how="right_anti")
|
| 306 |
+
tm.assert_index_equal(joined.index, float_frame.index[10:][::-1])
|
| 307 |
+
tm.assert_index_equal(joined.columns, expected_columns)
|
| 308 |
+
|
| 309 |
+
join_msg = (
|
| 310 |
+
"'foo' is not a valid Merge type: left, right, inner, outer, "
|
| 311 |
+
"left_anti, right_anti, cross, asof"
|
| 312 |
+
)
|
| 313 |
+
with pytest.raises(ValueError, match=re.escape(join_msg)):
|
| 314 |
+
f.join(f2, how="foo")
|
| 315 |
+
|
| 316 |
+
# corner case - overlapping columns
|
| 317 |
+
msg = "columns overlap but no suffix"
|
| 318 |
+
for how in ("outer", "left", "inner"):
|
| 319 |
+
with pytest.raises(ValueError, match=msg):
|
| 320 |
+
float_frame.join(float_frame, how=how)
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
def test_join_index_more(float_frame):
|
| 324 |
+
af = float_frame.loc[:, ["A", "B"]]
|
| 325 |
+
bf = float_frame.loc[::2, ["C", "D"]]
|
| 326 |
+
|
| 327 |
+
expected = af.copy()
|
| 328 |
+
expected["C"] = float_frame["C"][::2]
|
| 329 |
+
expected["D"] = float_frame["D"][::2]
|
| 330 |
+
|
| 331 |
+
result = af.join(bf)
|
| 332 |
+
tm.assert_frame_equal(result, expected)
|
| 333 |
+
|
| 334 |
+
result = af.join(bf, how="right")
|
| 335 |
+
tm.assert_frame_equal(result, expected[::2])
|
| 336 |
+
|
| 337 |
+
result = bf.join(af, how="right")
|
| 338 |
+
tm.assert_frame_equal(result, expected.loc[:, result.columns])
|
| 339 |
+
|
| 340 |
+
|
| 341 |
+
def test_join_index_series(float_frame):
|
| 342 |
+
df = float_frame.copy()
|
| 343 |
+
ser = df.pop(float_frame.columns[-1])
|
| 344 |
+
joined = df.join(ser)
|
| 345 |
+
|
| 346 |
+
tm.assert_frame_equal(joined, float_frame)
|
| 347 |
+
|
| 348 |
+
ser.name = None
|
| 349 |
+
with pytest.raises(ValueError, match="must have a name"):
|
| 350 |
+
df.join(ser)
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
def test_join_overlap(float_frame):
|
| 354 |
+
df1 = float_frame.loc[:, ["A", "B", "C"]]
|
| 355 |
+
df2 = float_frame.loc[:, ["B", "C", "D"]]
|
| 356 |
+
|
| 357 |
+
joined = df1.join(df2, suffixes=("_df1", "_df2"))
|
| 358 |
+
df1_suf = df1.loc[:, ["B", "C"]].add_suffix("_df1")
|
| 359 |
+
df2_suf = df2.loc[:, ["B", "C"]].add_suffix("_df2")
|
| 360 |
+
|
| 361 |
+
no_overlap = float_frame.loc[:, ["A", "D"]]
|
| 362 |
+
expected = df1_suf.join(df2_suf).join(no_overlap)
|
| 363 |
+
|
| 364 |
+
# column order not necessarily sorted
|
| 365 |
+
tm.assert_frame_equal(joined, expected.loc[:, joined.columns])
|
| 366 |
+
|
| 367 |
+
|
| 368 |
+
def test_join_period_index():
|
| 369 |
+
frame_with_period_index = pd.DataFrame(
|
| 370 |
+
data=np.arange(20).reshape(4, 5),
|
| 371 |
+
columns=list("abcde"),
|
| 372 |
+
index=pd.period_range(start="2000", freq="Y", periods=4),
|
| 373 |
+
)
|
| 374 |
+
other = frame_with_period_index.rename(columns=lambda key: f"{key}{key}")
|
| 375 |
+
|
| 376 |
+
joined_values = np.concatenate([frame_with_period_index.values] * 2, axis=1)
|
| 377 |
+
|
| 378 |
+
joined_cols = frame_with_period_index.columns.append(other.columns)
|
| 379 |
+
|
| 380 |
+
joined = frame_with_period_index.join(other)
|
| 381 |
+
expected = pd.DataFrame(
|
| 382 |
+
data=joined_values, columns=joined_cols, index=frame_with_period_index.index
|
| 383 |
+
)
|
| 384 |
+
|
| 385 |
+
tm.assert_frame_equal(joined, expected)
|
| 386 |
+
|
| 387 |
+
|
| 388 |
+
def test_join_left_sequence_non_unique_index():
|
| 389 |
+
# https://github.com/pandas-dev/pandas/issues/19607
|
| 390 |
+
df1 = pd.DataFrame({"a": [0, 10, 20]}, index=[1, 2, 3])
|
| 391 |
+
df2 = pd.DataFrame({"b": [100, 200, 300]}, index=[4, 3, 2])
|
| 392 |
+
df3 = pd.DataFrame({"c": [400, 500, 600]}, index=[2, 2, 4])
|
| 393 |
+
|
| 394 |
+
joined = df1.join([df2, df3], how="left")
|
| 395 |
+
|
| 396 |
+
expected = pd.DataFrame(
|
| 397 |
+
{
|
| 398 |
+
"a": [0, 10, 10, 20],
|
| 399 |
+
"b": [np.nan, 300, 300, 200],
|
| 400 |
+
"c": [np.nan, 400, 500, np.nan],
|
| 401 |
+
},
|
| 402 |
+
index=[1, 2, 2, 3],
|
| 403 |
+
)
|
| 404 |
+
|
| 405 |
+
tm.assert_frame_equal(joined, expected)
|
| 406 |
+
|
| 407 |
+
|
| 408 |
+
def test_join_list_series(float_frame):
|
| 409 |
+
# GH#46850
|
| 410 |
+
# Join a DataFrame with a list containing both a Series and a DataFrame
|
| 411 |
+
left = float_frame.A.to_frame()
|
| 412 |
+
right = [float_frame.B, float_frame[["C", "D"]]]
|
| 413 |
+
result = left.join(right)
|
| 414 |
+
tm.assert_frame_equal(result, float_frame)
|
| 415 |
+
|
| 416 |
+
|
| 417 |
+
class TestDataFrameJoin:
|
| 418 |
+
def test_join(self, multiindex_dataframe_random_data):
|
| 419 |
+
frame = multiindex_dataframe_random_data
|
| 420 |
+
|
| 421 |
+
a = frame.loc[frame.index[:5], ["A"]]
|
| 422 |
+
b = frame.loc[frame.index[2:], ["B", "C"]]
|
| 423 |
+
|
| 424 |
+
joined = a.join(b, how="outer").reindex(frame.index)
|
| 425 |
+
expected = frame.copy().values.copy()
|
| 426 |
+
expected[np.isnan(joined.values)] = np.nan
|
| 427 |
+
expected = pd.DataFrame(expected, index=frame.index, columns=frame.columns)
|
| 428 |
+
|
| 429 |
+
assert not np.isnan(joined.values).all()
|
| 430 |
+
|
| 431 |
+
tm.assert_frame_equal(joined, expected)
|
| 432 |
+
|
| 433 |
+
def test_join_segfault(self):
|
| 434 |
+
# GH#1532
|
| 435 |
+
df1 = pd.DataFrame({"a": [1, 1], "b": [1, 2], "x": [1, 2]})
|
| 436 |
+
df2 = pd.DataFrame({"a": [2, 2], "b": [1, 2], "y": [1, 2]})
|
| 437 |
+
df1 = df1.set_index(["a", "b"])
|
| 438 |
+
df2 = df2.set_index(["a", "b"])
|
| 439 |
+
# it works!
|
| 440 |
+
for how in ["left", "right", "outer"]:
|
| 441 |
+
df1.join(df2, how=how)
|
| 442 |
+
|
| 443 |
+
def test_join_str_datetime(self):
|
| 444 |
+
str_dates = ["20120209", "20120222"]
|
| 445 |
+
dt_dates = [datetime(2012, 2, 9), datetime(2012, 2, 22)]
|
| 446 |
+
|
| 447 |
+
A = pd.DataFrame(str_dates, index=range(2), columns=["aa"])
|
| 448 |
+
C = pd.DataFrame([[1, 2], [3, 4]], index=str_dates, columns=dt_dates)
|
| 449 |
+
|
| 450 |
+
tst = A.join(C, on="aa")
|
| 451 |
+
|
| 452 |
+
assert len(tst.columns) == 3
|
| 453 |
+
|
| 454 |
+
def test_join_multiindex_leftright(self):
|
| 455 |
+
# GH 10741
|
| 456 |
+
df1 = pd.DataFrame(
|
| 457 |
+
[
|
| 458 |
+
["a", "x", 0.471780],
|
| 459 |
+
["a", "y", 0.774908],
|
| 460 |
+
["a", "z", 0.563634],
|
| 461 |
+
["b", "x", -0.353756],
|
| 462 |
+
["b", "y", 0.368062],
|
| 463 |
+
["b", "z", -1.721840],
|
| 464 |
+
["c", "x", 1],
|
| 465 |
+
["c", "y", 2],
|
| 466 |
+
["c", "z", 3],
|
| 467 |
+
],
|
| 468 |
+
columns=["first", "second", "value1"],
|
| 469 |
+
).set_index(["first", "second"])
|
| 470 |
+
|
| 471 |
+
df2 = pd.DataFrame(
|
| 472 |
+
[["a", 10], ["b", 20]], columns=["first", "value2"]
|
| 473 |
+
).set_index(["first"])
|
| 474 |
+
|
| 475 |
+
exp = pd.DataFrame(
|
| 476 |
+
[
|
| 477 |
+
[0.471780, 10],
|
| 478 |
+
[0.774908, 10],
|
| 479 |
+
[0.563634, 10],
|
| 480 |
+
[-0.353756, 20],
|
| 481 |
+
[0.368062, 20],
|
| 482 |
+
[-1.721840, 20],
|
| 483 |
+
[1.000000, np.nan],
|
| 484 |
+
[2.000000, np.nan],
|
| 485 |
+
[3.000000, np.nan],
|
| 486 |
+
],
|
| 487 |
+
index=df1.index,
|
| 488 |
+
columns=["value1", "value2"],
|
| 489 |
+
)
|
| 490 |
+
|
| 491 |
+
# these must be the same results (but columns are flipped)
|
| 492 |
+
tm.assert_frame_equal(df1.join(df2, how="left"), exp)
|
| 493 |
+
tm.assert_frame_equal(df2.join(df1, how="right"), exp[["value2", "value1"]])
|
| 494 |
+
|
| 495 |
+
exp_idx = pd.MultiIndex.from_product(
|
| 496 |
+
[["a", "b"], ["x", "y", "z"]], names=["first", "second"]
|
| 497 |
+
)
|
| 498 |
+
exp = pd.DataFrame(
|
| 499 |
+
[
|
| 500 |
+
[0.471780, 10],
|
| 501 |
+
[0.774908, 10],
|
| 502 |
+
[0.563634, 10],
|
| 503 |
+
[-0.353756, 20],
|
| 504 |
+
[0.368062, 20],
|
| 505 |
+
[-1.721840, 20],
|
| 506 |
+
],
|
| 507 |
+
index=exp_idx,
|
| 508 |
+
columns=["value1", "value2"],
|
| 509 |
+
)
|
| 510 |
+
|
| 511 |
+
tm.assert_frame_equal(df1.join(df2, how="right"), exp)
|
| 512 |
+
tm.assert_frame_equal(df2.join(df1, how="left"), exp[["value2", "value1"]])
|
| 513 |
+
|
| 514 |
+
def test_join_multiindex_dates(self):
|
| 515 |
+
# GH 33692
|
| 516 |
+
date = pd.Timestamp(2000, 1, 1).date()
|
| 517 |
+
|
| 518 |
+
df1_index = pd.MultiIndex.from_tuples([(0, date)], names=["index_0", "date"])
|
| 519 |
+
df1 = pd.DataFrame({"col1": [0]}, index=df1_index)
|
| 520 |
+
df2_index = pd.MultiIndex.from_tuples([(0, date)], names=["index_0", "date"])
|
| 521 |
+
df2 = pd.DataFrame({"col2": [0]}, index=df2_index)
|
| 522 |
+
df3_index = pd.MultiIndex.from_tuples([(0, date)], names=["index_0", "date"])
|
| 523 |
+
df3 = pd.DataFrame({"col3": [0]}, index=df3_index)
|
| 524 |
+
|
| 525 |
+
result = df1.join([df2, df3])
|
| 526 |
+
|
| 527 |
+
expected_index = pd.MultiIndex.from_tuples(
|
| 528 |
+
[(0, date)], names=["index_0", "date"]
|
| 529 |
+
)
|
| 530 |
+
expected = pd.DataFrame(
|
| 531 |
+
{"col1": [0], "col2": [0], "col3": [0]}, index=expected_index
|
| 532 |
+
)
|
| 533 |
+
|
| 534 |
+
tm.assert_equal(result, expected)
|
| 535 |
+
|
| 536 |
+
def test_merge_join_different_levels_raises(self):
|
| 537 |
+
# GH#9455
|
| 538 |
+
# GH 40993: For raising, enforced in 2.0
|
| 539 |
+
|
| 540 |
+
# first dataframe
|
| 541 |
+
df1 = pd.DataFrame(columns=["a", "b"], data=[[1, 11], [0, 22]])
|
| 542 |
+
|
| 543 |
+
# second dataframe
|
| 544 |
+
columns = pd.MultiIndex.from_tuples([("a", ""), ("c", "c1")])
|
| 545 |
+
df2 = pd.DataFrame(columns=columns, data=[[1, 33], [0, 44]])
|
| 546 |
+
|
| 547 |
+
# merge
|
| 548 |
+
with pytest.raises(
|
| 549 |
+
MergeError, match="Not allowed to merge between different levels"
|
| 550 |
+
):
|
| 551 |
+
pd.merge(df1, df2, on="a")
|
| 552 |
+
|
| 553 |
+
# join, see discussion in GH#12219
|
| 554 |
+
with pytest.raises(
|
| 555 |
+
MergeError, match="Not allowed to merge between different levels"
|
| 556 |
+
):
|
| 557 |
+
df1.join(df2, on="a")
|
| 558 |
+
|
| 559 |
+
def test_frame_join_tzaware(self):
|
| 560 |
+
tz = zoneinfo.ZoneInfo("US/Central")
|
| 561 |
+
test1 = pd.DataFrame(
|
| 562 |
+
np.zeros((6, 3)),
|
| 563 |
+
index=pd.date_range("2012-11-15 00:00:00", periods=6, freq="100ms", tz=tz),
|
| 564 |
+
)
|
| 565 |
+
test2 = pd.DataFrame(
|
| 566 |
+
np.zeros((3, 3)),
|
| 567 |
+
index=pd.date_range("2012-11-15 00:00:00", periods=3, freq="250ms", tz=tz),
|
| 568 |
+
columns=range(3, 6),
|
| 569 |
+
)
|
| 570 |
+
|
| 571 |
+
result = test1.join(test2, how="outer")
|
| 572 |
+
expected = test1.index.union(test2.index)
|
| 573 |
+
|
| 574 |
+
tm.assert_index_equal(result.index, expected)
|
| 575 |
+
assert result.index.tz.key == "US/Central"
|
| 576 |
+
|
| 577 |
+
def test_frame_join_categorical_index(self):
|
| 578 |
+
# GH 61675
|
| 579 |
+
cat_data = pd.Categorical(
|
| 580 |
+
[3, 4],
|
| 581 |
+
categories=pd.Series([2, 3, 4, 5], dtype="Int64"),
|
| 582 |
+
ordered=True,
|
| 583 |
+
)
|
| 584 |
+
values1 = "a b".split()
|
| 585 |
+
values2 = "foo bar".split()
|
| 586 |
+
df1 = pd.DataFrame({"hr": cat_data, "values1": values1}).set_index("hr")
|
| 587 |
+
df2 = pd.DataFrame({"hr": cat_data, "values2": values2}).set_index("hr")
|
| 588 |
+
df1.columns = pd.CategoricalIndex([4], dtype=cat_data.dtype, name="other_hr")
|
| 589 |
+
df2.columns = pd.CategoricalIndex([3], dtype=cat_data.dtype, name="other_hr")
|
| 590 |
+
|
| 591 |
+
df_joined = df1.join(df2)
|
| 592 |
+
expected = pd.DataFrame(
|
| 593 |
+
{"hr": cat_data, "values1": values1, "values2": values2}
|
| 594 |
+
).set_index("hr")
|
| 595 |
+
expected.columns = pd.CategoricalIndex(
|
| 596 |
+
[4, 3], dtype=cat_data.dtype, name="other_hr"
|
| 597 |
+
)
|
| 598 |
+
|
| 599 |
+
tm.assert_frame_equal(df_joined, expected)
|
venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_map.py
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from datetime import datetime
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
import pandas as pd
|
| 7 |
+
import pandas._testing as tm
|
| 8 |
+
|
| 9 |
+
from pandas.tseries.offsets import BDay
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def test_map(float_frame):
|
| 13 |
+
result = float_frame.map(lambda x: x * 2)
|
| 14 |
+
tm.assert_frame_equal(result, float_frame * 2)
|
| 15 |
+
float_frame.map(type)
|
| 16 |
+
|
| 17 |
+
# GH 465: function returning tuples
|
| 18 |
+
result = float_frame.map(lambda x: (x, x))["A"].iloc[0]
|
| 19 |
+
assert isinstance(result, tuple)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
@pytest.mark.parametrize("val", [1, 1.0])
|
| 23 |
+
def test_map_float_object_conversion(val):
|
| 24 |
+
# GH 2909: object conversion to float in constructor?
|
| 25 |
+
df = pd.DataFrame(data=[val, "a"])
|
| 26 |
+
result = df.map(lambda x: x).dtypes[0]
|
| 27 |
+
assert result == object
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def test_map_keeps_dtype(na_action):
|
| 31 |
+
# GH52219
|
| 32 |
+
arr = pd.Series(["a", np.nan, "b"])
|
| 33 |
+
sparse_arr = arr.astype(pd.SparseDtype(object))
|
| 34 |
+
df = pd.DataFrame(data={"a": arr, "b": sparse_arr})
|
| 35 |
+
|
| 36 |
+
def func(x):
|
| 37 |
+
return str.upper(x) if not pd.isna(x) else x
|
| 38 |
+
|
| 39 |
+
result = df.map(func, na_action=na_action)
|
| 40 |
+
|
| 41 |
+
expected_sparse = pd.array(["A", np.nan, "B"], dtype=pd.SparseDtype(object))
|
| 42 |
+
expected_arr = expected_sparse.astype(object)
|
| 43 |
+
expected = pd.DataFrame({"a": expected_arr, "b": expected_sparse})
|
| 44 |
+
|
| 45 |
+
tm.assert_frame_equal(result, expected)
|
| 46 |
+
|
| 47 |
+
result_empty = df.iloc[:0, :].map(func, na_action=na_action)
|
| 48 |
+
expected_empty = expected.iloc[:0, :]
|
| 49 |
+
tm.assert_frame_equal(result_empty, expected_empty)
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def test_map_str():
|
| 53 |
+
# GH 2786
|
| 54 |
+
df = pd.DataFrame(np.random.default_rng(2).random((3, 4)))
|
| 55 |
+
df2 = df.copy()
|
| 56 |
+
cols = ["a", "a", "a", "a"]
|
| 57 |
+
df.columns = cols
|
| 58 |
+
|
| 59 |
+
expected = df2.map(str)
|
| 60 |
+
expected.columns = cols
|
| 61 |
+
result = df.map(str)
|
| 62 |
+
tm.assert_frame_equal(result, expected)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
@pytest.mark.parametrize(
|
| 66 |
+
"col, val",
|
| 67 |
+
[["datetime", pd.Timestamp("20130101")], ["timedelta", pd.Timedelta("1 min")]],
|
| 68 |
+
)
|
| 69 |
+
def test_map_datetimelike(col, val):
|
| 70 |
+
# datetime/timedelta
|
| 71 |
+
df = pd.DataFrame(np.random.default_rng(2).random((3, 4)))
|
| 72 |
+
df[col] = val
|
| 73 |
+
result = df.map(str)
|
| 74 |
+
assert result.loc[0, col] == str(df.loc[0, col])
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
@pytest.mark.parametrize(
|
| 78 |
+
"expected",
|
| 79 |
+
[
|
| 80 |
+
pd.DataFrame(),
|
| 81 |
+
pd.DataFrame(columns=list("ABC")),
|
| 82 |
+
pd.DataFrame(index=list("ABC")),
|
| 83 |
+
pd.DataFrame({"A": [], "B": [], "C": []}),
|
| 84 |
+
],
|
| 85 |
+
)
|
| 86 |
+
@pytest.mark.parametrize("func", [round, lambda x: x])
|
| 87 |
+
def test_map_empty(expected, func):
|
| 88 |
+
# GH 8222
|
| 89 |
+
result = expected.map(func)
|
| 90 |
+
tm.assert_frame_equal(result, expected)
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def test_map_kwargs():
|
| 94 |
+
# GH 40652
|
| 95 |
+
result = pd.DataFrame([[1, 2], [3, 4]]).map(lambda x, y: x + y, y=2)
|
| 96 |
+
expected = pd.DataFrame([[3, 4], [5, 6]])
|
| 97 |
+
tm.assert_frame_equal(result, expected)
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def test_map_na_ignore(float_frame):
|
| 101 |
+
# GH 23803
|
| 102 |
+
strlen_frame = float_frame.map(lambda x: len(str(x)))
|
| 103 |
+
float_frame_with_na = float_frame.copy()
|
| 104 |
+
mask = np.random.default_rng(2).integers(0, 2, size=float_frame.shape, dtype=bool)
|
| 105 |
+
float_frame_with_na[mask] = pd.NA
|
| 106 |
+
strlen_frame_na_ignore = float_frame_with_na.map(
|
| 107 |
+
lambda x: len(str(x)), na_action="ignore"
|
| 108 |
+
)
|
| 109 |
+
# Set float64 type to avoid upcast when setting NA below
|
| 110 |
+
strlen_frame_with_na = strlen_frame.copy().astype("float64")
|
| 111 |
+
strlen_frame_with_na[mask] = pd.NA
|
| 112 |
+
tm.assert_frame_equal(strlen_frame_na_ignore, strlen_frame_with_na)
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def test_map_box_timestamps():
|
| 116 |
+
# GH 2689, GH 2627
|
| 117 |
+
ser = pd.Series(pd.date_range("1/1/2000", periods=10))
|
| 118 |
+
|
| 119 |
+
def func(x):
|
| 120 |
+
return (x.hour, x.day, x.month)
|
| 121 |
+
|
| 122 |
+
# it works!
|
| 123 |
+
pd.DataFrame(ser).map(func)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def test_map_box():
|
| 127 |
+
# ufunc will not be boxed. Same test cases as the test_map_box
|
| 128 |
+
df = pd.DataFrame(
|
| 129 |
+
{
|
| 130 |
+
"a": [pd.Timestamp("2011-01-01"), pd.Timestamp("2011-01-02")],
|
| 131 |
+
"b": [
|
| 132 |
+
pd.Timestamp("2011-01-01", tz="US/Eastern"),
|
| 133 |
+
pd.Timestamp("2011-01-02", tz="US/Eastern"),
|
| 134 |
+
],
|
| 135 |
+
"c": [pd.Timedelta("1 days"), pd.Timedelta("2 days")],
|
| 136 |
+
"d": [
|
| 137 |
+
pd.Period("2011-01-01", freq="M"),
|
| 138 |
+
pd.Period("2011-01-02", freq="M"),
|
| 139 |
+
],
|
| 140 |
+
}
|
| 141 |
+
)
|
| 142 |
+
|
| 143 |
+
result = df.map(lambda x: type(x).__name__)
|
| 144 |
+
expected = pd.DataFrame(
|
| 145 |
+
{
|
| 146 |
+
"a": ["Timestamp", "Timestamp"],
|
| 147 |
+
"b": ["Timestamp", "Timestamp"],
|
| 148 |
+
"c": ["Timedelta", "Timedelta"],
|
| 149 |
+
"d": ["Period", "Period"],
|
| 150 |
+
}
|
| 151 |
+
)
|
| 152 |
+
tm.assert_frame_equal(result, expected)
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def test_frame_map_dont_convert_datetime64(unit):
|
| 156 |
+
dtype = f"M8[{unit}]"
|
| 157 |
+
df = pd.DataFrame({"x1": [datetime(1996, 1, 1)]}, dtype=dtype)
|
| 158 |
+
|
| 159 |
+
df = df.map(lambda x: x + BDay())
|
| 160 |
+
df = df.map(lambda x: x + BDay())
|
| 161 |
+
|
| 162 |
+
result = df.x1.dtype
|
| 163 |
+
assert result == dtype
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
def test_map_function_runs_once():
|
| 167 |
+
df = pd.DataFrame({"a": [1, 2, 3]})
|
| 168 |
+
values = [] # Save values function is applied to
|
| 169 |
+
|
| 170 |
+
def reducing_function(val):
|
| 171 |
+
values.append(val)
|
| 172 |
+
|
| 173 |
+
def non_reducing_function(val):
|
| 174 |
+
values.append(val)
|
| 175 |
+
return val
|
| 176 |
+
|
| 177 |
+
for func in [reducing_function, non_reducing_function]:
|
| 178 |
+
del values[:]
|
| 179 |
+
|
| 180 |
+
df.map(func)
|
| 181 |
+
assert values == df.a.to_list()
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
def test_map_type():
|
| 185 |
+
# GH 46719
|
| 186 |
+
df = pd.DataFrame(
|
| 187 |
+
{"col1": [3, "string", float], "col2": [0.25, datetime(2020, 1, 1), np.nan]},
|
| 188 |
+
index=["a", "b", "c"],
|
| 189 |
+
)
|
| 190 |
+
|
| 191 |
+
result = df.map(type)
|
| 192 |
+
expected = pd.DataFrame(
|
| 193 |
+
{"col1": [int, str, type], "col2": [float, datetime, float]},
|
| 194 |
+
index=["a", "b", "c"],
|
| 195 |
+
)
|
| 196 |
+
tm.assert_frame_equal(result, expected)
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
def test_map_invalid_na_action(float_frame):
|
| 200 |
+
# GH 23803
|
| 201 |
+
with pytest.raises(ValueError, match="na_action must be .*Got 'abc'"):
|
| 202 |
+
float_frame.map(lambda x: len(str(x)), na_action="abc")
|
venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_matmul.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import operator
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
import pandas as pd
|
| 7 |
+
import pandas._testing as tm
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class TestMatMul:
|
| 11 |
+
def test_matmul(self):
|
| 12 |
+
# matmul test is for GH#10259
|
| 13 |
+
a = pd.DataFrame(
|
| 14 |
+
np.random.default_rng(2).standard_normal((3, 4)),
|
| 15 |
+
index=["a", "b", "c"],
|
| 16 |
+
columns=["p", "q", "r", "s"],
|
| 17 |
+
)
|
| 18 |
+
b = pd.DataFrame(
|
| 19 |
+
np.random.default_rng(2).standard_normal((4, 2)),
|
| 20 |
+
index=["p", "q", "r", "s"],
|
| 21 |
+
columns=["one", "two"],
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
# DataFrame @ DataFrame
|
| 25 |
+
result = operator.matmul(a, b)
|
| 26 |
+
expected = pd.DataFrame(
|
| 27 |
+
np.dot(a.values, b.values), index=["a", "b", "c"], columns=["one", "two"]
|
| 28 |
+
)
|
| 29 |
+
tm.assert_frame_equal(result, expected)
|
| 30 |
+
|
| 31 |
+
# DataFrame @ Series
|
| 32 |
+
result = operator.matmul(a, b.one)
|
| 33 |
+
expected = pd.Series(np.dot(a.values, b.one.values), index=["a", "b", "c"])
|
| 34 |
+
tm.assert_series_equal(result, expected)
|
| 35 |
+
|
| 36 |
+
# np.array @ DataFrame
|
| 37 |
+
result = operator.matmul(a.values, b)
|
| 38 |
+
assert isinstance(result, pd.DataFrame)
|
| 39 |
+
assert result.columns.equals(b.columns)
|
| 40 |
+
assert result.index.equals(pd.Index(range(3)))
|
| 41 |
+
expected = np.dot(a.values, b.values)
|
| 42 |
+
tm.assert_almost_equal(result.values, expected)
|
| 43 |
+
|
| 44 |
+
# nested list @ DataFrame (__rmatmul__)
|
| 45 |
+
result = operator.matmul(a.values.tolist(), b)
|
| 46 |
+
expected = pd.DataFrame(
|
| 47 |
+
np.dot(a.values, b.values), index=["a", "b", "c"], columns=["one", "two"]
|
| 48 |
+
)
|
| 49 |
+
tm.assert_almost_equal(result.values, expected.values)
|
| 50 |
+
|
| 51 |
+
# mixed dtype DataFrame @ DataFrame
|
| 52 |
+
a["q"] = a.q.round().astype(int)
|
| 53 |
+
result = operator.matmul(a, b)
|
| 54 |
+
expected = pd.DataFrame(
|
| 55 |
+
np.dot(a.values, b.values), index=["a", "b", "c"], columns=["one", "two"]
|
| 56 |
+
)
|
| 57 |
+
tm.assert_frame_equal(result, expected)
|
| 58 |
+
|
| 59 |
+
# different dtypes DataFrame @ DataFrame
|
| 60 |
+
a = a.astype(int)
|
| 61 |
+
result = operator.matmul(a, b)
|
| 62 |
+
expected = pd.DataFrame(
|
| 63 |
+
np.dot(a.values, b.values), index=["a", "b", "c"], columns=["one", "two"]
|
| 64 |
+
)
|
| 65 |
+
tm.assert_frame_equal(result, expected)
|
| 66 |
+
|
| 67 |
+
# unaligned
|
| 68 |
+
df = pd.DataFrame(
|
| 69 |
+
np.random.default_rng(2).standard_normal((3, 4)),
|
| 70 |
+
index=[1, 2, 3],
|
| 71 |
+
columns=range(4),
|
| 72 |
+
)
|
| 73 |
+
df2 = pd.DataFrame(
|
| 74 |
+
np.random.default_rng(2).standard_normal((5, 3)),
|
| 75 |
+
index=range(5),
|
| 76 |
+
columns=[1, 2, 3],
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
with pytest.raises(ValueError, match="aligned"):
|
| 80 |
+
operator.matmul(df, df2)
|
| 81 |
+
|
| 82 |
+
def test_matmul_message_shapes(self):
|
| 83 |
+
# GH#21581 exception message should reflect original shapes,
|
| 84 |
+
# not transposed shapes
|
| 85 |
+
a = np.random.default_rng(2).random((10, 4))
|
| 86 |
+
b = np.random.default_rng(2).random((5, 3))
|
| 87 |
+
|
| 88 |
+
df = pd.DataFrame(b)
|
| 89 |
+
|
| 90 |
+
msg = r"shapes \(10, 4\) and \(5, 3\) not aligned"
|
| 91 |
+
with pytest.raises(ValueError, match=msg):
|
| 92 |
+
a @ df
|
| 93 |
+
with pytest.raises(ValueError, match=msg):
|
| 94 |
+
a.tolist() @ df
|
venv/lib/python3.14/site-packages/pandas/tests/frame/methods/test_nlargest.py
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Note: for naming purposes, most tests are title with as e.g. "test_nlargest_foo"
|
| 3 |
+
but are implicitly also testing nsmallest_foo.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from string import ascii_lowercase
|
| 7 |
+
|
| 8 |
+
import numpy as np
|
| 9 |
+
import pytest
|
| 10 |
+
|
| 11 |
+
import pandas as pd
|
| 12 |
+
import pandas._testing as tm
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
@pytest.fixture
|
| 16 |
+
def df_main_dtypes():
|
| 17 |
+
return pd.DataFrame(
|
| 18 |
+
{
|
| 19 |
+
"group": [1, 1, 2],
|
| 20 |
+
"int": [1, 2, 3],
|
| 21 |
+
"float": [4.0, 5.0, 6.0],
|
| 22 |
+
"string": list("abc"),
|
| 23 |
+
"category_string": pd.Series(list("abc")).astype("category"),
|
| 24 |
+
"category_int": [7, 8, 9],
|
| 25 |
+
"datetime": pd.date_range("20130101", periods=3),
|
| 26 |
+
"datetimetz": pd.date_range("20130101", periods=3, tz="US/Eastern"),
|
| 27 |
+
"timedelta": pd.timedelta_range("1 s", periods=3, freq="s"),
|
| 28 |
+
},
|
| 29 |
+
columns=[
|
| 30 |
+
"group",
|
| 31 |
+
"int",
|
| 32 |
+
"float",
|
| 33 |
+
"string",
|
| 34 |
+
"category_string",
|
| 35 |
+
"category_int",
|
| 36 |
+
"datetime",
|
| 37 |
+
"datetimetz",
|
| 38 |
+
"timedelta",
|
| 39 |
+
],
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
class TestNLargestNSmallest:
|
| 44 |
+
# ----------------------------------------------------------------------
|
| 45 |
+
# Top / bottom
|
| 46 |
+
@pytest.mark.parametrize(
|
| 47 |
+
"order",
|
| 48 |
+
[
|
| 49 |
+
["a"],
|
| 50 |
+
["c"],
|
| 51 |
+
["a", "b"],
|
| 52 |
+
["a", "c"],
|
| 53 |
+
["b", "a"],
|
| 54 |
+
["b", "c"],
|
| 55 |
+
["a", "b", "c"],
|
| 56 |
+
["c", "a", "b"],
|
| 57 |
+
["c", "b", "a"],
|
| 58 |
+
["b", "c", "a"],
|
| 59 |
+
["b", "a", "c"],
|
| 60 |
+
# dups!
|
| 61 |
+
["b", "c", "c"],
|
| 62 |
+
],
|
| 63 |
+
)
|
| 64 |
+
@pytest.mark.parametrize("n", range(1, 11))
|
| 65 |
+
def test_nlargest_n(self, nselect_method, n, order):
|
| 66 |
+
# GH#10393
|
| 67 |
+
df = pd.DataFrame(
|
| 68 |
+
{
|
| 69 |
+
"a": np.random.default_rng(2).permutation(10),
|
| 70 |
+
"b": list(ascii_lowercase[:10]),
|
| 71 |
+
"c": np.random.default_rng(2).permutation(10).astype("float64"),
|
| 72 |
+
}
|
| 73 |
+
)
|
| 74 |
+
if "b" in order:
|
| 75 |
+
error_msg = (
|
| 76 |
+
f"Column 'b' has dtype (object|str), "
|
| 77 |
+
f"cannot use method '{nselect_method}' with this dtype"
|
| 78 |
+
)
|
| 79 |
+
with pytest.raises(TypeError, match=error_msg):
|
| 80 |
+
getattr(df, nselect_method)(n, order)
|
| 81 |
+
else:
|
| 82 |
+
ascending = nselect_method == "nsmallest"
|
| 83 |
+
result = getattr(df, nselect_method)(n, order)
|
| 84 |
+
result.index = pd.Index(list(result.index))
|
| 85 |
+
expected = df.sort_values(order, ascending=ascending).head(n)
|
| 86 |
+
tm.assert_frame_equal(result, expected)
|
| 87 |
+
|
| 88 |
+
@pytest.mark.parametrize(
|
| 89 |
+
"columns", [["group", "category_string"], ["group", "string"]]
|
| 90 |
+
)
|
| 91 |
+
def test_nlargest_error(self, df_main_dtypes, nselect_method, columns):
|
| 92 |
+
df = df_main_dtypes
|
| 93 |
+
col = columns[1]
|
| 94 |
+
error_msg = (
|
| 95 |
+
f"Column '{col}' has dtype {df[col].dtype}, "
|
| 96 |
+
f"cannot use method '{nselect_method}' with this dtype"
|
| 97 |
+
)
|
| 98 |
+
# escape some characters that may be in the repr
|
| 99 |
+
error_msg = (
|
| 100 |
+
error_msg.replace("(", "\\(")
|
| 101 |
+
.replace(")", "\\)")
|
| 102 |
+
.replace("[", "\\[")
|
| 103 |
+
.replace("]", "\\]")
|
| 104 |
+
)
|
| 105 |
+
with pytest.raises(TypeError, match=error_msg):
|
| 106 |
+
getattr(df, nselect_method)(2, columns)
|
| 107 |
+
|
| 108 |
+
def test_nlargest_all_dtypes(self, df_main_dtypes):
|
| 109 |
+
df = df_main_dtypes
|
| 110 |
+
df.nsmallest(2, list(set(df) - {"category_string", "string"}))
|
| 111 |
+
df.nlargest(2, list(set(df) - {"category_string", "string"}))
|
| 112 |
+
|
| 113 |
+
def test_nlargest_duplicates_on_starter_columns(self):
|
| 114 |
+
# regression test for GH#22752
|
| 115 |
+
|
| 116 |
+
df = pd.DataFrame({"a": [2, 2, 2, 1, 1, 1], "b": [1, 2, 3, 3, 2, 1]})
|
| 117 |
+
|
| 118 |
+
result = df.nlargest(4, columns=["a", "b"])
|
| 119 |
+
expected = pd.DataFrame(
|
| 120 |
+
{"a": [2, 2, 2, 1], "b": [3, 2, 1, 3]}, index=[2, 1, 0, 3]
|
| 121 |
+
)
|
| 122 |
+
tm.assert_frame_equal(result, expected)
|
| 123 |
+
|
| 124 |
+
result = df.nsmallest(4, columns=["a", "b"])
|
| 125 |
+
expected = pd.DataFrame(
|
| 126 |
+
{"a": [1, 1, 1, 2], "b": [1, 2, 3, 1]}, index=[5, 4, 3, 0]
|
| 127 |
+
)
|
| 128 |
+
tm.assert_frame_equal(result, expected)
|
| 129 |
+
|
| 130 |
+
def test_nlargest_n_identical_values(self):
|
| 131 |
+
# GH#15297
|
| 132 |
+
df = pd.DataFrame({"a": [1] * 5, "b": [1, 2, 3, 4, 5]})
|
| 133 |
+
|
| 134 |
+
result = df.nlargest(3, "a")
|
| 135 |
+
expected = pd.DataFrame({"a": [1] * 3, "b": [1, 2, 3]}, index=range(3))
|
| 136 |
+
tm.assert_frame_equal(result, expected)
|
| 137 |
+
|
| 138 |
+
result = df.nsmallest(3, "a")
|
| 139 |
+
expected = pd.DataFrame({"a": [1] * 3, "b": [1, 2, 3]})
|
| 140 |
+
tm.assert_frame_equal(result, expected)
|
| 141 |
+
|
| 142 |
+
@pytest.mark.parametrize(
|
| 143 |
+
"order",
|
| 144 |
+
[["a", "b", "c"], ["c", "b", "a"], ["a"], ["b"], ["a", "b"], ["c", "b"]],
|
| 145 |
+
)
|
| 146 |
+
@pytest.mark.parametrize("n", range(1, 6))
|
| 147 |
+
def test_nlargest_n_duplicate_index(self, n, order):
|
| 148 |
+
# GH#13412
|
| 149 |
+
|
| 150 |
+
df = pd.DataFrame(
|
| 151 |
+
{"a": [1, 2, 3, 4, 4], "b": [1, 1, 1, 1, 1], "c": [0, 1, 2, 5, 4]},
|
| 152 |
+
index=[0, 0, 1, 1, 1],
|
| 153 |
+
)
|
| 154 |
+
result = df.nsmallest(n, order)
|
| 155 |
+
expected = df.sort_values(order, kind="stable").head(n)
|
| 156 |
+
tm.assert_frame_equal(result, expected)
|
| 157 |
+
|
| 158 |
+
result = df.nlargest(n, order)
|
| 159 |
+
expected = df.sort_values(order, ascending=False, kind="stable").head(n)
|
| 160 |
+
tm.assert_frame_equal(result, expected)
|
| 161 |
+
|
| 162 |
+
def test_nlargest_duplicate_keep_all_ties(self):
|
| 163 |
+
# GH#16818
|
| 164 |
+
df = pd.DataFrame(
|
| 165 |
+
{"a": [5, 4, 4, 2, 3, 3, 3, 3], "b": [10, 9, 8, 7, 5, 50, 10, 20]}
|
| 166 |
+
)
|
| 167 |
+
result = df.nlargest(4, "a", keep="all")
|
| 168 |
+
expected = pd.DataFrame(
|
| 169 |
+
{
|
| 170 |
+
"a": [5, 4, 4, 3, 3, 3, 3],
|
| 171 |
+
"b": [10, 9, 8, 5, 50, 10, 20],
|
| 172 |
+
},
|
| 173 |
+
index=[0, 1, 2, 4, 5, 6, 7],
|
| 174 |
+
)
|
| 175 |
+
tm.assert_frame_equal(result, expected)
|
| 176 |
+
|
| 177 |
+
result = df.nsmallest(2, "a", keep="all")
|
| 178 |
+
expected = pd.DataFrame(
|
| 179 |
+
{
|
| 180 |
+
"a": [2, 3, 3, 3, 3],
|
| 181 |
+
"b": [7, 5, 50, 10, 20],
|
| 182 |
+
},
|
| 183 |
+
index=range(3, 8),
|
| 184 |
+
)
|
| 185 |
+
tm.assert_frame_equal(result, expected)
|
| 186 |
+
|
| 187 |
+
def test_nlargest_multiindex_column_lookup(self):
|
| 188 |
+
# Check whether tuples are correctly treated as multi-level lookups.
|
| 189 |
+
# GH#23033
|
| 190 |
+
df = pd.DataFrame(
|
| 191 |
+
columns=pd.MultiIndex.from_product([["x"], ["a", "b"]]),
|
| 192 |
+
data=[[0.33, 0.13], [0.86, 0.25], [0.25, 0.70], [0.85, 0.91]],
|
| 193 |
+
)
|
| 194 |
+
|
| 195 |
+
# nsmallest
|
| 196 |
+
result = df.nsmallest(3, ("x", "a"))
|
| 197 |
+
expected = df.iloc[[2, 0, 3]]
|
| 198 |
+
tm.assert_frame_equal(result, expected)
|
| 199 |
+
|
| 200 |
+
# nlargest
|
| 201 |
+
result = df.nlargest(3, ("x", "b"))
|
| 202 |
+
expected = df.iloc[[3, 2, 1]]
|
| 203 |
+
tm.assert_frame_equal(result, expected)
|
| 204 |
+
|
| 205 |
+
def test_nlargest_nan(self):
|
| 206 |
+
# GH#43060
|
| 207 |
+
df = pd.DataFrame([np.nan, np.nan, 0, 1, 2, 3])
|
| 208 |
+
result = df.nlargest(5, 0)
|
| 209 |
+
expected = df.sort_values(0, ascending=False).head(5)
|
| 210 |
+
tm.assert_frame_equal(result, expected)
|
| 211 |
+
|
| 212 |
+
def test_nsmallest_nan_after_n_element(self):
|
| 213 |
+
# GH#46589
|
| 214 |
+
df = pd.DataFrame(
|
| 215 |
+
{
|
| 216 |
+
"a": [1, 2, 3, 4, 5, None, 7],
|
| 217 |
+
"b": [7, 6, 5, 4, 3, 2, 1],
|
| 218 |
+
"c": [1, 1, 2, 2, 3, 3, 3],
|
| 219 |
+
},
|
| 220 |
+
index=range(7),
|
| 221 |
+
)
|
| 222 |
+
result = df.nsmallest(5, columns=["a", "b"])
|
| 223 |
+
expected = pd.DataFrame(
|
| 224 |
+
{
|
| 225 |
+
"a": [1, 2, 3, 4, 5],
|
| 226 |
+
"b": [7, 6, 5, 4, 3],
|
| 227 |
+
"c": [1, 1, 2, 2, 3],
|
| 228 |
+
},
|
| 229 |
+
index=range(5),
|
| 230 |
+
).astype({"a": "float"})
|
| 231 |
+
tm.assert_frame_equal(result, expected)
|