id
int64
number
int64
title
string
state
string
created_at
timestamp[s]
updated_at
timestamp[s]
closed_at
timestamp[s]
html_url
string
is_pull_request
bool
pull_request_url
string
pull_request_html_url
string
user_login
string
comments_count
int64
body
string
labels
list
reactions_plus1
int64
reactions_minus1
int64
reactions_laugh
int64
reactions_hooray
int64
reactions_confused
int64
reactions_heart
int64
reactions_rocket
int64
reactions_eyes
int64
comments
list
2,149,909,615
57,572
ENH: Add Rich formatting support to Pandas object displays with `__rich_console__` method
open
2024-02-22T20:48:18
2024-02-29T19:01:35
null
https://github.com/pandas-dev/pandas/issues/57572
true
null
null
dwreeves
9
### Feature Type - [x] Adding new functionality to pandas - [ ] Changing existing functionality in pandas - [ ] Removing existing functionality in pandas ### Problem Description [Rich](https://github.com/Textualize/rich) is a very popular and, at this point, a standard tool in the Python ecosystem for beautiful rendering of text in terminals. Pandas's rich rendering via `_repr_html_` is very optimized for the Jupyter ecoystem, but lags behind in the terminal space. As someone who primarily codes in a terminal with a Rich patched REPL, I find this unfortunate and unnecessary. Hence I am adding this feature request in hopes that the situation can be improved. I can work on this if it is agreed that this feature would be handy and useful. ### Feature Description This is a very rough solution that does not cover all the appropriate challenges, requirements and complexities that would need to be met. It is just to give you an idea that it is possible: ```python import pandas as pd class DataFrame(pd.DataFrame): def __rich_console__(self, console: "rich.console.Console", console_options: "rich.console.Console"): from rich.table import Table table = Table() table.add_column(self.index.name if self.index.name is not None else "") for c in self.columns: table.add_column(str(c)) for r in self.itertuples(): table.add_row(*map(str, r)) yield from table.__rich_console__(console, console_options) from rich.console import Console console = Console() df = DataFrame([ {"name": "John Doe", "phone": "555-555-5555", "last_purchase_amount": 1.23}, {"name": "Mary Sue", "phone": "800-123-4567", "last_purchase_amount": 100.00} ]) console.print(df) ``` A few things are missing from this solution. Notably, it needs to hook into the Pandas options; it needs to be able to truncate the rows and columns based on the relevant display options. Series objects also need to have a `__rich_console__`. The Styler object should, as well, and this should hook into the Styler object configuration. There should probably be a way to set additional display options for this somewhere (e.g. `display.rich.[...]` and `styler.rich.[...]`). You'd need to hook into the try-except import stuff that Pandas does on the backend for optional dependencies. Lastly, of course, this would all need to be documented. ### Alternative Solutions - Users can just do it themselves, I suppose. - You can use the `__rich__` method, but I think you'd want to have access to the console parameters when fleshing out the code. ### Additional Context I could not find any related issues.
[ "Enhancement", "Output-Formatting", "Needs Discussion" ]
4
0
0
0
0
0
0
0
[ "Can you show examples?\r\n\r\nSpecifically with and without a `pandas.MultiIndex` both axis 0 and axis 1? Without and without axis 0 names? What kind of support does `rich` provide for multi indexes?", "Looks like there's this external library that supports rich for pandas objects: https://pypi.org/project/rich-dataframe/", "@Delengowski \r\n\r\n> Can you show examples?\r\n\r\nThe example code I provided in the issue outputs like this:\r\n\r\n![image](https://github.com/pandas-dev/pandas/assets/31971762/4986f07a-d94b-4353-bd0d-03656e282d25)\r\n\r\nOne can certainly do additional work however to implement more styling options. Rich has a bunch.\r\n\r\n> Specifically with and without a `pandas.MultiIndex` both axis 0 and axis 1? Without and without axis 0 names? What kind of support does `rich` provide for multi indexes?\r\n\r\nMultiindexes are a good point. Rich does not \"provide support for multindexes\" per se, it's is just a visualization library. The way you render them depends on how you want to render them.\r\n\r\nWith my code example above the following dataframe:\r\n\r\n```python\r\ndf = DataFrame(\r\n [\r\n {\"name\": \"John Doe\", \"phone\": \"555-555-5555\", \"last_purchase_amount\": 1.23},\r\n {\"name\": \"Mary Sue\", \"phone\": \"800-123-4567\", \"last_purchase_amount\": 100.00},\r\n ],\r\n index=pd.MultiIndex.from_tuples([(1, 2), (3, 4)], names=[None, None])\r\n)\r\n```\r\n\r\nYou get this:\r\n\r\n![image](https://github.com/pandas-dev/pandas/assets/31971762/f6b057ba-a1ae-4b1e-b320-23a8507c0b7e)\r\n\r\nYou can modify the code to support more functionality, though:\r\n\r\n```python\r\nimport pandas as pd\r\n\r\n# todo: replace with actual pandas settings\r\nsettings__display_rich_combine_multindex = False\r\n\r\nclass DataFrame(pd.DataFrame):\r\n\r\n def __rich_console__(self, console: \"rich.console.Console\", console_options: \"rich.console.Console\"):\r\n from rich.table import Table\r\n table = Table()\r\n split_multiindices = False\r\n # Todo: check if there is a better way to check for multi indices\r\n if self.index.names and not settings__display_rich_combine_multindex:\r\n split_multiindices = True\r\n for name in self.index.names:\r\n table.add_column(name if name is not None else \"\")\r\n else:\r\n if self.index.names:\r\n name = \",\".join(self.index.names)\r\n else:\r\n name = self.index.name\r\n table.add_column(name if name is not None else \"\")\r\n\r\n for c in self.columns:\r\n table.add_column(str(c))\r\n for r in self.itertuples():\r\n if split_multiindices:\r\n row_data = map(str, [*r[0], *r[1:]])\r\n else:\r\n row_data = map(str, r)\r\n table.add_row(*row_data)\r\n\r\n yield from table.__rich_console__(console, console_options)\r\n\r\nfrom rich.console import Console\r\n\r\nconsole = Console(color_system=\"truecolor\")\r\n\r\ndf = DataFrame(\r\n [\r\n {\"name\": \"John Doe\", \"phone\": \"555-555-5555\", \"last_purchase_amount\": 1.23},\r\n {\"name\": \"Mary Sue\", \"phone\": \"800-123-4567\", \"last_purchase_amount\": 100.00},\r\n ],\r\n index=pd.MultiIndex.from_tuples([(1, 2), (3, 4)], names=[\"foo\", \"bar\"])\r\n)\r\n\r\nconsole.print(df)\r\n```\r\n\r\nOutput:\r\n\r\n![image](https://github.com/pandas-dev/pandas/assets/31971762/f121dc74-08bf-4394-af03-afb296ebd300)\r\n\r\nYou can do the thing where you create a new row just for the index names, if you want, as well. Again, it's very composable.\r\n\r\n---\r\n\r\nNote that all of this code is very rough. Implementing this would take a lot, lot more effort than I put into this code right here. I'm just trying to see first whether the Pandas dev team agrees that this should be implemented.", "@mroeschke\r\n\r\n> Looks like there's this external library that supports rich for pandas objects: https://pypi.org/project/rich-dataframe/\r\n\r\nI'm aware, and the owners of that library should definitely be consulted and should be brought into this discussion if we agree that this should exist as a native feature, as they have relevant knowledge and I'm sure they'd love to see this become a native feature + work on it.\r\n\r\nBut, I do think there is a lot of value in making this native, and not just relying on third-party support, even if said third-party support exists.\r\n\r\nI would put it like this: if there was a library called `jupyter-dataframe`, it would still have been a good idea for Pandas to implement `_repr_html_` natively. It would not be a good user experience to tell people, \"well, just use this third party library and wrap everything with `jupyter_dataframe.prettify(df)`. Arguably, Pandas may not have become nearly as popular as it is today if `_repr_html_` wasn't natively implemented.\r\n\r\nSome of the benefits of adding this natively:\r\n\r\n- Just type `>>> df` and get your pretty repr, instead of needing to wrap in `prettify(df)`. That's a massive difference in quality of life for exploratory workflows.\r\n- User does not need to install another library.\r\n- Likely to receive more functionality, bugfixes, and community support. For example, the linked library does not seem to support MultiIndexes, which I was just asked about above.\r\n- People are way more likely to use this in general, I think, if it is officially supported.\r\n\r\nAgain, Rich is popular (46k Github stars), modern, and people just really enjoy it. I'm not proposing pandas-dev creates a new optional dependency on some random no-name library. I'm proposing that terminal-based Pandas workflows should get a modern, native, built-in facelift, in the same spirit that Pandas already supports a quality native experience for Jupyter-based workflows.\r\n\r\nAlso to clarify, I don't necessarily see pointing this out as a tacit disagreement with my argument that it should be native. I do just want to state my position here that for purposes of native support, I don't see it as relevant that a third-party library exists, other than that we could @ the creator of that library and get them involved in this, if we agree it should be native 😄 ", "It looks like all the unit-tests for Pandas display related stuff already are:\r\n\r\n- For dataframes reprs: https://github.com/pandas-dev/pandas/blob/main/pandas/tests/frame/test_repr.py\r\n- For series reprs + other reprs: https://github.com/pandas-dev/pandas/blob/main/pandas/tests/series/test_formats.py\r\n- For HTML, console, etc. outputs: https://github.com/pandas-dev/pandas/blob/main/pandas/tests/io/formats (HTML tests seem to be the most comprehensive.)\r\n\r\nObviously, reasonable acceptance criteria would be that a Rich hook can implement all these behaviors but as Rich-formatted tables. There are a few stylistic decisions that one would still have to make even within this constraint, however, but reimplementing the spirit of these tests but for Rich would really narrow down the scope of the problem.", "> Note that all of this code is very rough. Implementing this would take a lot, lot more effort than I put into this code right here. I'm just trying to see first whether the Pandas dev team agrees that this should be implemented.\r\n\r\nThanks for this. The first thought that came to mind was merging of cells for multi index. I would think that unless Rich can do that, it's a non starter because displaying rich bases repr for a data frame with multi index that looks different from the regular repr would be incredibly confusing. \r\n\r\n\r\nThat's why I was asking, to see if it has out of box support or if it would be a bit of work.\r\n\r\n", "It looks like spans are desired but not yet implemented nor a high priority.\r\n\r\nhttps://github.com/Textualize/rich/issues/164", "You mean to support this test case?\r\n\r\nhttps://github.com/pandas-dev/pandas/blob/e14a9bd41d8cd8ac52c5c958b735623fe0eae064/pandas/tests/io/formats/data/html/index_5.html\r\n\r\n![image](https://github.com/pandas-dev/pandas/assets/31971762/54a89c13-9809-40a0-934a-9acb7caeb541)\r\n\r\nIf you do not include horizontal lines to split out the rows (which is the default behavior of Rich, i.e. `show_lines=False`, and also is likely a reasonable default for Pandas too), then the reasonable 'work around' is just to display a blank string. Because there are no horizontal dividers, this will visually look correct.\r\n\r\nThis only gets finicky when `show_lines=True`, and then you have empty cells. This would not look very good.\r\n\r\nAn option here is (pseudocode):\r\n\r\n```python\r\nif not config.show_lines and index_is_same_as_above:\r\n # don't repeat the row as above\r\n multi_index_row_label = \"\"\r\nelse:\r\n # if `show_lines` is on, stylistically the best option is to repeat the value over again.\r\n multi_index_row_label = row.index\r\n```\r\n\r\nThis does not 100% meet the exact same style for MultiIndex support that HTML + base repr do, but only specifically in the case of `show_lines=True`. When `show_lines=False` then it should look correct to users.\r\n\r\nAnother option: Disable support for `show_lines=True`. I don't love this, as users would probably expect a bit of customizability for these Rich Table objects, but it is an option to enforce this style decision for multi-indexes.\r\n\r\n---\r\n\r\nIf the main blocker to adoption of this feature is a concern over support for this and a few other things, rather than e.g. this feature being out of scope in general for Pandas, we can potentially make changes to Rich itself.\r\n\r\nMy question is: If Rich had every feature you'd reasonably want to render the reprs in a way that is consistent with the current repr behavior (which I think it does), would Rich support still be considered out of scope for Pandas? Or would it be potentially in-scope? Because if the latter, i.e. Rich support is in-scope, it's possible we can try to prioritize any missing functionality on Textualize/Rich's end; I'm sure they'd be interested in unblocking a major library like Pandas adopting Rich.", "Here is an example of the snippet code modified to emulate the rowspan-like visualization that the base repr provides:\r\n\r\n```python\r\nimport pandas as pd\r\n\r\n# todo: replace with actual pandas settings\r\nsettings__display_rich_combine_multindex = False\r\n\r\nclass DataFrame(pd.DataFrame):\r\n\r\n def __rich_console__(self, console: \"rich.console.Console\", console_options: \"rich.console.Console\"):\r\n from rich.table import Table\r\n table = Table()\r\n split_multiindices = False\r\n # Todo: check if there is a better way to check for multi indices\r\n if self.index.names and not settings__display_rich_combine_multindex:\r\n split_multiindices = True\r\n for name in self.index.names:\r\n table.add_column(name if name is not None else \"\")\r\n else:\r\n if self.index.names:\r\n name = \",\".join(self.index.names)\r\n else:\r\n name = self.index.name\r\n table.add_column(name if name is not None else \"\")\r\n\r\n _prev_index = None\r\n\r\n for c in self.columns:\r\n table.add_column(str(c))\r\n for r in self.itertuples():\r\n if split_multiindices:\r\n if _prev_index is not None:\r\n new_index = [\r\n new if prev != new else \"\"\r\n for prev, new in zip(_prev_index, r[0])\r\n ]\r\n else:\r\n new_index = r[0]\r\n _prev_index = r[0]\r\n row_data = map(str, [*new_index, *r[1:]])\r\n else:\r\n row_data = map(str, r)\r\n table.add_row(*row_data)\r\n\r\n yield from table.__rich_console__(console, console_options)\r\n\r\nfrom rich.console import Console\r\n\r\nconsole = Console(color_system=\"truecolor\")\r\n\r\ndf = DataFrame(\r\n [\r\n {\"name\": \"John Doe\", \"phone\": \"555-555-5555\", \"last_purchase_amount\": 1.23},\r\n {\"name\": \"Mary Sue\", \"phone\": \"800-123-4567\", \"last_purchase_amount\": 100.00},\r\n {\"name\": \"Bob James\", \"phone\": \"800-234-5678\", \"last_purchase_amount\": 50.00},\r\n ],\r\n index=pd.MultiIndex.from_tuples([(1, 1), (1, 2), (2, 1)], names=[\"foo\", \"bar\"])\r\n)\r\n\r\nconsole.print(df)\r\n```\r\n\r\nThis is the output:\r\n\r\n![image](https://github.com/pandas-dev/pandas/assets/31971762/e7fc0ac2-832b-4970-a337-403d82fc2c3e)\r\n\r\nLooks decent if you ask me.\r\n\r\nHowever, you can see that it looks bad when I replace `table = Table()` with `table = Table(show_lines=True)`:\r\n\r\n![image](https://github.com/pandas-dev/pandas/assets/31971762/ab659c3e-8260-491e-b3bc-da1a69fd2459)\r\n\r\nThe 'work around' I propose is, when `show_lines=True`, we display everything:\r\n\r\n![image](https://github.com/pandas-dev/pandas/assets/31971762/9a2095bc-ae11-4081-b4f1-137bb31946f5)\r\n\r\nIn the sloppy draft code above, you can achieve this by replacing this line: `if _prev_index is not None:` with: `if _prev_index is not None and not table.show_lines:`.\r\n\r\nThis is not ideal, but it's the best idea I can come up with that doesn't involve significant rewrites of Rich's internals and/or getting Rich maintainers involved (again, not that this would be an impossible ask if a library as big as Pandas were to ask for a feature)." ]
2,149,879,436
57,571
TST: Clean contexts
closed
2024-02-22T20:25:42
2024-02-24T18:36:09
2024-02-24T18:36:06
https://github.com/pandas-dev/pandas/pull/57571
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57571
https://github.com/pandas-dev/pandas/pull/57571
mroeschke
1
* Replaced only use of `use_numexpr` * Created pytest native `temp_file` fixture for use over `tm.ensure_clean`
[ "Testing", "Clean" ]
0
0
0
0
0
0
0
0
[ "Going to merge this cleanup. Can follow up if needed" ]
2,149,695,887
57,570
BUG: Interchange object data buffer has the wrong dtype / from_dataframe incorrect
closed
2024-02-22T18:30:43
2024-02-23T17:12:56
2024-02-23T17:12:43
https://github.com/pandas-dev/pandas/pull/57570
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57570
https://github.com/pandas-dev/pandas/pull/57570
MarcoGorelli
1
- [ ] closes #54781 (Replace xxxx with the GitHub issue number) - [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.
[ "Interchange" ]
0
0
0
0
0
0
0
0
[ "Thanks @MarcoGorelli " ]
2,149,666,555
57,569
BUG: still getting UnicodeDecodeError with encoding_errors="ignore"
open
2024-02-22T18:19:36
2024-04-13T23:13:02
null
https://github.com/pandas-dev/pandas/issues/57569
true
null
null
dadrake3
3
### Pandas version checks - [X] I have checked that this issue has not already been reported. - [X] I have confirmed this bug exists on the [latest version](https://pandas.pydata.org/docs/whatsnew/index.html) of pandas. - [x] I have confirmed this bug exists on the [main branch](https://pandas.pydata.org/docs/dev/getting_started/install.html#installing-the-development-version-of-pandas) of pandas. ### Reproducible Example ```python import pandas as pd import gzip from io import BytesIO file_path = ... with gzip.open(file_path, "rb") as gz: data = gz.read() encoding = "ascii" bytes_io = BytesIO(data) df = pd.read_csv( bytes_io, encoding=encoding, encoding_errors="ignore", delimiter="|", dtype=str, on_bad_lines=lambda x: "skip", engine="pyarrow", keep_default_na=False, ) ``` ### Issue Description I am trying to use pandas internals to decode my file rather than calling data.decode(encoding...) and passing in a stringIO object, to save on ram. However when I do this I am getting this error ``` File "/root/conda/envs/main/lib/python3.11/site-packages/pandas/io/parsers/readers.py", line 1024, in read_csv return _read(filepath_or_buffer, kwds) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/conda/envs/main/lib/python3.11/site-packages/pandas/io/parsers/readers.py", line 624, in _read return parser.read(nrows) ^^^^^^^^^^^^^^^^^^ File "/root/conda/envs/main/lib/python3.11/site-packages/pandas/io/parsers/readers.py", line 1909, in read df = self._engine.read() # type: ignore[attr-defined] ^^^^^^^^^^^^^^^^^^^ File "/root/conda/envs/main/lib/python3.11/site-packages/pandas/io/parsers/arrow_parser_wrapper.py", line 266, in read table = pyarrow_csv.read_csv( ^^^^^^^^^^^^^^^^^^^^^ File "pyarrow/_csv.pyx", line 1261, in pyarrow._csv.read_csv File "pyarrow/_csv.pyx", line 1270, in pyarrow._csv.read_csv File "pyarrow/error.pxi", line 154, in pyarrow.lib.pyarrow_internal_check_status File "pyarrow/types.pxi", line 88, in pyarrow.lib._datatype_to_pep3118 File "pyarrow/io.pxi", line 1843, in pyarrow.lib._cb_transform File "pyarrow/io.pxi", line 1884, in pyarrow.lib.Transcoder.__call__ File "/root/conda/envs/main/lib/python3.11/encodings/ascii.py", line 26, in decode return codecs.ascii_decode(input, self.errors)[0] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 10356: ordinal not in range(128) ``` this happens when I use `encoding_errors='ignore'` or `encoding_errors='replace'` ### Expected Behavior This should behave the same way as if I were doing this ``` string_io = StringIO(data.decode(encoding, errors="replace")) df = pd.read_csv(string_io, ...) ``` and ignore the unicode errors in my file ### Installed Versions <details> INSTALLED VERSIONS ------------------ commit : f538741432edf55c6b9fb5d0d496d2dd1d7c2457 python : 3.11.8.final.0 python-bits : 64 OS : Linux OS-release : 6.5.0-17-generic Version : #17-Ubuntu SMP PREEMPT_DYNAMIC Thu Jan 11 14:20:13 UTC 2024 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : None LOCALE : en_US.UTF-8 pandas : 2.2.0 numpy : 1.26.4 pytz : 2024.1 dateutil : 2.8.2 setuptools : 69.1.0 pip : 24.0 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : None IPython : None pandas_datareader : None adbc-driver-postgresql: None adbc-driver-sqlite : None bs4 : None bottleneck : None dataframe-api-compat : None fastparquet : None fsspec : None gcsfs : None matplotlib : None numba : None numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : 15.0.0 pyreadstat : None python-calamine : None pyxlsb : None s3fs : None scipy : None sqlalchemy : 2.0.27 tables : None tabulate : 0.9.0 xarray : None xlrd : None zstandard : None tzdata : 2024.1 qtpy : None pyqt5 : None </details>
[ "Bug", "Needs Triage" ]
0
0
0
0
0
0
0
0
[ "take", "take", "hello! @dadrake3 could you provide us with the file or the snippet of the file that you used? we can't reproduce the bug right now with our own file with a unicode decode error, it's following the expected encoding errors = ignore behavior." ]
2,149,592,589
57,568
Backport PR #57556 on branch 2.2.x (Remove PyArrow deprecation warning)
closed
2024-02-22T17:45:49
2024-02-22T18:45:40
2024-02-22T18:45:36
https://github.com/pandas-dev/pandas/pull/57568
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57568
https://github.com/pandas-dev/pandas/pull/57568
phofl
0
#57556
[ "Docs" ]
0
0
0
0
0
0
0
0
[]
2,149,189,008
57,567
DEPS: update numexpr to use not buggy numexpr 2.8.x anymore (update to 2.9.0) - fix critical CVE-2023-39631⁠
closed
2024-02-22T14:22:22
2024-02-22T16:54:53
2024-02-22T16:54:52
https://github.com/pandas-dev/pandas/pull/57567
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57567
https://github.com/pandas-dev/pandas/pull/57567
nigzak
1
update numexpr to 2.9.0 to fix CVE-2023-39631⁠ findings HINT: come from other project (apache-superset) where panda is injecting this faulty numexpr inside the project as sub-dependency - [ ] closes #xxxx (Replace xxxx with the GitHub issue number) - [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.
[]
0
0
0
0
0
0
0
0
[ "Thanks for the PR, but pandas tries to support optional dependencies that are at most 1 year old. Additionally, pandas just species a lower pin, so a user is able to specify numexpr>=2.9.0 if they want to avoid this CVE. pandas will bump to 2.9.0 eventually, but I think it's too early to do so at this moment so closing" ]
2,148,986,823
57,566
why the loss: 8.7021 >= 1 ? why the sparse_categorical_accuracy: 4.9620 >=1 ?
closed
2024-02-22T12:39:40
2024-03-08T20:45:31
2024-03-08T20:45:31
https://github.com/pandas-dev/pandas/issues/57566
true
null
null
challenge2
2
Epoch 25/25 104/104 ━━━━━━━━━━━━━━━━━━━━ 73s 709ms/step - loss: 8.7021 - sparse_categorical_accuracy: 4.9620 - val_loss: 1.0865 - val_sparse_categorical_accuracy: 0.6331
[]
0
0
0
0
0
0
0
0
[ "There isn't enough information here to know what you're talking about. Please provide more context.", "This doesn't seem related to pandas" ]
2,148,607,295
57,565
DOC: Series.diff with boolean dtype does not return a series of dtype float
open
2024-02-22T09:26:53
2024-04-06T20:00:12
null
https://github.com/pandas-dev/pandas/issues/57565
true
null
null
from-nowhere
4
### Pandas version checks - [X] I have checked that the issue still exists on the latest versions of the docs on `main` [here](https://pandas.pydata.org/docs/dev/) ### Location of the documentation https://pandas.pydata.org/docs/reference/api/pandas.Series.diff.html#pandas.Series.diff https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.diff.html#pandas.DataFrame.diff ### Documentation problem The documentation for `pandas.Series.diff` and `pandas.DataFrame.diff` states that no matter the dtype of the original series/column, the output will be of dtype `float64`. This is not true for series/columns of dtypes `bool` -- the output here is of dtype `object`. For example: ```py import pandas as pd # pd.__version__ == '2.2.0' s = pd.Series([True, True, False, False, True]) d = s.diff() # d.dtype is now 'object' ``` Indeed, the underlying function [algorithms.diff](https://github.com/pandas-dev/pandas/blob/v2.2.0/pandas/core/algorithms.py#L1363) explicitly differentiates between boolean and integer dtypes. ### Suggested fix for documentation The `Notes` section should read something like this: ``` Notes ----- For boolean dtypes, this uses :meth:`operator.xor` rather than :meth:`operator.sub` and the result's dtype is ``object``. Otherwise, the result is calculated according to the current dtype in {klass}, however the dtype of the result is always float64. ```
[ "Docs", "Dtype Conversions", "Needs Discussion", "Transformations" ]
0
0
0
0
0
0
0
0
[ "I am also open to change the function behaviour to return a float64 dtype, as advertised. This would also solve another problem: in 2.2.0, downcasting object dtypes by fillna etc. is deprecated: `s.diff().fillna(False)` produces a warning and the best replacement I could come up with is `s.diff().astype(float).fillna(0.0).astype(bool)`", "Thanks for the report. Returning object is the behavior on 1.0.0; haven't tried prior versions. I'm +1 on agreeing with the docs here and returning float64 instead of object dtype.\r\n\r\nIt might also be worth adding a `fill_value` argument, similar to `shift`.\r\n\r\nCould use some other eyes - cc @MarcoGorelli.", "Looking at [issue 821 in pandas-stubs](https://github.com/pandas-dev/pandas-stubs/issues/821) it looks like `Series.diff()` does not always returns `float64` it can return `pandas.Timedelta`.\r\n\r\nBeside is look strange to me when making the difference of 2 integers to return a float. It may be due to pandas/numpy internal but mathematically speeking `int` - `int` = `int`. ( `uint` - `uint` = `int` to link with #4899)\r\n\r\nI made a short review of current behavior:\r\n\r\n> float ➡️ float\r\n> int ➡️ float\r\n> unit ➡️ float\r\n> timestamp ➡️ timedelta\r\n> period ➡️ object\r\n> timedelta ➡️ timedelta64\r\n> interval ➡️ TypeError: IntervalArray has no 'diff' method. Convert to a suitable dtype prior to calling 'diff'.\r\n> bool ➡️ object\r\n> object ➡️ object", "I made some more test to cover all possible series types:\r\n\r\n> bytes ➡️ numpy.core._exceptions._UFuncNoLoopError: ufunc 'subtract' did not contain a loop with signature matching types (dtype('S21'), dtype('S21')) -> None\r\n> dtype ➡️ TypeError: unsupported operand type(s) for -: 'type' and 'type'\r\n> datetime.date ➡️ timeDelta\r\n> datetime.time ➡️ TypeError: unsupported operand type(s) for -: 'datetime.time' and 'datetime.time'\r\n> complex ➡️ complex\r\n> Baseoffset considered already as object ➡️ object\r\n\r\nPretty strange that `datetime.time` throws and error. Would that be a bug ?" ]
2,148,596,521
57,564
BUG: GroupBy float16 indexes are not supported
closed
2024-02-22T09:21:54
2024-02-23T06:55:02
2024-02-22T18:31:09
https://github.com/pandas-dev/pandas/issues/57564
true
null
null
BohdanBilonoh
2
### Pandas version checks - [X] I have checked that this issue has not already been reported. - [X] I have confirmed this bug exists on the [latest version](https://pandas.pydata.org/docs/whatsnew/index.html) of pandas. - [X] I have confirmed this bug exists on the [main branch](https://pandas.pydata.org/docs/dev/getting_started/install.html#installing-the-development-version-of-pandas) of pandas. ### Reproducible Example ```python import pandas as pd import numpy as np df = pd.DataFrame({ "column1": np.array([0.1, 0.1, 0.1, 0.2, 0.2, 0.2], dtype=np.float16), "column2": [1,2,3,4,5,6] }) df.groupby("column1").groups ``` ### Issue Description GroupBy fails with float16 key type ### Expected Behavior GroupBy should support float16 key dtype ### Installed Versions INSTALLED VERSIONS ------------------ commit : fc37c83c2deb59253ae2d10ca631b6a1242cfdcb python : 3.11.8.final.0 python-bits : 64 OS : Linux OS-release : 5.15.0-94-generic Version : #104~20.04.1-Ubuntu SMP Tue Jan 16 13:34:09 UTC 2024 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : en_US.UTF-8 LANG : en_US.UTF-8 LOCALE : en_US.UTF-8 pandas : 3.0.0.dev0+407.gfc37c83c2d numpy : 1.26.4 pytz : 2024.1 dateutil : 2.8.2 setuptools : 69.1.0 pip : 24.0 Cython : 3.0.0 pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : None IPython : 8.21.0 pandas_datareader : None adbc-driver-postgresql: None adbc-driver-sqlite : None bs4 : None bottleneck : None fastparquet : None fsspec : None gcsfs : None matplotlib : None numba : None numexpr : None odfpy : None openpyxl : None pyarrow : 15.0.0 pyreadstat : None python-calamine : None pyxlsb : None s3fs : None scipy : None sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None zstandard : None tzdata : 2024.1 qtpy : None pyqt5 : None
[ "Bug", "Needs Triage" ]
0
0
0
0
0
0
0
0
[ "float16 is not supported In pandas, you'll have a bad time using it", "Thank you for clarification!" ]
2,148,429,359
57,563
DOC: fix ES01 for pandas.Flags
closed
2024-02-22T07:45:14
2024-02-23T02:36:10
2024-02-22T17:00:31
https://github.com/pandas-dev/pandas/pull/57563
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57563
https://github.com/pandas-dev/pandas/pull/57563
jordan-d-murphy
1
All ES01 Errors resolved in the following cases: 1. scripts/validate_docstrings.py --format=actions --errors=ES01 pandas.Flags - [x] xref https://github.com/pandas-dev/pandas/issues/57440 - [x] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [x] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.
[ "Docs" ]
0
0
0
0
0
0
0
0
[ "Thanks @jordan-d-murphy " ]
2,148,318,837
57,562
DOC: fixing GL08 errors for pandas.DatetimeIndex.as_unit and pandas.DatetimeIndex.freq
closed
2024-02-22T06:32:35
2024-02-26T18:24:00
2024-02-26T18:12:56
https://github.com/pandas-dev/pandas/pull/57562
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57562
https://github.com/pandas-dev/pandas/pull/57562
jordan-d-murphy
3
All GL08 Errors resolved in the following cases: 1. scripts/validate_docstrings.py --format=actions --errors=GL08 pandas.DatetimeIndex.as_unit 2. scripts/validate_docstrings.py --format=actions --errors=GL08 pandas.DatetimeIndex.freq _Note: [6232a2e](https://github.com/pandas-dev/pandas/pull/57562/commits/6232a2ed2590fb8d8b43658adc009688cb30dce2) commit message was a typo, this commit is for GL08 errors_ - [x] xref https://github.com/pandas-dev/pandas/issues/57443 - [x] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [x] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.
[ "Docs" ]
0
0
0
0
0
0
0
0
[ "pre-commit.ci autofix\r\n\r\n", "pre-commit.ci autofix\r\n\r\n\r\n", "Thanks @jordan-d-murphy " ]
2,148,247,319
57,561
DOC: fixing PR01 errors for pandas.Categorical and pandas.Categorical.__array__
closed
2024-02-22T05:43:38
2024-02-23T17:14:24
2024-02-23T17:13:26
https://github.com/pandas-dev/pandas/pull/57561
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57561
https://github.com/pandas-dev/pandas/pull/57561
jordan-d-murphy
2
All PR01 Errors resolved in the following cases: 1. scripts/validate_docstrings.py --format=actions --errors=PR01 pandas.Categorical 2. scripts/validate_docstrings.py --format=actions --errors=PR01 pandas.Categorical.__array__ - [x] xref https://github.com/pandas-dev/pandas/issues/57438 - [x] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [x] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.
[ "Docs" ]
0
0
0
0
0
0
0
0
[ "Thanks for the feedback - updated this with your suggestion, can you take another look @mroeschke? ", "Thanks @jordan-d-murphy " ]
2,147,885,269
57,560
PERF: Switch conditions in RangeIndex._shallow_copy
closed
2024-02-21T23:28:26
2024-02-22T16:35:31
2024-02-22T14:39:55
https://github.com/pandas-dev/pandas/pull/57560
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57560
https://github.com/pandas-dev/pandas/pull/57560
mroeschke
1
xref https://github.com/pandas-dev/pandas/pull/57534#issuecomment-1957832841 `is_range_indexer` lets us short circuit unlike checking the remainder ```python In [1]: from pandas import *; import numpy as np ...: np.random.seed(123) ...: size = 1_000_000 ...: ngroups = 1000 ...: data = Series(np.random.randint(0, ngroups, size=size)) + /opt/miniconda3/envs/pandas-dev/bin/ninja [1/1] Generating write_version_file with a custom command In [2]: %timeit data.groupby(data).groups 16.8 ms ± 183 µs per loop (mean ± std. dev. of 7 runs, 100 loops each) # PR In [3]: %timeit data.groupby(data).groups 17.6 ms ± 114 µs per loop (mean ± std. dev. of 7 runs, 100 loops each) # main ```
[ "Performance", "Index" ]
0
0
0
0
0
0
0
0
[ "thx @mroeschke " ]
2,147,879,125
57,559
PERF: Improve merge performance
closed
2024-02-21T23:22:01
2025-04-15T16:27:36
2025-04-15T16:27:35
https://github.com/pandas-dev/pandas/pull/57559
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57559
https://github.com/pandas-dev/pandas/pull/57559
phofl
3
- [ ] closes #xxxx (Replace xxxx with the GitHub issue number) - [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature. this avoids a bunch of unnecessary checks, might be worth it ``` | Change | Before [b2b1aae3] <merge~1> | After [aebecfe9] <merge> | Ratio | Benchmark (Parameter) | |----------|-------------------------------|----------------------------|---------|---------------------------------------------------------------------------------------------| | - | 46.9±3μs | 41.9±0.5μs | 0.89 | join_merge.ConcatIndexDtype.time_concat_series('string[pyarrow]', 'monotonic', 0, True) | | - | 210±7ms | 187±5ms | 0.89 | join_merge.I8Merge.time_i8merge('left') | | - | 2.11±0.2ms | 1.88±0.01ms | 0.89 | join_merge.MergeEA.time_merge('Float32', False) | | - | 17.1±3ms | 15.2±0.2ms | 0.89 | join_merge.MergeMultiIndex.time_merge_sorted_multiindex(('int64', 'int64'), 'inner') | | - | 1.06±0.04ms | 907±20μs | 0.86 | join_merge.Merge.time_merge_dataframe_integer_2key(False) | | - | 7.99±0.9ms | 6.82±0.06ms | 0.85 | join_merge.ConcatIndexDtype.time_concat_series('string[pyarrow]', 'non_monotonic', 1, True) | | - | 224±10ms | 191±6ms | 0.85 | join_merge.I8Merge.time_i8merge('inner') | | - | 513±90μs | 425±5μs | 0.83 | join_merge.ConcatIndexDtype.time_concat_series('string[python]', 'monotonic', 0, False) | | - | 519±100μs | 421±2μs | 0.81 | join_merge.ConcatIndexDtype.time_concat_series('string[python]', 'non_monotonic', 0, False) | | - | 1.18±0.6ms | 751±7μs | 0.63 | join_merge.ConcatIndexDtype.time_concat_series('int64[pyarrow]', 'has_na', 1, False) | ```
[ "Performance", "Reshaping", "Stale" ]
0
0
0
0
0
0
0
0
[ "@WillAyd good to merge?", "This pull request is stale because it has been open for thirty days with no activity. Please [update](https://pandas.pydata.org/pandas-docs/stable/development/contributing.html#updating-your-pull-request) and respond to this comment if you're still interested in working on this.", "I think we would want this, but it appears this has gone stale so going to close to clear the queue" ]
2,147,845,681
57,558
CLN: correct file names in a comment in _optional.py
closed
2024-02-21T22:49:11
2024-02-21T23:51:02
2024-02-21T23:50:56
https://github.com/pandas-dev/pandas/pull/57558
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57558
https://github.com/pandas-dev/pandas/pull/57558
natmokval
1
corrected file names in a comment in `pandas/compat/_optional.py`
[ "Clean" ]
0
0
0
0
0
0
0
0
[ "Thanks @natmokval " ]
2,147,821,484
57,557
Backport PR #57551: BLD: Add pyarrow extra for pip installation
closed
2024-02-21T22:28:47
2024-02-21T23:49:31
2024-02-21T23:49:28
https://github.com/pandas-dev/pandas/pull/57557
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57557
https://github.com/pandas-dev/pandas/pull/57557
mroeschke
0
null
[ "Build" ]
0
0
0
0
0
0
0
0
[]
2,147,812,469
57,556
Remove PyArrow deprecation warning
closed
2024-02-21T22:21:14
2024-02-22T17:48:22
2024-02-22T17:43:15
https://github.com/pandas-dev/pandas/pull/57556
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57556
https://github.com/pandas-dev/pandas/pull/57556
phofl
6
- [ ] closes #xxxx (Replace xxxx with the GitHub issue number) - [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.
[ "Warnings" ]
0
0
0
0
0
1
0
0
[ "/preview", "Website preview of this PR available at: https://pandas.pydata.org/preview/pandas-dev/pandas/57556/", "thanks @phofl.", "Owee, I'm MrMeeseeks, Look at me.\n\nThere seem to be a conflict, please backport manually. Here are approximate instructions:\n\n1. Checkout backport branch and update it.\n\n```\ngit checkout 2.2.x\ngit pull\n```\n\n2. Cherry pick the first parent branch of the this PR on top of the older branch:\n```\ngit cherry-pick -x -m1 4ed67ac9ef3d9fde6fb8441bc9ea33c0d786649e\n```\n\n3. You will likely have some merge/cherry-pick conflict here, fix them and commit:\n\n```\ngit commit -am 'Backport PR #57556: Remove PyArrow deprecation warning'\n```\n\n4. Push to a named branch:\n\n```\ngit push YOURFORK 2.2.x:auto-backport-of-pr-57556-on-2.2.x\n```\n\n5. Create a PR against branch 2.2.x, I would have named this PR:\n\n> \"Backport PR #57556 on branch 2.2.x (Remove PyArrow deprecation warning)\"\n\nAnd apply the correct labels and milestones.\n\nCongratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!\n\nRemember to remove the `Still Needs Manual Backport` label once the PR gets merged.\n\nIf these instructions are inaccurate, feel free to [suggest an improvement](https://github.com/MeeseeksBox/MeeseeksDev).\n ", "I'll do the backport", "#57558" ]
2,147,718,565
57,555
CLN: Remove pickle support pre-pandas 1.0
closed
2024-02-21T21:09:59
2024-02-22T22:44:01
2024-02-22T22:43:58
https://github.com/pandas-dev/pandas/pull/57555
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57555
https://github.com/pandas-dev/pandas/pull/57555
mroeschke
0
For a major pandas 3.0 release, I think it's reasonable that pickle support for pre-pandas 1.0 can be removed by now. Retry at https://github.com/pandas-dev/pandas/pull/57155
[ "Clean", "IO Pickle" ]
0
0
0
0
0
0
0
0
[]
2,147,646,687
57,554
Roadmap: remove ArrayManager
closed
2024-02-21T20:29:46
2024-02-21T22:20:48
2024-02-21T21:13:55
https://github.com/pandas-dev/pandas/pull/57554
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57554
https://github.com/pandas-dev/pandas/pull/57554
jbrockmendel
1
- [ ] closes #xxxx (Replace xxxx with the GitHub issue number) - [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature. The deprecation of ArrayManager was recently enforced; this is no longer a Roadmap item.
[ "Docs", "Clean" ]
0
0
0
0
0
0
0
0
[ "Thanks @jbrockmendel " ]
2,147,626,447
57,553
API: avoid passing Manager to subclass __init__
closed
2024-02-21T20:21:57
2024-04-10T12:08:36
2024-03-26T01:40:18
https://github.com/pandas-dev/pandas/pull/57553
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57553
https://github.com/pandas-dev/pandas/pull/57553
jbrockmendel
2
- [x] closes #57032 (Replace xxxx with the GitHub issue number) - [x] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [x] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature. Many subclasses have `__init__` methods that call `super().__init__`, which in the relevant cases with a Manager object is deprecated. The solution in this PR is to construct the pd.DataFrame/Series and pass that to the subclass's `_constructor`. This removes _sliced_from_mgr and _expanddim_from_mgr, as they are not really necessary, simplifying things a bit. Also makes _from_mgr `@final`. Can separate these simplifications into their own PR on request. xref #56681. For subclasses that currently have special handling for Manager objects in their `__init__`, they will need to move that special handling to the appropriate `_constructor(_foo)?_from_mgr` method. The only package I'm aware of that does this is geopandas, so this includes a shim special-casing GeoDataFrame intended to maintain the current behavior until they have time to move that logic. cc @jorisvandenbossche ATM the shim is only in _constructor_from_mgr, pls advise on whether something analogous is needed in constructor_sliced_from_mgr and _constructor_expanddim_from_mgr.
[ "Internals", "Constructors" ]
1
0
0
0
0
0
0
0
[ "thx @jbrockmendel ", "Owee, I'm MrMeeseeks, Look at me.\n\nThere seem to be a conflict, please backport manually. Here are approximate instructions:\n\n1. Checkout backport branch and update it.\n\n```\ngit checkout 2.2.x\ngit pull\n```\n\n2. Cherry pick the first parent branch of the this PR on top of the older branch:\n```\ngit cherry-pick -x -m1 805dbde3651fa4f7c30d5c9c247f723dceb7dfde\n```\n\n3. You will likely have some merge/cherry-pick conflict here, fix them and commit:\n\n```\ngit commit -am 'Backport PR #57553: API: avoid passing Manager to subclass __init__'\n```\n\n4. Push to a named branch:\n\n```\ngit push YOURFORK 2.2.x:auto-backport-of-pr-57553-on-2.2.x\n```\n\n5. Create a PR against branch 2.2.x, I would have named this PR:\n\n> \"Backport PR #57553 on branch 2.2.x (API: avoid passing Manager to subclass __init__)\"\n\nAnd apply the correct labels and milestones.\n\nCongratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!\n\nRemember to remove the `Still Needs Manual Backport` label once the PR gets merged.\n\nIf these instructions are inaccurate, feel free to [suggest an improvement](https://github.com/MeeseeksBox/MeeseeksDev).\n " ]
2,147,544,972
57,552
Backport PR #57439 on branch 2.2.x (BUG: read_json returning Index instead of RangeIndex)
closed
2024-02-21T19:41:37
2024-02-21T20:46:10
2024-02-21T20:46:10
https://github.com/pandas-dev/pandas/pull/57552
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57552
https://github.com/pandas-dev/pandas/pull/57552
meeseeksmachine
0
Backport PR #57439: BUG: read_json returning Index instead of RangeIndex
[ "IO JSON", "Index" ]
0
0
0
0
0
0
0
0
[]
2,147,407,878
57,551
BLD: Add pyarrow extra for pip installation
closed
2024-02-21T18:15:16
2024-02-21T22:29:11
2024-02-21T20:13:44
https://github.com/pandas-dev/pandas/pull/57551
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57551
https://github.com/pandas-dev/pandas/pull/57551
mroeschke
2
Partial feedback from #54466
[ "Build" ]
1
0
0
0
0
0
0
0
[ "thx @mroeschke ", "Owee, I'm MrMeeseeks, Look at me.\n\nThere seem to be a conflict, please backport manually. Here are approximate instructions:\n\n1. Checkout backport branch and update it.\n\n```\ngit checkout 2.2.x\ngit pull\n```\n\n2. Cherry pick the first parent branch of the this PR on top of the older branch:\n```\ngit cherry-pick -x -m1 734501e595d1e771774949232ed5f382e238db8d\n```\n\n3. You will likely have some merge/cherry-pick conflict here, fix them and commit:\n\n```\ngit commit -am 'Backport PR #57551: BLD: Add pyarrow extra for pip installation'\n```\n\n4. Push to a named branch:\n\n```\ngit push YOURFORK 2.2.x:auto-backport-of-pr-57551-on-2.2.x\n```\n\n5. Create a PR against branch 2.2.x, I would have named this PR:\n\n> \"Backport PR #57551 on branch 2.2.x (BLD: Add pyarrow extra for pip installation)\"\n\nAnd apply the correct labels and milestones.\n\nCongratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!\n\nRemember to remove the `Still Needs Manual Backport` label once the PR gets merged.\n\nIf these instructions are inaccurate, feel free to [suggest an improvement](https://github.com/MeeseeksBox/MeeseeksDev).\n " ]
2,147,115,718
57,550
Split pandas package into pandas and pandas-core
closed
2024-02-21T15:56:50
2024-02-29T23:49:10
2024-02-29T23:49:10
https://github.com/pandas-dev/pandas/issues/57550
true
null
null
datapythonista
12
Maybe worth a PDEP, but opening as an issue first to see what other people think, and see if it's needed or worth the time. The status quo for dependencies in pandas has been to depend on numpy, pytz, and dateutil, and for everything else just make them optional. This has been working reasonably ok, but I don't think it's ideal, and [the discussion](https://github.com/pandas-dev/pandas/issues/57424) on whether PyArrow should be required or optional is one example of it. In my opinion, there are two main things to consider. The first one is about users, and I see two broad groups: 1. The average user who will `pip/conda install pandas` and wants things to work without much hassle 2. The advanced user who wants more control on what is installed I think the current approach favors group 2, and causes users in group 1 to experience many exceptions on missing dependencies if they want to use key functionalities like `.read_excel()` or `.plot()` or have suboptimal performance if they use `.read_csv()` and others and miss PyArrow. Of course this is avoided if they install pandas with a distribution that includes the dependencies, which I think it's common. There is a second thing that it's how code is structured for soft dependencies, but I will leave it out of this discussion, as it's another complex but somehow independent topic. What I propose regarding the packaging is what many other packages do, for example R in the packaging on Linux distributions. Distribute two different packages `pandas` and `pandas-core`. The existing package `pandas` would be renamed to `pandas-core`, and users who would want a minimal installation would be able to use it. A new metapackage would be created with the existing name `pandas`. It'd be a metapackage / "empty" package with just dependencies to `pandas-code`, `pyarrow`, `matplotlib`... and any other package we consider important to have by default. I think this would solve in a reasonable way the discussion on whether to make PyArrow required, and in general improve the experience of most pandas users. @pandas-dev/pandas-core thoughts?
[ "Build", "Ideas", "Release", "Needs Discussion", "Dependencies" ]
0
0
0
0
0
0
0
0
[ "I like the idea of having a \"minimal\" installation that covers most common use cases and avoids downloading unneeded packages. I would suggest the name `minipandas`, akin to how `miniconda` vs. `anaconda` are a minimal and maximal version of anaconda.\r\n\r\nWith respect to the `pyarrow` issue, we'd then have to make sure that `minipandas` would work without `pyarrow` being installed.\r\n\r\nOne other thought - I imagine the current test suite would have to be split into tests appropriate for `minipandas` and `pandas` , and there would be an additional burden when building distributions. We'd also have to carefully examine the docs to determine which parts need a \"full pandas\" label to indicate that you need the full package (or specific dependencies) for it to work.\r\n", "I do think this would be useful but mainly for considering how the code is packaged and less about how dependencies are bundled (which seems to be the focus here?). For pip installations we have the pip extras set up and understandably conda doesn't have something like that (yet). If this re-packaging is to make the conda installation story nicer I'm not sure if it's worth it.\r\n\r\nJust noting that `core` seems to be the \"common\" prefix for minimal packages in Python too:\r\n\r\nhttps://anaconda.org/conda-forge/jupyter_core\r\nhttps://anaconda.org/conda-forge/dask-core\r\nhttps://anaconda.org/conda-forge/poetry-core\r\nhttps://anaconda.org/conda-forge/botocore", "> which seems to be the focus here?\r\n\r\nMy main point is about the UX, anything else I'm personally flexible and can be discussed later.\r\n\r\nI think `pip install pandas` and `conda install pandas` should install PyArrow, and possibly Matplotlib and other dependencies. And there should be a way to install pandas without any optional dependencies, `pip install pandas[core]` and `conda install pandas-core`, or whatever makes sense and is feasible.", "> I think `pip install pandas` and `conda install pandas` should install PyArrow, and possibly Matplotlib and other dependencies. And there should be a way to install pandas without any optional dependencies, `pip install pandas[core]` and `conda install pandas-core`, or whatever makes sense and is feasible.\r\n\r\nAs long as PDEP-10 holds I think pyarrow is a _core_ package. Outside of that how much of a difference is this expected to make? I think there is also a downside to having separate packages because then you start to fragment the user base", "The difference is that by default users will get our recommended dependencies, as opposed as now, since the main packages will now add them, still leaving the option for users to install a version with no optional dependencies.\r\n\r\nMaking up the numbers, but if 20% of users have PyArrow now, maybe we'll get 80% of them, making pandas faster for many users who don't know or don't care much on what to install, and trust us on providing what they need by default.\r\n\r\nI personally don't see the fragmentation problem you mention. This solution has been implemented for decades in the Linux world. If you want KDE for example, you just install the `kde` package and you get a notepad, a calculator, a calendar... If you have a reason to not have everything that KDE provides, you can still install `kde-core` and the specific packages you want. I wouldn't say KDE users are fragmented because of this, or that pandas users will be. We are already dealing with an user base where each individual has a different set of dependencies. We'll affect the percentage of users that have some of the pandas optional dependencies, but other than that I personally don't see a significant change or any drawback. the pandas installed will be exactly the same, the one in `pandas-core`, which will be installed by both the `pandas` and the `pandas-core` packages.", "There is already a great mechanism and all that is needed are some recommendations like installing `pandas[all]` (or full or kitchen-sink) and possibly other subsets like `pandas[io]`. \n\nI think it would be a mistake to try and redefine pandas to be some huge set of dependencies, and to introduce some other package to be the current pandas. \n", "I think this is well known, but feels worth stating anyways: no matter how its implemented, if there are ways of using pandas without pyarrow, then we have to maintain both \"pandas with pyarrow\" and \"pandas without pyarrow\" - which to me was the main reasons for PDEP-10.\r\n\r\nIf pyarrow is always opt-in, then I don't see much issue with this. But if we are having e.g. \"string[pyarrow] when pyarrow is installed and otherwise numpy object\" type inference, then users will have different behavior in pandas itself depending on whether a third party package is installed or not. That seems like a very bad user experience to me.", "> I think this is well known, but feels worth stating anyways: no matter how its implemented, if there are ways of using pandas without pyarrow, then we have to maintain both \"pandas with pyarrow\" and \"pandas without pyarrow\" - which to me was the main reasons for PDEP-10.\r\n> \r\n\r\nThat was my understanding of one of the core reasons for PDEP-10. I was was one of the few people voting against PDEP-10, but now it has been voted is it not supposed to be accepted it and stuck with? Unless a new PDEP or amendment to it is put forward then surely this is out of scope until then. According to the PDEP the warning should be retained also and not repealed by a close majority vote which might also not follow PDEP rules.\r\n\r\n\r\n", "I agree, and it's surely not the goal of this issue to cancel PDEP-10. Also, while having two packages could be used to install PyArrow more broadly without requiring, the scope of what I'm discussing here is not limited to PyArrow and could be used to other dependencies that we recommend (or assume users are most likely to want) but we don't want to force, for example Matplotlib.\r\n\r\nFrom the previous discussions seems like several people have interest in not moving forward with PDEP-10, at least as is. I fully agree that this issue is not where we want to decide or even discuss it. But if there is interest in implementing the two packages for default and minimal dependencies, I think it can make a difference for future discussions on requiring Arrow.\r\n\r\nAnd clearly, this issue doesn't help with cleaning our codebase of `if pyarrow` or having to deal with two separate cases. The main change I envision is a significant increase in the number of users who have PyArrow installed.\r\n\r\nI'm personally +1 on moving forward with PDEP-10, fully requiring PyArrow and keeping the warning, but if many people dislike the PDEP now, I think we'll have to have a new discussion.", "> There is already a great mechanism and all that is needed are some recommendations like installing `pandas[all]` (or full or kitchen-sink) and possibly other subsets like `pandas[io]`.\r\n> \r\n> I think it would be a mistake to try and redefine pandas to be some huge set of dependencies, and to introduce some other package to be the current pandas.\r\n\r\nAgreed with this. Extras should stay extras. \r\n\r\nIIRC, the -core thing is probably specific to conda-forge, I've never seen it used with a project on PyPI.", "> There is already a great mechanism and all that is needed are some recommendations like installing `pandas[all]` (or full or kitchen-sink) and possibly other subsets like `pandas[io]`.\r\n> \r\n> I think it would be a mistake to try and redefine pandas to be some huge set of dependencies, and to introduce some other package to be the current pandas.\r\n\r\nAgree. And we should have more detailed installation instructions to educate users on using extras.\r\n\r\nAnd I think we could have a `pandas-core` containing all (or some) the extension modules so we could have more fine-grained tests and benchmarks. It'll also speed up CI and improve developer experience. ", "Thanks all for the feedback. It doesn't seem there is much interest to move forward with this at this point. I guess in the future something similar can be considered for conda-forge, which doesn't have extras like pip, but I'll close this issue, which was specific to making the \"normal\" `pandas` package to install a subset of optional dependencies, which doesn't have much support." ]
2,146,930,446
57,549
BUG: .rolling-method is not working properly when called with a timedelta
open
2024-02-21T14:44:04
2024-04-01T20:57:08
null
https://github.com/pandas-dev/pandas/issues/57549
true
null
null
malte-fu
6
### Pandas version checks - [X] I have checked that this issue has not already been reported. - [X] I have confirmed this bug exists on the [latest version](https://pandas.pydata.org/docs/whatsnew/index.html) of pandas. - [X] I have confirmed this bug exists on the [main branch](https://pandas.pydata.org/docs/dev/getting_started/install.html#installing-the-development-version-of-pandas) of pandas. ### Reproducible Example ```python df = pd.DataFrame(index=pd.date_range(start="2024-02-01", end="2024-02-21", freq="1d")) df["A"] = df.index.day.astype(float) df.iloc[-2, 0] = np.inf df.iloc[-9, 0] = np.nan res1 = df.rolling(window=pd.Timedelta("4d")).mean() res2 = df.rolling(window=4).mean() ``` ### Issue Description When passing a timedelta to the rolling method, entries like nan and inf are being ignored. Also missing values at the beginning of the column are not taken into account for the calculation. In the Reproducible Example both results res1 and res2 should be equal, but they are not. ### Expected Behavior Missing and invalid values should be taken into account properly when passing a TimeDelta. ### Installed Versions <details> INSTALLED VERSIONS ------------------ commit : f538741432edf55c6b9fb5d0d496d2dd1d7c2457 python : 3.10.2.final.0 python-bits : 64 OS : Windows OS-release : 10 Version : 10.0.19045 machine : AMD64 processor : AMD64 Family 25 Model 80 Stepping 0, AuthenticAMD byteorder : little LC_ALL : None LANG : None LOCALE : de_DE.cp1252 pandas : 2.2.0 numpy : 1.26.4 pytz : 2024.1 dateutil : 2.8.2 setuptools : 58.1.0 pip : 21.2.4 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : None IPython : 8.21.0 pandas_datareader : None adbc-driver-postgresql: None adbc-driver-sqlite : None bs4 : None bottleneck : None dataframe-api-compat : None fastparquet : None fsspec : None gcsfs : None matplotlib : 3.8.2 numba : None numexpr : None odfpy : None openpyxl : 3.1.2 pandas_gbq : None pyarrow : 15.0.0 pyreadstat : None python-calamine : None pyxlsb : None s3fs : None scipy : 1.12.0 sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None zstandard : None tzdata : 2023.4 qtpy : None pyqt5 : None </details>
[ "Bug", "Window" ]
0
0
0
0
0
0
0
0
[ "Thanks for the report!\r\n\r\n> In the Reproducible Example both results res1 and res2 should be equal, but they are not.\r\n\r\nI don't think this is correct. From [the docs](https://pandas.pydata.org/pandas-docs/dev/reference/api/pandas.DataFrame.rolling.html):\r\n\r\n> For a window that is specified by an offset, min_periods will default to 1.\r\n> For a window that is specified by an integer, min_periods will default to the size of the window.\r\n\r\nSpecifying `min_periods` to be the same for each example, the output then matches.\r\n\r\n> entries like nan and inf are being ignored.\r\n\r\nCan you clarify what you mean here? What is the expected output?", "Thanks for the fast response.\r\n\r\nIndeed you are right and i was wrong. Still i think that for a window specified by an offset the result should be np.nan if the observed window is shorter than the specified offset. (in my example the first 3 days, since the specified offset is 4 days).\r\n\r\nFurther i would expect the result for the windows inclusing np.inf or np.nan to be np.nan. Expecialle for np.inf since it is a workaround for the related problem (groupby.mean decribed here: https://github.com/pandas-dev/pandas/issues/32696)\r\n\r\nThanks for your thoughts on this in advance.", "> Still i think that for a window specified by an offset the result should be np.nan if the observed window is shorter than the specified offset. (in my example the first 3 days, since the specified offset is 4 days).\r\n\r\nCan it be the case that the offset is not an integer multiple of the data?\r\n\r\n> Further i would expect the result for the windows inclusing np.inf or np.nan to be np.nan.\r\n\r\nFor np.nan, we would first need to implement `skipna` - I'm +1 here. We should probably set up a tracking issue for this for rolling. The one for groupby is here: https://github.com/pandas-dev/pandas/issues/15675.\r\n\r\nFor np.inf, the corresponding result for DataFrame / groupby is in fact inf, so I would think we should get the same here. Further investigations and PRs to fix are welcome!", "> Can it be the case that the offset is not an integer multiple of the data?\r\n\r\nI am not sure if i understand you right here. What i wanted to say is: The first entries of the observed dataframe should be np.nan until the entries specify an offset >= the offset specified when calling the function. Like in my example the datetimeindex has a frequence of 1 day. The specified window size is 4 days. So the first 3 entries (window size only 3 days but offset is 4 days) is too small to evaluate the specified window.", "And for e.g. `df.rolling(window=pd.Timedelta(\"3.5d\")).mean()`? Does that result in np.nan when there are only 3 and not 4 days in the window? Or since the 4th data point will never be used (even if it existed, should the result be non-nan?\r\n\r\nIn any case, I would recommend having this issue focus on the `np.inf` bug. The behavior with `window` being non-integral is documented and functioning correctly in accordance with the docs. If you think this behavior should be changed, can you open up a new issue?", "@rhshadrach I briefly looked into why infs are being ignored. The reason is the function `_prep_values` which contains the lines\r\n\r\n```python\r\n# Convert inf to nan for C funcs\r\ninf = np.isinf(values)\r\nif inf.any():\r\n values = np.where(inf, np.nan, values)\r\n```\r\n\r\n`_prep_values` is called in what seems like all the window aggregation functions and infs have been replaced by nans at least since the `rolling` module was created in 2015.\r\n\r\nI'd be happy to work on treating infs as infs, but after all this time I'm not sure we can change the default behavior by calling this a bug. What do you think about adding a `skipinf` parameter with default True? This would be a bit more flexible than something like `treat_inf_as_na` and implementing `skipna`." ]
2,146,596,329
57,548
Fix accidental loss-of-precision for to_datetime(str, unit=...)
closed
2024-02-21T12:08:47
2024-03-28T09:28:23
2024-03-27T16:51:54
https://github.com/pandas-dev/pandas/pull/57548
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57548
https://github.com/pandas-dev/pandas/pull/57548
QuLogic
7
In Pandas 1.5.3, the `float(val)` cast was inline to the `cast_from_unit` call in `array_with_unit_to_datetime`. This caused the intermediate (unnamed) value to be a Python float. Since #50301, a temporary variable was added to avoid multiple casts, but with explicit type `cdef float`, which defines a _Cython_ float. This type is 32-bit, and causes a loss of precision, and a regression in parsing from 1.5.3. Since `cast_from_unit` takes an `object`, not a more specific Cython type, remove the explicit type from the temporary `fval` variable entirely. This will cause it to be a (64-bit) Python float, and thus not lose precision. Fixes #57051 - [x] closes #xxxx (Replace xxxx with the GitHub issue number) - [x] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [x] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [n/a] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [x] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.
[ "Datetime", "Stale" ]
0
0
0
0
0
0
0
0
[ "Can this be declared as double instead? Using a PyObject is unnecessary overhead", "As noted, `cast_from_unit` takes an `object`, so that doesn't seem to save anything. Here's the diff of the generated code when you add the type (vs having it commented out since that reduces line number changes in the diff):\r\n```diff\r\n--- untyped/pandas/_libs/tslib.pyx.c\t2024-02-21 18:27:51.686387390 -0500\r\n+++ typed/pandas/_libs/tslib.pyx.c\t2024-02-21 18:24:14.824227898 -0500\r\n@@ -25828,9 +25828,9 @@\r\n int __pyx_v_is_raise;\r\n PyArrayObject *__pyx_v_iresult = 0;\r\n PyDateTime_TZInfo *__pyx_v_tz = 0;\r\n+ double __pyx_v_fval;\r\n PyObject *__pyx_v_result = NULL;\r\n PyObject *__pyx_v_val = NULL;\r\n- double __pyx_v_fval;\r\n PyObject *__pyx_v_err = NULL;\r\n __Pyx_LocalBuf_ND __pyx_pybuffernd_iresult;\r\n __Pyx_Buffer __pyx_pybuffer_iresult;\r\n@@ -25919,14 +25919,14 @@\r\n * bint is_raise = errors == \"raise\"\r\n * ndarray[int64_t] iresult\r\n * tzinfo tz = None # <<<<<<<<<<<<<<\r\n- * # double fval\r\n+ * double fval\r\n * \r\n */\r\n __Pyx_INCREF(Py_None);\r\n __pyx_v_tz = ((PyDateTime_TZInfo *)Py_None);\r\n \r\n /* \"pandas/_libs/tslib.pyx\":280\r\n- * # double fval\r\n+ * double fval\r\n * \r\n * assert is_coerce or is_raise # <<<<<<<<<<<<<<\r\n * \r\n@@ -32771,7 +32771,7 @@\r\n * ndarray[object] values,\r\n * str unit,\r\n */\r\n- __pyx_tuple__37 = PyTuple_Pack(13, __pyx_n_s_values, __pyx_n_s_unit, __pyx_n_s_errors, __pyx_n_s_i, __pyx_n_s_n, __pyx_n_s_is_coerce, __pyx_n_s_is_raise, __pyx_n_s_iresult, __pyx_n_s_tz, __pyx_n_s_result, __pyx_n_s_val, __pyx_n_s_fval, __pyx_n_s_err); if (unlikely(!__pyx_tuple__37)) __PYX_ERR(0, 239, __pyx_L1_error)\r\n+ __pyx_tuple__37 = PyTuple_Pack(13, __pyx_n_s_values, __pyx_n_s_unit, __pyx_n_s_errors, __pyx_n_s_i, __pyx_n_s_n, __pyx_n_s_is_coerce, __pyx_n_s_is_raise, __pyx_n_s_iresult, __pyx_n_s_tz, __pyx_n_s_fval, __pyx_n_s_result, __pyx_n_s_val, __pyx_n_s_err); if (unlikely(!__pyx_tuple__37)) __PYX_ERR(0, 239, __pyx_L1_error)\r\n __Pyx_GOTREF(__pyx_tuple__37);\r\n __Pyx_GIVEREF(__pyx_tuple__37);\r\n __pyx_codeobj__38 = (PyObject*)__Pyx_PyCode_New(3, 0, 0, 13, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__37, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_elliott_code_pandas_pandas, __pyx_n_s_array_with_unit_to_datetime, 239, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__38)) __PYX_ERR(0, 239, __pyx_L1_error)\r\n```", "Fair point on the existing structure of the code. But if it works should still add it - generally the more typing in Cython the better. And if this gets refactored in the future the next developer won't have to think about it", "If you see us using float anywhere else probably worth changing to double everywhere in Cython (in a follow up PR)", "Thanks a lot for your investigation and fix for this @QuLogic!", "This pull request is stale because it has been open for thirty days with no activity. Please [update](https://pandas.pydata.org/pandas-docs/stable/development/contributing.html#updating-your-pull-request) and respond to this comment if you're still interested in working on this.", "Thanks @QuLogic " ]
2,146,590,420
57,547
BUG: na_values dict form not working on index column
closed
2024-02-21T12:06:45
2024-04-09T17:08:35
2024-04-09T17:08:35
https://github.com/pandas-dev/pandas/issues/57547
true
null
null
anna-intellegens
6
### Pandas version checks - [X] I have checked that this issue has not already been reported. - [X] I have confirmed this bug exists on the [latest version](https://pandas.pydata.org/docs/whatsnew/index.html) of pandas. - [ ] I have confirmed this bug exists on the [main branch](https://pandas.pydata.org/docs/dev/getting_started/install.html#installing-the-development-version-of-pandas) of pandas. ### Reproducible Example ```python from io import StringIO from pandas._libs.parsers import STR_NA_VALUES import pandas as pd file_contents = """,x,y MA,1,2 NA,2,1 OA,,3 """ default_nan_values = STR_NA_VALUES | {"squid"} names = [None, "x", "y"] nan_mapping = {name: default_nan_values for name in names} dtype = {0: "object", "x": "float32", "y": "float32"} pd.read_csv( StringIO(file_contents), index_col=0, header=0, engine="c", dtype=dtype, names=names, na_values=nan_mapping, keep_default_na=False, ) ``` ### Issue Description I'm trying to find a way to read in an index column as exact strings, but read in the rest of the columns as NaN-able numbers or strings. The dict form of na_values seems to be the only way implied in the documentation to allow this to happen, however, when I try this, it errors with the message: ``` Traceback (most recent call last): File ".../test.py", line 17, in <module> pd.read_csv( File ".../venv/lib/python3.10/site-packages/pandas/io/parsers/readers.py", line 1024, in read_csv return _read(filepath_or_buffer, kwds) File ".../venv/lib/python3.10/site-packages/pandas/io/parsers/readers.py", line 624, in _read return parser.read(nrows) File ".../venv/lib/python3.10/site-packages/pandas/io/parsers/readers.py", line 1921, in read ) = self._engine.read( # type: ignore[attr-defined] File ".../venv/lib/python3.10/site-packages/pandas/io/parsers/c_parser_wrapper.py", line 333, in read index, column_names = self._make_index(date_data, alldata, names) File ".../venv/lib/python3.10/site-packages/pandas/io/parsers/base_parser.py", line 372, in _make_index index = self._agg_index(simple_index) File ".../venv/lib/python3.10/site-packages/pandas/io/parsers/base_parser.py", line 504, in _agg_index arr, _ = self._infer_types( File ".../venv/lib/python3.10/site-packages/pandas/io/parsers/base_parser.py", line 744, in _infer_types na_count = parsers.sanitize_objects(values, na_values) TypeError: Argument 'na_values' has incorrect type (expected set, got dict) ``` This is unhelpful, as the docs imply this should work, and I can't find any other way to turn off nan detection in the index column without disabling it in the rest of the table (which is a hard requirement) ### Expected Behavior The pandas table should be read without error, leading to a pandas table a bit like the following: ``` x y MA 1.0 2.0 NA 2.0 1.0 OA NaN 3.0 ``` ### Installed Versions This has been tested on three versions of pandas v1.5.2, v2.0.2, and v2.2.0, all with similar results. <details> INSTALLED VERSIONS ------------------ commit : fd3f57170aa1af588ba877e8e28c158a20a4886d python : 3.10.11.final.0 python-bits : 64 OS : Linux OS-release : 6.5.0-18-generic Version : #18~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Feb 7 11:40:03 UTC 2 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_GB.UTF-8 LOCALE : en_GB.UTF-8 pandas : 2.2.0 numpy : 1.26.3 pytz : 2023.3.post1 dateutil : 2.8.2 setuptools : 69.0.3 pip : 23.2.1 Cython : None pytest : 7.4.4 hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : 1.1 pymysql : None psycopg2 : 2.9.9 jinja2 : 3.1.3 IPython : None pandas_datareader : None adbc-driver-postgresql: None adbc-driver-sqlite : None bs4 : None bottleneck : None dataframe-api-compat : None fastparquet : None fsspec : None gcsfs : None matplotlib : None numba : 0.58.1 numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pyreadstat : None python-calamine : None pyxlsb : None s3fs : None scipy : 1.11.4 sqlalchemy : None tables : None tabulate : 0.9.0 xarray : None xlrd : None zstandard : None tzdata : 2024.1 qtpy : None pyqt5 : None </details>
[ "Bug", "IO CSV" ]
0
0
0
0
0
0
0
0
[ "import io\r\nimport pandas as pd\r\n\r\nfile_contents = \"\"\"\r\n,x,y\r\nMA,1,2\r\nNA,2,1\r\nOA,,3\r\n\"\"\"\r\n\r\ndefault_nan_values = set([\"NA\", \"squid\"])\r\nnames = [None, \"x\", \"y\"]\r\nnan_mapping = {name: default_nan_values for name in names}\r\ndtype = {0: \"object\", \"x\": \"float32\", \"y\": \"float32\"}\r\n\r\ntry:\r\n df = pd.read_csv(\r\n io.StringIO(file_contents),\r\n index_col=0,\r\n header=0,\r\n engine=\"c\",\r\n dtype=dtype,\r\n names=names,\r\n na_values=nan_mapping,\r\n keep_default_na=True,\r\n )\r\n print(df)\r\nexcept Exception as e:\r\n print(f\"Error occurred: {e}\")", "Thanks for the report, confirmed on main. Further investigations and PRs to fix are welcome!", "take", "replacing the `None` in `names` with anything else (string) works fine.", "@thomas-intellegens Sorry to bother, but in the issue post you mention that \r\n\r\n> The dict form of na_values seems to be the only way implied in the documentation to allow having no na values on a specific column\r\n\r\nIn case you might remember, was the documentation [this one?](https://pandas.pydata.org/docs/user_guide/io.html#na-and-missing-data-handling)\r\n\r\nBecause otherwise, I cannot find, in the docs, where such property is mentioned.\r\n\r\nThank you", "> In case you might remember, was the documentation [this one?](https://pandas.pydata.org/docs/user_guide/io.html#na-and-missing-data-handling)\r\n\r\nYeah, this was the section I was reading. Many thanks for taking a look at this" ]
2,146,235,942
57,546
DOC: Add missing docstrings for Index.empty, Index.view and Index.names
closed
2024-02-21T09:27:07
2024-05-07T17:18:58
2024-05-07T17:18:58
https://github.com/pandas-dev/pandas/pull/57546
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57546
https://github.com/pandas-dev/pandas/pull/57546
merlinymy
5
- [ All docstrings tests passed]
[ "Docs", "Index" ]
0
0
0
0
0
0
0
0
[ "pre-commit.ci autofix", "/preview", "> I fixed all the issues here, if someone else can have a second look to see if this can be merge. The PR is stale but it's a nice addition, so I've been addressing all the issues myself.\r\n\r\nLGTM.", "@mroeschke all docstrings seem to have already been added in main, should we close this?\r\n\r\nI think the changes here provide more info and I also see a few differences that look correct here but are wrong on main. I can follow up with a PR that will add some of the changes here to the current docstrings.", "> all docstrings seem to have already been added in main, should we close this?\r\n\r\nSure we can close this and have a follow up to improve the docstrings if needed " ]
2,145,945,775
57,545
DOC: Improve to_string() docstring to clarify that missing values are not passed through formatters
closed
2024-02-21T06:37:04
2024-06-03T18:41:21
2024-06-03T18:41:14
https://github.com/pandas-dev/pandas/pull/57545
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57545
https://github.com/pandas-dev/pandas/pull/57545
treefern
12
## Summary The current docstring for `to_string()` does not provide detail on how missing values are handled when using `formatters`. This change adds an additional block to the `formatters` docstring explaining that `formatters` are **not** invoked for missing values. It also provides some guidance on how per-column formatting of missing values can be achieved. ### Background This issue came to my attention while fixing a bug likely caused by a misunderstanding of how `to_string()` handles missing values. Specifically, formatters were assumed to be invoked on all values, including missing ones (which is not the case). ### Further issues - It is slightly unclear to me how broadly this behaviour applies (I've seen it with `DataFrame.to_string()`, and the implementation appears to be generic). I could be wrong though. - **Possible bug:** `NDFrame.to_latex()` takes a parameter called `formatters`, but following that through leads to the function `_to_latex_via_styler()` which **does not use the formatters parameter**!? This looks like a potentially incomplete implementation without annotation (at `pandas/core/generic.py` , line ~3519). I can raise an issue for that separately if desired. ### Checks ~~- [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature~~ Not applicable: no new code. - [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - Most tests passed. Exhaustive pre-commit suite did not complete due to failure of a check _completely unrelated to this change_ (incorrect type passed to `BaseBlockManager.copy()` in `pandas/core/generic.py`). ~~- [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions.~~ Not applicable: no new code. ~~- [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.~~ Not applicable: this is just an improvement to documentation of existing functionality.
[ "Docs", "Styler", "Stale" ]
0
0
0
0
0
0
0
0
[ "What do you think about moving much of the current content in this PR to the User Guide:\r\n\r\nhttps://pandas.pydata.org/docs/dev/user_guide/io.html#writing-a-formatted-string\r\n\r\nand then linking to that from the docstring? ", "Thanks for the review @datapythonista and suggestion @rhshadrach 😃\r\n\r\nI agree what I've got feels overlong for a docstring, and probably makes more sense in the main docs.\r\nI've shorted the docstring and added notes to the IO tools doc page.\r\n\r\nIncluding a link in the docstring feels a bit clunky, though I can't see a good alternative. The other option would be saying `see 'Writing a formatted string' in the 'IO tools' section of the user guide`, and that is both long and less helpful. 🤷", "/preview", "Website preview of this PR available at: https://pandas.pydata.org/preview/pandas-dev/pandas/57545/", "/preview", "> /preview\r\n\r\nThe preview needs that the documentation is built in the CI. Seems like the documentation job failed because of warnings:\r\n\r\n```\r\n/home/runner/work/pandas/pandas/pandas/core/frame.py:docstring of pandas.core.frame.DataFrame.to_html:31: ERROR: Unknown target name: \"io.formatting\".\r\n/home/runner/work/pandas/pandas/pandas/core/frame.py:docstring of pandas.core.frame.DataFrame.to_html:35: ERROR: Unknown target name: \"io.formatting\".\r\n/home/runner/work/pandas/pandas/pandas/core/frame.py:docstring of pandas.core.frame.DataFrame.to_string:31: ERROR: Unknown target name: \"io.formatting\".\r\n/home/runner/work/pandas/pandas/pandas/core/frame.py:docstring of pandas.core.frame.DataFrame.to_string:35: ERROR: Unknown target name: \"io.formatting\".\r\n```\r\n\r\nIf you get the CI green, at least for the docs job, the previewer will work.", "I think I've fixed all my issues.\r\nThe doc build is still breaking in the GH action, but due to something I don't think I caused:\r\n\r\n`Doc Build and Upload` > `Test website`\r\n```\r\n File \"/home/runner/micromamba/envs/test/lib/python3.10/site-packages/pluggy/_manager.py\", line 342, in _verify_hook\r\n raise PluginValidationError(\r\npluggy._manager.PluginValidationError: Plugin 'pytest_cython' for hook 'pytest_collect_file'\r\nhookimpl definition: pytest_collect_file(path, parent)\r\nArgument(s) {'path'} are declared in the hookimpl but can not be found in the hookspec\r\n```", "> The doc build is still breaking in the GH action, but due to something I don't think I caused:\r\n\r\npytest released today; guessing it's related to that.\r\n\r\nEdit: pytest yanked the release, rerunning the builds.", "Looks like many of the other tests failed due to CircleCI deprecating a load of Ubuntu images yesterday:\r\nhttps://status.circleci.com/incidents/m04y1p0l3f3n\r\n\r\nEdit: one of the other test failures was due to a test mismatch with `dateutil` 2.9 ([fixed upstream](https://github.com/pandas-dev/pandas/commit/c3ae17d04d3993e1c3e4c0f8824fde03b8c9beac), merged in).\r\n\r\nEdit: merging in upstream again, looks like the test error about numpy arrays with copy=false has been addressed [here](https://github.com/pandas-dev/pandas/commit/b89f1d0d05f4c9f360985abc6bda421d73bae85f). Hopefully this'll fix the last test failure.", "_bump_\r\n@rhshadrach I think everything is now addressed. If you're happy with it can you update your review to remove the requested changes flag?", "This pull request is stale because it has been open for thirty days with no activity. Please [update](https://pandas.pydata.org/pandas-docs/stable/development/contributing.html#updating-your-pull-request) and respond to this comment if you're still interested in working on this.", "Thanks for the pull request, but it appears to have gone stale. If interested in continuing, please merge in the main branch, address any review comments and/or failing tests, and we can reopen." ]
2,145,685,790
57,544
Potential regression induced by PR #57328
closed
2024-02-21T02:52:56
2024-02-26T02:30:06
2024-02-26T02:29:53
https://github.com/pandas-dev/pandas/issues/57544
true
null
null
rhshadrach
0
PR #57328 may have induced a performance regression. If it was a necessary behavior change, this may have been expected and everything is okay.\n\nPlease check the links below. If any ASVs are parameterized, the combinations of parameters that a regression has been detected for appear as subbullets.\n\n - [frame_methods.Fillna.time_fillna](https://asv-runner.github.io/asv-collection/pandas/#frame_methods.Fillna.time_fillna)\n - [inplace=True; dtype=\'object\'](https://asv-runner.github.io/asv-collection/pandas/#frame_methods.Fillna.time_fillna?p-inplace=True&p-dtype=%27object%27)\n\nSubsequent benchmarks may have skipped some commits. The link below lists the commits that are between the two benchmark runs where the regression was identified.\n\n[Commit Range](https://github.com/pandas-dev/pandas/compare/b3b97dcb723f86331b2276cc2809bd6506d472b9...590d6edb4c149eba38640d9a94f4de760d0a9fb5)\n\ncc @phofl\n
[ "Missing-data", "Performance", "Regression", "Duplicate Report" ]
0
0
0
0
0
0
0
0
[]
2,145,519,555
57,543
PERF: Return RangeIndex from RangeIndex.join when possible
closed
2024-02-21T00:18:40
2024-02-22T01:24:45
2024-02-22T01:24:39
https://github.com/pandas-dev/pandas/pull/57543
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57543
https://github.com/pandas-dev/pandas/pull/57543
mroeschke
0
Discovered in https://github.com/pandas-dev/pandas/pull/57441
[ "Performance", "Index" ]
0
0
0
0
0
0
0
0
[]
2,145,462,641
57,542
PERF: Return RangeIndex columns in str.extract when possible
closed
2024-02-20T23:28:38
2024-02-21T20:34:48
2024-02-21T20:17:51
https://github.com/pandas-dev/pandas/pull/57542
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57542
https://github.com/pandas-dev/pandas/pull/57542
mroeschke
1
Retry at https://github.com/pandas-dev/pandas/pull/57465
[ "Performance", "Strings" ]
0
0
0
0
0
0
0
0
[ "thx @mroeschke " ]
2,145,453,033
57,541
CLN: Use not .any() instead of comparing to 0
closed
2024-02-20T23:18:21
2024-02-21T00:23:03
2024-02-21T00:23:00
https://github.com/pandas-dev/pandas/pull/57541
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57541
https://github.com/pandas-dev/pandas/pull/57541
mroeschke
0
Follow up to https://github.com/pandas-dev/pandas/pull/57534 ```python In [1]: import numpy as np In [2]: zeros = np.zeros(100_000) In [4]: %timeit (zeros == 0).all() 36.4 µs ± 108 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each) In [5]: %timeit not np.all(zeros) 33.6 µs ± 111 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each) ```
[ "Clean" ]
0
0
0
0
0
0
0
0
[]
2,145,330,438
57,540
ES01 Extended Summaries for Categorical
closed
2024-02-20T21:37:18
2024-02-26T19:51:43
2024-02-26T17:58:03
https://github.com/pandas-dev/pandas/pull/57540
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57540
https://github.com/pandas-dev/pandas/pull/57540
williamking1221
1
- [x] xref #57440 - [x] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [x] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.
[]
0
0
0
0
0
0
0
0
[ "Thanks for the effort here, but it was decided that ES01 is not going to be enforced so closing. Happy to have PRs on other doc issues!" ]
2,145,327,274
57,539
BUG: ADBC Postgres writer incorrectly names the table
closed
2024-02-20T21:35:08
2024-03-28T17:55:55
2024-03-28T17:55:55
https://github.com/pandas-dev/pandas/issues/57539
true
null
null
LeonLuttenberger
1
### Pandas version checks - [X] I have checked that this issue has not already been reported. - [X] I have confirmed this bug exists on the [latest version](https://pandas.pydata.org/docs/whatsnew/index.html) of pandas. - [ ] I have confirmed this bug exists on the [main branch](https://pandas.pydata.org/docs/dev/getting_started/install.html#installing-the-development-version-of-pandas) of pandas. ### Reproducible Example ```python import adbc_driver_postgresql.dbapi as pg_dbapi import pandas as pd con = pg_dbapi.connect(uri="<PG_URI>") table_name = "my_table" df = pd.DataFrame({"c0": [1, 2, 3], "c1": ["foo", "boo", "bar"]}) df.to_sql(name=table_name, con=con, schema="public", if_exists="replace") ``` ### Issue Description The table which ends up being created in the `public` schema ends up being named `public.my_table`, instead of just `my_table`. The table is then inaccessible, as the following code throws this error `ValueError: Table my_table not found`: ```python df_out = pd.read_sql_table(table, con, schema="public") ``` The created table can be found using the following code: ```python objects = con.adbc_get_objects(depth="tables", db_schema_filter="public", catalog_filter="postgres").read_all() catalogs = objects.to_pylist() all_tables = catalogs[0]["catalog_db_schemas"][0]["db_schema_tables"] table = [x for x in all_tables if table in x["table_name"]][0] ``` ### Expected Behavior Table gets created under the name specified, without including the schema name in the table name. ### Installed Versions <details> INSTALLED VERSIONS ------------------ commit : fd3f57170aa1af588ba877e8e28c158a20a4886d python : 3.9.13.final.0 python-bits : 64 OS : Darwin OS-release : 23.3.0 Version : Darwin Kernel Version 23.3.0: Wed Dec 20 21:30:27 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T8103 machine : arm64 processor : arm byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8 pandas : 2.2.0 numpy : 1.26.2 pytz : 2023.3.post1 dateutil : 2.8.2 setuptools : 69.1.0 pip : 24.0 Cython : None pytest : 8.0.1 hypothesis : None sphinx : 7.1.2 blosc : None feather : None xlsxwriter : None lxml.etree : 4.9.3 html5lib : None pymysql : 1.4.6 psycopg2 : None jinja2 : 3.1.3 IPython : 8.12.3 pandas_datareader : None adbc-driver-postgresql: None adbc-driver-sqlite : None bs4 : 4.12.2 bottleneck : None dataframe-api-compat : None fastparquet : None fsspec : 2023.12.2 gcsfs : None matplotlib : None numba : None numexpr : None odfpy : None openpyxl : 3.1.2 pandas_gbq : None pyarrow : 15.0.0 pyreadstat : None python-calamine : None pyxlsb : None s3fs : None scipy : None sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None zstandard : None tzdata : 2023.3 qtpy : None pyqt5 : None </details>
[ "Bug", "IO SQL", "Needs Triage" ]
1
0
0
0
0
0
0
0
[ "take" ]
2,145,253,966
57,538
Backport PR #57510 on branch 2.2.x (DOC: Fix xarray example)
closed
2024-02-20T20:48:03
2024-02-20T21:32:46
2024-02-20T21:32:46
https://github.com/pandas-dev/pandas/pull/57538
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57538
https://github.com/pandas-dev/pandas/pull/57538
phofl
0
#57510
[ "Docs" ]
0
0
0
0
0
0
0
0
[]
2,145,153,247
57,537
Backport PR #57536 on branch 2.2.x (BUG: dt64 + DateOffset with milliseconds)
closed
2024-02-20T19:51:27
2024-02-20T21:32:30
2024-02-20T21:32:30
https://github.com/pandas-dev/pandas/pull/57537
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57537
https://github.com/pandas-dev/pandas/pull/57537
meeseeksmachine
0
Backport PR #57536: BUG: dt64 + DateOffset with milliseconds
[ "Datetime", "Numeric Operations", "Frequency" ]
0
0
0
0
0
0
0
0
[]
2,145,063,251
57,536
BUG: dt64 + DateOffset with milliseconds
closed
2024-02-20T18:54:30
2024-02-20T19:50:50
2024-02-20T19:50:48
https://github.com/pandas-dev/pandas/pull/57536
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57536
https://github.com/pandas-dev/pandas/pull/57536
mroeschke
1
- [ ] closes #57529 (Replace xxxx with the GitHub issue number) - [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.
[ "Datetime", "Numeric Operations", "Frequency" ]
0
0
0
0
0
0
0
0
[ "> lgtm. nanoseconds is implicitly handled right?\r\n\r\nYeah I believe so a few lines above the last `elif \"milliseconds\" in kwds:` added check" ]
2,144,991,811
57,535
TST: Allow test_dti_constructor_with_non_nano_now_today to be flaky
closed
2024-02-20T18:15:38
2024-02-20T19:53:32
2024-02-20T19:53:30
https://github.com/pandas-dev/pandas/pull/57535
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57535
https://github.com/pandas-dev/pandas/pull/57535
mroeschke
0
I see this test occasionally fail e.g. https://github.com/pandas-dev/pandas/actions/runs/7977358781/job/21780077825?pr=57510 It's probably best in the long run if we can find a way to make now/today be deterministic
[ "Unreliable Test" ]
0
0
0
0
0
0
0
0
[]
2,144,964,512
57,534
PERF: Add short circuiting to RangeIndex._shallow_copy
closed
2024-02-20T18:00:38
2024-02-21T20:16:50
2024-02-20T23:00:44
https://github.com/pandas-dev/pandas/pull/57534
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57534
https://github.com/pandas-dev/pandas/pull/57534
mroeschke
2
xref https://github.com/pandas-dev/pandas/pull/57445#issuecomment-1953881838 There needs to be More Work done to attempt to return a RangeIndex, but this should help minimize that Work
[ "Performance", "Index" ]
0
0
0
0
0
0
0
0
[ "thx", "Still a 10% slowdown compared to before, could you check if we can close the gap further?" ]
2,144,901,012
57,533
Backport PR #57489 on branch 2.2.x (REGR: astype introducing decimals when casting from int with na to string)
closed
2024-02-20T17:27:01
2024-02-20T18:51:27
2024-02-20T18:51:27
https://github.com/pandas-dev/pandas/pull/57533
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57533
https://github.com/pandas-dev/pandas/pull/57533
meeseeksmachine
0
Backport PR #57489: REGR: astype introducing decimals when casting from int with na to string
[ "Dtype Conversions" ]
0
0
0
0
0
0
0
0
[]
2,144,873,189
57,532
TYP: Remove None from copy deep values
closed
2024-02-20T17:11:39
2024-02-20T17:55:44
2024-02-20T17:55:36
https://github.com/pandas-dev/pandas/pull/57532
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57532
https://github.com/pandas-dev/pandas/pull/57532
phofl
1
- [ ] closes #xxxx (Replace xxxx with the GitHub issue number) - [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.
[ "Typing" ]
0
0
0
0
0
0
0
0
[ "Thanks @phofl " ]
2,144,832,975
57,531
BUG: `sort_values` is sorting the index too when `ignore_index=False`
open
2024-02-20T16:51:06
2024-03-04T14:20:31
null
https://github.com/pandas-dev/pandas/issues/57531
true
null
null
galipremsagar
1
### Pandas version checks - [X] I have checked that this issue has not already been reported. - [X] I have confirmed this bug exists on the [latest version](https://pandas.pydata.org/docs/whatsnew/index.html) of pandas. - [ ] I have confirmed this bug exists on the [main branch](https://pandas.pydata.org/docs/dev/getting_started/install.html#installing-the-development-version-of-pandas) of pandas. ### Reproducible Example ```python In [1]: import pandas as pd In [2]: pdf = pd.DataFrame({"a": [1, 3, 5, 2, 4], "b": [1, 1, 2, 2, 3], "c": [9, 7, 7, 7, 1]}) In [3]: pdf = pdf.set_index(['a', 'b']) In [4]: pdf Out[4]: c a b 1 1 9 3 1 7 5 2 7 2 2 7 4 3 1 In [5]: pdf.sort_values(['c'], ignore_index=False) Out[5]: c a b 4 3 1 3 1 7 2 2 7 5 2 7 1 1 9 ``` ### Issue Description When there seems to be a tie in column `c`, the `MultiIndex` levels seem to be sorted - which is kind of unexpected. The expected behavior would be to preserve the order of occurrence right? ### Expected Behavior ```python In [5]: pdf.sort_values(['c'], ignore_index=False) Out[5]: c a b 4 3 1 3 1 7 5 2 7 2 2 7 1 1 9 ``` ### Installed Versions <details> INSTALLED VERSIONS ------------------ commit : fd3f57170aa1af588ba877e8e28c158a20a4886d python : 3.10.13.final.0 python-bits : 64 OS : Linux OS-release : 5.15.0-94-generic Version : #104-Ubuntu SMP Tue Jan 9 15:25:40 UTC 2024 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8 pandas : 2.2.0 numpy : 1.26.4 pytz : 2024.1 dateutil : 2.8.2 setuptools : 69.1.0 pip : 24.0 Cython : 3.0.8 pytest : 7.4.4 hypothesis : 6.98.9 sphinx : 6.2.1 blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : 3.1.3 IPython : 8.21.0 pandas_datareader : None adbc-driver-postgresql: None adbc-driver-sqlite : None bs4 : 4.12.3 bottleneck : None dataframe-api-compat : None fastparquet : None fsspec : 2024.2.0 gcsfs : None matplotlib : None numba : 0.59.0 numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : 14.0.1 pyreadstat : None python-calamine : None pyxlsb : None s3fs : 2024.2.0 scipy : 1.12.0 sqlalchemy : 2.0.27 tables : None tabulate : 0.9.0 xarray : None xlrd : None zstandard : None tzdata : 2024.1 qtpy : None pyqt5 : None </details>
[ "Bug", "Sorting" ]
0
0
0
0
0
0
0
0
[ "I cannot seemingly get the sorted result on main\r\n\r\n```python\r\nIn [1]: In [1]: import pandas as pd\r\n ...: \r\n ...: In [2]: pdf = pd.DataFrame({\"a\": [1, 3, 5, 2, 4], \"b\": [1, 1, 2, 2, 3], \"c\": [9, 7, 7, 7, 1]})\r\n ...: \r\n ...: In [3]: pdf = pdf.set_index(['a', 'b'])\r\n\r\nIn [2]: pdf.sort_values(['c'], ignore_index=False)\r\nOut[2]: \r\n c\r\na b \r\n4 3 1\r\n3 1 7\r\n5 2 7\r\n2 2 7\r\n1 1 9\r\n```\r\n\r\nBut since the numpy sorts internally are unstable (xref https://github.com/pandas-dev/pandas/issues/53558) maybe you're hitting a case where the result gets reordered?" ]
2,144,807,055
57,530
dsintro.rst: Add missing 'the'
closed
2024-02-20T16:37:29
2024-02-20T17:05:39
2024-02-20T17:02:33
https://github.com/pandas-dev/pandas/pull/57530
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57530
https://github.com/pandas-dev/pandas/pull/57530
moshekaplan
1
dsintro.rst: Add missing 'the' to the sentence
[ "Docs" ]
0
0
0
0
0
0
0
0
[ "Thanks @moshekaplan " ]
2,144,774,156
57,529
BUG: Binary op with datetime offset is resulting in incorrect results
closed
2024-02-20T16:24:34
2024-02-20T19:50:50
2024-02-20T19:50:50
https://github.com/pandas-dev/pandas/issues/57529
true
null
null
galipremsagar
1
### Pandas version checks - [X] I have checked that this issue has not already been reported. - [X] I have confirmed this bug exists on the [latest version](https://pandas.pydata.org/docs/whatsnew/index.html) of pandas. - [ ] I have confirmed this bug exists on the [main branch](https://pandas.pydata.org/docs/dev/getting_started/install.html#installing-the-development-version-of-pandas) of pandas. ### Reproducible Example ```python In [1]: import pandas as pd In [2]: s = pd.Series([ ...: "2000-01-01 00:00:00.012345678", ...: "2000-01-31 00:00:00.012345678", ...: "2000-02-29 00:00:00.012345678", ...: ], dtype='datetime64[ns]') In [3]: s Out[3]: 0 2000-01-01 00:00:00.012345678 1 2000-01-31 00:00:00.012345678 2 2000-02-29 00:00:00.012345678 dtype: datetime64[ns] In [4]: o = pd.DateOffset(milliseconds=4) In [5]: o Out[5]: <DateOffset: milliseconds=4> In [6]: s + o Out[6]: 0 2000-01-01 00:00:00.012345678 1 2000-01-31 00:00:00.012345678 2 2000-02-29 00:00:00.012345678 dtype: datetime64[ns] In [7]: o + s Out[7]: 0 2000-01-01 00:00:00.012345678 1 2000-01-31 00:00:00.012345678 2 2000-02-29 00:00:00.012345678 dtype: datetime64[ns] ``` ### Issue Description The millisecond values are not being added. ### Expected Behavior ```python (Pdb) o + s 0 2000-01-01 00:00:00.016345678 1 2000-01-31 00:00:00.016345678 2 2000-02-29 00:00:00.016345678 dtype: datetime64[ns] ``` ### Installed Versions <details> INSTALLED VERSIONS ------------------ commit : fd3f57170aa1af588ba877e8e28c158a20a4886d python : 3.10.13.final.0 python-bits : 64 OS : Linux OS-release : 5.15.0-94-generic Version : #104-Ubuntu SMP Tue Jan 9 15:25:40 UTC 2024 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8 pandas : 2.2.0 numpy : 1.26.4 pytz : 2024.1 dateutil : 2.8.2 setuptools : 69.1.0 pip : 24.0 Cython : 3.0.8 pytest : 7.4.4 hypothesis : 6.98.9 sphinx : 6.2.1 blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : 3.1.3 IPython : 8.21.0 pandas_datareader : None adbc-driver-postgresql: None adbc-driver-sqlite : None bs4 : 4.12.3 bottleneck : None dataframe-api-compat : None fastparquet : None fsspec : 2024.2.0 gcsfs : None matplotlib : None numba : 0.59.0 numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : 14.0.1 pyreadstat : None python-calamine : None pyxlsb : None s3fs : 2024.2.0 scipy : 1.12.0 sqlalchemy : 2.0.27 tables : None tabulate : 0.9.0 xarray : None xlrd : None zstandard : None tzdata : 2024.1 qtpy : None pyqt5 : None </details>
[ "Bug", "Needs Triage" ]
0
0
0
0
0
0
0
0
[ "cc: @mroeschke " ]
2,144,772,105
57,528
dsintro.rst: Clarify Series constructor information
closed
2024-02-20T16:23:46
2024-02-20T17:06:30
2024-02-20T17:03:23
https://github.com/pandas-dev/pandas/pull/57528
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57528
https://github.com/pandas-dev/pandas/pull/57528
moshekaplan
1
Clarify sentence leading into Series constructor explanation
[ "Docs" ]
0
0
0
0
0
0
0
0
[ "Thanks @moshekaplan " ]
2,144,759,656
57,527
dsintro.rst: Add more info for first mention of ndarray
closed
2024-02-20T16:19:05
2024-02-20T17:06:07
2024-02-20T17:03:58
https://github.com/pandas-dev/pandas/pull/57527
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57527
https://github.com/pandas-dev/pandas/pull/57527
moshekaplan
1
As this is the first mention of an ndarray, qualify it by adding a link to what it is.
[ "Docs" ]
0
0
0
0
0
0
0
0
[ "Thanks @moshekaplan " ]
2,144,633,447
57,526
DOC: Clarify how groupby forms groups for mixed-value columns
closed
2024-02-20T15:23:01
2024-03-06T21:48:06
2024-03-06T21:48:05
https://github.com/pandas-dev/pandas/issues/57526
true
null
null
gabuzi
3
### Pandas version checks - [X] I have checked that the issue still exists on the latest versions of the docs on `main` [here](https://pandas.pydata.org/docs/dev/) ### Location of the documentation https://pandas.pydata.org/docs/dev/reference/api/pandas.DataFrame.groupby.html#pandas.DataFrame.groupby https://pandas.pydata.org/docs/dev/user_guide/groupby.html# ### Documentation problem In my broad view of things, groupby can work on any (combination of) hashables, but there can be some unintuitive situations that should be mentioned in the docs. E.g., the following should and does work (work as in there is no exception, but the results are not necessarily as expected): ``` >>> df = pd.DataFrame({'a': [False, 1, True, 'string'], 'b': [1, 2, 3, 4]}) a b 0 False 1 1 1 2 2 True 3 3 string 4 # let's groupby on 'a': >>> df.groupby('a').describe() b count mean std min 25% 50% 75% max a False 1.0 1.0 NaN 1.0 1.00 1.0 1.00 1.0 1 2.0 2.5 0.707107 2.0 2.25 2.5 2.75 3.0 string 1.0 4.0 NaN 4.0 4.00 4.0 4.00 4.0 ``` We can see that the value `1` and `True` were grouped together. From a Python background, that is not unexpected, as `1 == True` evaluates as `True`, i.e. `1` and `True` are equal and thus in the same group. While this data layout may be questionable, it certainly happens in reality. I find myself often using (abusing?) `groupby()` on multiple cols to identify unique combinations of values, and in this case, I would not want `1` to be considered equal to `True` (or `0` equal to `False` and whichever other 'convenience' conversions Python does). ### Suggested fix for documentation I think the docs could benefit from mentioning this pitfall. The suggested workaround that I see would be to first convert the columns to strings before the `groupby`: ``` >>> df.groupby(df['a'].apply(str)).describe() b count mean std min 25% 50% 75% max a 1 1.0 2.0 NaN 2.0 2.0 2.0 2.0 2.0 False 1.0 1.0 NaN 1.0 1.0 1.0 1.0 1.0 True 1.0 3.0 NaN 3.0 3.0 3.0 3.0 3.0 string 1.0 4.0 NaN 4.0 4.0 4.0 4.0 4.0 ```
[ "Docs", "Groupby" ]
0
0
0
0
0
0
0
0
[ "Thanks for the report, I think a line in the notes section of the docstring on `DataFrame.groupby` and `Series.groupby` would be appropriate, something like:\r\n\r\n> The implementation of `groupby` is hash-based, meaning in particular that objects that compare as equal will be considered as the same group. An exception to this is that pandas has special handling of NA values: any NA values will be collapsed to a single group, regardless of how they compare. See the user guide for more details.\r\n\r\nAn example in the user guide and your suggested workaround could then be linked to in the last sentence.\r\n\r\nWould you be interested in submitting a PR?", "Thanks for the suggestion. I'd be happy to open a PR on this. Should I insert that here at current L97? https://github.com/pandas-dev/pandas/blob/bdc79c146c2e32f2cab629be240f01658cfb6cc2/pandas/core/shared_docs.py#L95-L99\r\n\r\nShould I add an example?\r\n\r\nI just have another follow-up question: When you say hash-based, I assume this means that it always uses `__hash__()`? `__eq__()` is never considered? Should this be mentioned? Maybe in the linked user guide? The implication is that a simple `a == b` test during debugging as I did above is not actually the right thing to look at (although proper code should maintain `a.__eq__(b) == True` `=>` `a.__hash__() == b.__hash__()`, but bugs do happen...).\r\n\r\nI also just realized that the string workaround obviously has its own drawbacks, as it would now group the string `'1'` and the int `1` as equals, but I guess we don't have to provide a general solution.", "> Should I insert that here at current L97? \r\n\r\nI think this should go in the notes section which is below `See Also`; L190 here. \r\n\r\n> When you say hash-based, I assume this means that it always uses __hash__()? __eq__() is never considered? Should this be mentioned?\r\n\r\nNo - `hash` is used to produce a non-necessarily unique but often distinct number; `__eq__` is then used in the case of conflicts. This is why a requirement for writing a hash function is that two objects that are equal must have equal hashes.\r\n\r\n> I also just realized that the string workaround obviously has its own drawbacks, as it would now group the string `'1'` and the int `1` as equals, but I guess we don't have to provide a general solution.\r\n\r\nThat's a good point - this makes me quite hesitant to mention the workaround." ]
2,144,585,005
57,525
ENH: Better documentation or default behavior for GroupBy for columns with non-sortable values
open
2024-02-20T15:01:14
2024-02-26T22:37:45
null
https://github.com/pandas-dev/pandas/issues/57525
true
null
null
gabuzi
6
### Feature Type - [ ] Adding new functionality to pandas - [X] Changing existing functionality in pandas - [ ] Removing existing functionality in pandas ### Problem Description Currently (2.2.0), there is a relatively cryptic error message for groupby on columns that contain object values which are not sortable. The default argument value for `sort` in groupby is `True`, which understandably can't be honored for columns with values that just can't be sorted (e.g. of different types). ### Feature Description currently: ```python import pandas as pd df = pd.DataFrame({'a': [False, 'string', True], 'b': [1, 2, 3]}) df.groupby('a').describe() # works df = pd.DataFrame({'a': [False, (1, 2,), True], 'b': [1, 2, 3]}) df.groupby('a').describe() # fails! # TypeError: '<' not supported between instances of 'tuple' and 'bool' ``` It would be nice if Pandas would just fall back to not sorting the output. As illustrated by the case with the `'string'` value, Pandas is lenient and sorts booleans and strings without complaining, which is not technically correct, and it would be convenient if this behavior is extended to other types. ### Alternative Solutions I realize that the suggested change may be a conflicting one as the argument `sort=True` clearly requests a sorted output. For applications that would rely on this output being indeed sorted, it might be better to be more strict and keep having an error. In this case, however, it would be good to get a hint that `sort=False` would solve the issue. But then again, there's the issue that it currently is supported between non-sortable values (string vs bool), and for consistency, I would suggest the `sort` argument be ignored. ### Additional Context _No response_
[ "Enhancement", "Groupby", "Needs Discussion", "Sorting" ]
1
0
0
0
0
0
0
0
[ "Thanks for the report.\r\n\r\n> It would be nice if Pandas would just fall back to not sorting the output.\r\n\r\nI'm opposed here. This makes the output harder to predict for users and can hide bugs.\r\n\r\n> As illustrated by the case with the 'string' value, Pandas is lenient and sorts booleans and strings without complaining, which is not technically correct, and it would be convenient if this behavior is extended to other types.\r\n\r\nWhat is meant by \"is extended to other types\"? In the first half of the line above you seem to suggest pandas shouldn't be sorting Booleans and strings, and the second half you seem to suggest pandas should be sorting more combinations of dtypes.\r\n\r\n> In this case, however, it would be good to get a hint that sort=False would solve the issue.\r\n\r\nI think this is a good idea, but the difficulty will be in the implementation. The failure happens within factorize, which is used in a variety of places in pandas. Since we can be attempting to sort any Python object, we can't predict the type of error a sorting failure will raise. So it seems to me we can't reliably catch the exception in the groupby code, nor can we raise a message like \"use sort=False instead\" in factorize. \r\n\r\nRelated: https://github.com/pandas-dev/pandas/issues/54847#issuecomment-1698257419", "I suppose we could wrap the sorting in factorize:\r\n\r\nhttps://github.com/pandas-dev/pandas/blob/9a6c8f0ad02f7faa23a06a69cdd003bd4a47d6be/pandas/core/algorithms.py#L807-L814\r\n\r\nwith something like:\r\n\r\n```\r\ntry:\r\n ... = safe_sort(...)\r\nexcept Exception as err:\r\n raise type(err)(\"factorize failed sorting\") from err\r\n```\r\n\r\nand then we could reliably catch and rethrow this in groupby.\r\n\r\ncc @mroeschke - any thoughts?", "Is the exception from `safe_sort` be captured in groupby and rethrown instead?", "Thanks for picking up this issue!\r\n\r\n> > It would be nice if Pandas would just fall back to not sorting the output.\r\n> \r\n> I'm opposed here. This makes the output harder to predict for users and can hide bugs.\r\n> \r\n> > As illustrated by the case with the 'string' value, Pandas is lenient and sorts booleans and strings without complaining, which is not technically correct, and it would be convenient if this behavior is extended to other types.\r\n> \r\n> What is meant by \"is extended to other types\"? In the first half of the line above you seem to suggest pandas shouldn't be sorting Booleans and strings, and the second half you seem to suggest pandas should be sorting more combinations of dtypes.\r\n> \r\n\r\nSorry if that was a bit confusing.\r\n\r\nWhat I meant here is that I found the current behavior inconsistent in the sense that some values (strings) get special treatment and work with `sort=True` despite fudamentally not being sortable with booleans, while others don't (my tuples in the example above).\r\nEssentially, I see two options to get more consistency:\r\n1. `sort=True` fails with any values for which `a < b` would raise a basic python exception, like e.g. `'string' < False` does. E.g. my 'alternative solution' above\r\n2. Be more lenient as currently is done for strings.\r\n\r\nWhat I proposed as the desired feature was to go with option 2 to resolve this inconsistency. My main reason was that it would not change the current behavior of not raising an exception with string values. With 'not technically correct', I meant that there fundamentally just is no order between booleans and strings, but pandas doesn't complain despite `sort=True`, and I can only guess what it actually does. With \"is extended to other types\" I meant that pandas should not complain in other scenarios that are not sortable either.\r\n\r\nThis brings up the strong argument of output predictability. I think, though that a focus on predictability would support option 1. I didn't dig deeper in the code or docs, so I don't know how pandas actually sorts bools and strings for groupby, so predictability in the current state might already not be as good as it could be. For comparison, I just did a quick check and in 2.1.4 Pandas refuses to sort a pd.Series with bool and string values. Maybe it would be better to also be more strict on groupby group values (option 1).\r\n", "@mroeschke \r\n\r\n> Is the exception from `safe_sort` be captured in groupby and rethrown instead?\r\n\r\nI think you mean to try to catch the exception thrown from `safe_sort` as-is (that is, without changing `safe_sort`). Because it can be sorting an arbitrary Python object, I don't think there is a reliable way to catch error thrown from `safe_sort` within the groupby code while letting others propagate.\r\n\r\n@gabuzi \r\n\r\n> Essentially, I see two options to get more consistency:\r\n\r\nI think strings and numeric data occur common enough in index labels (e.g. pandas will default to creating column labels as integers, whereas strings are very common) that this may be special enough to warrant an exception, but that does not mean we have to \"sort the world\" :laughing: In any case, if we are going to allow strings, numerics, and NA values and nothing else, it should at least be documented better.\r\n\r\n> Maybe it would be better to also be more strict on groupby group values (option 1).\r\n\r\nIf we were designing the API from scratch, this would be my recommendation. However I think we have to consider the potential disruption to users. The benefit of having a more predictable/consistent \"what is sortable\" seems minor to the disruption it might cause, but of course I'm only guessing here. Unfortunately I see no way to be sure. I wouldn't be opposed if this gains support.", "> I don't think there is a reliable way to catch error thrown from safe_sort within the groupby code while letting others propagate.\r\n\r\nOK then doing what you suggested in https://github.com/pandas-dev/pandas/issues/57525#issuecomment-1962330777 seems reasonable" ]
2,144,427,120
57,524
BUG: Subtraction fails with matching index of different name and type
open
2024-02-20T13:49:03
2024-02-26T13:45:00
null
https://github.com/pandas-dev/pandas/issues/57524
true
null
null
Bjoern-Rapp
6
### Pandas version checks - [X] I have checked that this issue has not already been reported. - [X] I have confirmed this bug exists on the [latest version](https://pandas.pydata.org/docs/whatsnew/index.html) of pandas. - [ ] I have confirmed this bug exists on the [main branch](https://pandas.pydata.org/docs/dev/getting_started/install.html#installing-the-development-version-of-pandas) of pandas. ### Reproducible Example ```python import pandas as pd s1 = pd.Series( [23, 22, 21], index=pd.Index(["a", "b", "c"], name="index a"), dtype=pd.Int64Dtype() ) s2 = pd.Series( [21, 22, 23], index=pd.Index(["a", "b", "c"], name="index b", dtype=pd.StringDtype()), dtype=pd.Int64Dtype(), ) s1 - s2 ``` ### Issue Description This example with two series with a nullable integer data type and a index with different names and of differing data types, on with a nullable string datatype and object datatype fails with and error from `pandas._libs.algos.ensure_platform_int()` <details> ``` --------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[170], line 10 1 s1 = pd.Series( 2 [23, 22, 21], index=pd.Index(["a", "b", "c"], name="index a"), dtype=pd.Int64Dtype() 3 ) 4 s2 = pd.Series( 5 [21, 22, 23], 6 index=pd.Index(["a", "b", "c"], name="index b", dtype=pd.StringDtype()), 7 dtype=pd.Int64Dtype(), 8 ) ---> 10 s1 - s2 File ~/beftett/.venv/lib/python3.10/site-packages/pandas/core/ops/common.py:76, in _unpack_zerodim_and_defer.<locals>.new_method(self, other) 72 return NotImplemented 74 other = item_from_zerodim(other) ---> 76 return method(self, other) File ~/beftett/.venv/lib/python3.10/site-packages/pandas/core/arraylike.py:194, in OpsMixin.__sub__(self, other) 192 @unpack_zerodim_and_defer("__sub__") 193 def __sub__(self, other): --> 194 return self._arith_method(other, operator.sub) File ~/beftett/.venv/lib/python3.10/site-packages/pandas/core/series.py:5814, in Series._arith_method(self, other, op) 5813 def _arith_method(self, other, op): -> 5814 self, other = self._align_for_op(other) 5815 return base.IndexOpsMixin._arith_method(self, other, op) File ~/beftett/.venv/lib/python3.10/site-packages/pandas/core/series.py:5844, in Series._align_for_op(self, right, align_asobject) 5841 left = left.astype(object) 5842 right = right.astype(object) -> 5844 left, right = left.align(right, copy=False) 5846 return left, right File ~/beftett/.venv/lib/python3.10/site-packages/pandas/core/generic.py:10095, in NDFrame.align(self, other, join, axis, level, copy, fill_value, method, limit, fill_axis, broadcast_axis) 10082 left, _right, join_index = self._align_frame( 10083 other, 10084 join=join, (...) 10091 fill_axis=fill_axis, 10092 ) 10094 elif isinstance(other, ABCSeries): > 10095 left, _right, join_index = self._align_series( 10096 other, 10097 join=join, 10098 axis=axis, 10099 level=level, 10100 copy=copy, 10101 fill_value=fill_value, 10102 method=method, 10103 limit=limit, 10104 fill_axis=fill_axis, 10105 ) 10106 else: # pragma: no cover 10107 raise TypeError(f"unsupported type: {type(other)}") File ~/beftett/.venv/lib/python3.10/site-packages/pandas/core/generic.py:10224, in NDFrame._align_series(self, other, join, axis, level, copy, fill_value, method, limit, fill_axis) 10221 new_mgr = self._mgr.reindex_indexer(join_index, lidx, axis=1, copy=copy) 10222 left = self._constructor_from_mgr(new_mgr, axes=new_mgr.axes) > 10224 right = other._reindex_indexer(join_index, ridx, copy) 10226 else: 10227 # one has > 1 ndim 10228 fdata = self._mgr File ~/beftett/.venv/lib/python3.10/site-packages/pandas/core/series.py:4779, in Series._reindex_indexer(self, new_index, indexer, copy) 4776 return self.copy(deep=copy) 4777 return self -> 4779 new_values = algorithms.take_nd( 4780 self._values, indexer, allow_fill=True, fill_value=None 4781 ) 4782 return self._constructor(new_values, index=new_index, copy=False) File ~/beftett/.venv/lib/python3.10/site-packages/pandas/core/array_algos/take.py:115, in take_nd(arr, indexer, axis, fill_value, allow_fill) 110 arr = cast("NDArrayBackedExtensionArray", arr) 111 return arr.take( 112 indexer, fill_value=fill_value, allow_fill=allow_fill, axis=axis 113 ) --> 115 return arr.take(indexer, fill_value=fill_value, allow_fill=allow_fill) 117 arr = np.asarray(arr) 118 return _take_nd_ndarray(arr, indexer, axis, fill_value, allow_fill) File ~/beftett/.venv/lib/python3.10/site-packages/pandas/core/arrays/masked.py:905, in BaseMaskedArray.take(self, indexer, allow_fill, fill_value, axis) 894 def take( 895 self, 896 indexer, (...) 902 # we always fill with 1 internally 903 # to avoid upcasting 904 data_fill_value = self._internal_fill_value if isna(fill_value) else fill_value --> 905 result = take( 906 self._data, 907 indexer, 908 fill_value=data_fill_value, 909 allow_fill=allow_fill, 910 axis=axis, 911 ) 913 mask = take( 914 self._mask, indexer, fill_value=True, allow_fill=allow_fill, axis=axis 915 ) 917 # if we are filling 918 # we only fill where the indexer is null 919 # not existing missing values 920 # TODO(jreback) what if we have a non-na float as a fill value? File ~/beftett/.venv/lib/python3.10/site-packages/pandas/core/algorithms.py:1309, in take(arr, indices, axis, allow_fill, fill_value) 1306 if not is_array_like(arr): 1307 arr = np.asarray(arr) -> 1309 indices = ensure_platform_int(indices) 1311 if allow_fill: 1312 # Pandas style, -1 means NA 1313 validate_indices(indices, arr.shape[axis]) File pandas/_libs/algos_common_helper.pxi:22, in pandas._libs.algos.ensure_platform_int() TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType' ``` </details> If any of these three conditions is removed, the subtraction succeeds. ### Expected Behavior The subtraction should succeed. ### Installed Versions <details> commit: 2a953cf80b77e4348bf50ed724f8abc0d814d9dd python: 3.10.9.final.0 python-bits : 64 OS : Linux OS-release : 5.15.133+ Version : #1 SMP Sat Dec 30 11:18:04 UTC 2023 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : en_US.UTF-8 LANG : en_US.UTF-8 LOCALE : en_US.UTF-8 pandas : 2.1.3 numpy : 1.24.4 pytz : 2023.3.post1 dateutil : 2.8.2 setuptools : 69.0.3 pip : 23.2.1 Cython : None pytest : 7.4.4 hypothesis : 6.91.0 sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : 5.0.0 html5lib : None pymysql : None psycopg2 : None jinja2 : 3.1.2 IPython : 8.19.0 pandas_datareader : None bs4 : 4.12.2 bottleneck : None dataframe-api-compat: None fastparquet : None fsspec : 2023.12.2 gcsfs : 2023.12.2post1 matplotlib : 3.8.2 numba : 0.57.1 numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : 13.0.0 pyreadstat : None pyxlsb : None s3fs : None scipy : 1.11.4 sqlalchemy : 2.0.24 tables : None tabulate : None xarray : 2023.8.0 xlrd : None zstandard : None tzdata : 2023.4 qtpy : None pyqt5 : None </details>
[ "Bug", "Numeric Operations", "ExtensionArray" ]
0
0
0
0
0
0
0
0
[ "Thanks for the report. Might be related to #45564 - cc @phofl.\r\n\r\nhttps://github.com/pandas-dev/pandas/blob/95308514e1221200e4526dfaf248283f3d7ade06/pandas/core/series.py#L4637-L4646\r\n\r\nPrior to this PR, we would not call `take_nd` when `indexer is None`. Now we might be passing `indexer=None` to `take_nd`. For NumPy arrays, we end up in `_take_nd_array` which has the lines:\r\n\r\nhttps://github.com/pandas-dev/pandas/blob/95308514e1221200e4526dfaf248283f3d7ade06/pandas/core/array_algos/take.py#L127-L129\r\n\r\nbut no such logic exists for EAs. Perhaps it should?", "take", "take", "take", "take", "take" ]
2,144,203,549
57,523
BUG: Test failures on 32-bit x86 with pyarrow installed
open
2024-02-20T11:53:14
2024-02-21T13:33:32
null
https://github.com/pandas-dev/pandas/issues/57523
true
null
null
mgorny
3
### Pandas version checks - [X] I have checked that this issue has not already been reported. - [X] I have confirmed this bug exists on the [latest version](https://pandas.pydata.org/docs/whatsnew/index.html) of pandas. - [ ] I have confirmed this bug exists on the [main branch](https://pandas.pydata.org/docs/dev/getting_started/install.html#installing-the-development-version-of-pandas) of pandas. ### Reproducible Example ```python python -m pytest # ;-) ``` ### Issue Description When running the test suite on 32-bit x86 with `pyarrow` installed, I'm getting the following test failures (compared to a run without `pyarrow`): ``` FAILED pandas/tests/indexes/numeric/test_indexing.py::TestGetIndexer::test_get_indexer_arrow_dictionary_target - AssertionError: numpy array are different FAILED pandas/tests/interchange/test_impl.py::test_large_string_pyarrow - OverflowError: Python int too large to convert to C ssize_t FAILED pandas/tests/frame/methods/test_join.py::test_join_on_single_col_dup_on_right[string[pyarrow]] - ValueError: putmask: output array is read-only FAILED pandas/tests/reshape/merge/test_multi.py::TestMergeMulti::test_left_join_multi_index[False-True] - ValueError: putmask: output array is read-only ``` <details> <summary>Tracebacks</summary> ```pytb _______________________________________ TestGetIndexer.test_get_indexer_arrow_dictionary_target _______________________________________ [gw8] linux -- Python 3.11.7 /var/tmp/portage/dev-python/pandas-2.2.0-r1/work/pandas-2.2.0-python3_11/install/usr/bin/python3.11 self = <pandas.tests.indexes.numeric.test_indexing.TestGetIndexer object at 0xd9180110> def test_get_indexer_arrow_dictionary_target(self): pa = pytest.importorskip("pyarrow") target = Index( ArrowExtensionArray( pa.array([1, 2], type=pa.dictionary(pa.int8(), pa.int8())) ) ) idx = Index([1]) result = idx.get_indexer(target) expected = np.array([0, -1], dtype=np.int64) > tm.assert_numpy_array_equal(result, expected) E AssertionError: numpy array are different E E Attribute "dtype" are different E [left]: int32 E [right]: int64 expected = array([ 0, -1], dtype=int64) idx = Index([1], dtype='int64') pa = <module 'pyarrow' from '/usr/lib/python3.11/site-packages/pyarrow/__init__.py'> result = array([ 0, -1], dtype=int32) self = <pandas.tests.indexes.numeric.test_indexing.TestGetIndexer object at 0xd9180110> target = Index([1, 2], dtype='dictionary<values=int8, indices=int8, ordered=0>[pyarrow]') pandas/tests/indexes/numeric/test_indexing.py:406: AssertionError ______________________________________________________ test_large_string_pyarrow ______________________________________________________ [gw8] linux -- Python 3.11.7 /var/tmp/portage/dev-python/pandas-2.2.0-r1/work/pandas-2.2.0-python3_11/install/usr/bin/python3.11 def test_large_string_pyarrow(): # GH 52795 pa = pytest.importorskip("pyarrow", "11.0.0") arr = ["Mon", "Tue"] table = pa.table({"weekday": pa.array(arr, "large_string")}) exchange_df = table.__dataframe__() result = from_dataframe(exchange_df) expected = pd.DataFrame({"weekday": ["Mon", "Tue"]}) tm.assert_frame_equal(result, expected) # check round-trip > assert pa.Table.equals(pa.interchange.from_dataframe(result), table) arr = ['Mon', 'Tue'] exchange_df = <pyarrow.interchange.dataframe._PyArrowDataFrame object at 0xd877c7d0> expected = weekday 0 Mon 1 Tue pa = <module 'pyarrow' from '/usr/lib/python3.11/site-packages/pyarrow/__init__.py'> result = weekday 0 Mon 1 Tue table = pyarrow.Table weekday: large_string ---- weekday: [["Mon","Tue"]] pandas/tests/interchange/test_impl.py:104: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3.11/site-packages/pyarrow/interchange/from_dataframe.py:113: in from_dataframe return _from_dataframe(df.__dataframe__(allow_copy=allow_copy), allow_copy = True df = weekday 0 Mon 1 Tue /usr/lib/python3.11/site-packages/pyarrow/interchange/from_dataframe.py:136: in _from_dataframe batch = protocol_df_chunk_to_pyarrow(chunk, allow_copy) allow_copy = True batches = [] chunk = <pandas.core.interchange.dataframe.PandasDataFrameXchg object at 0xccc70410> df = <pandas.core.interchange.dataframe.PandasDataFrameXchg object at 0xccc70410> /usr/lib/python3.11/site-packages/pyarrow/interchange/from_dataframe.py:182: in protocol_df_chunk_to_pyarrow columns[name] = column_to_array(col, allow_copy) allow_copy = True col = <pandas.core.interchange.column.PandasColumn object at 0xccc703d0> columns = {} df = <pandas.core.interchange.dataframe.PandasDataFrameXchg object at 0xccc70410> dtype = <DtypeKind.STRING: 21> name = 'weekday' /usr/lib/python3.11/site-packages/pyarrow/interchange/from_dataframe.py:214: in column_to_array data = buffers_to_array(buffers, data_type, allow_copy = True buffers = {'data': (PandasBuffer({'bufsize': 6, 'ptr': 3445199088, 'device': 'CPU'}), (<DtypeKind.STRING: 21>, 8, 'u', '=')), 'offsets': (PandasBuffer({'bufsize': 24, 'ptr': 1546049072, 'device': 'CPU'}), (<DtypeKind.INT: 0>, 64, 'l', '=')), 'validity': (PandasBuffer({'bufsize': 2, 'ptr': 1544334624, 'device': 'CPU'}), (<DtypeKind.BOOL: 20>, 8, 'b', '='))} col = <pandas.core.interchange.column.PandasColumn object at 0xccc703d0> data_type = (<DtypeKind.STRING: 21>, 8, 'u', '=') /usr/lib/python3.11/site-packages/pyarrow/interchange/from_dataframe.py:396: in buffers_to_array data_pa_buffer = pa.foreign_buffer(data_buff.ptr, data_buff.bufsize, _ = (<DtypeKind.STRING: 21>, 8, 'u', '=') allow_copy = True buffers = {'data': (PandasBuffer({'bufsize': 6, 'ptr': 3445199088, 'device': 'CPU'}), (<DtypeKind.STRING: 21>, 8, 'u', '=')), 'offsets': (PandasBuffer({'bufsize': 24, 'ptr': 1546049072, 'device': 'CPU'}), (<DtypeKind.INT: 0>, 64, 'l', '=')), 'validity': (PandasBuffer({'bufsize': 2, 'ptr': 1544334624, 'device': 'CPU'}), (<DtypeKind.BOOL: 20>, 8, 'b', '='))} data_buff = PandasBuffer({'bufsize': 6, 'ptr': 3445199088, 'device': 'CPU'}) data_type = (<DtypeKind.STRING: 21>, 8, 'u', '=') describe_null = (<ColumnNullType.USE_BYTEMASK: 4>, 0) length = 2 offset = 0 offset_buff = PandasBuffer({'bufsize': 24, 'ptr': 1546049072, 'device': 'CPU'}) offset_dtype = (<DtypeKind.INT: 0>, 64, 'l', '=') validity_buff = PandasBuffer({'bufsize': 2, 'ptr': 1544334624, 'device': 'CPU'}) validity_dtype = (<DtypeKind.BOOL: 20>, 8, 'b', '=') _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > ??? E OverflowError: Python int too large to convert to C ssize_t pyarrow/io.pxi:1990: OverflowError ________________________________________ test_join_on_single_col_dup_on_right[string[pyarrow]] ________________________________________ [gw5] linux -- Python 3.11.7 /var/tmp/portage/dev-python/pandas-2.2.0-r1/work/pandas-2.2.0-python3_11/install/usr/bin/python3.11 left_no_dup = a b 0 a cat 1 b dog 2 c weasel 3 d horse right_w_dups = c a <NA> meow <NA> bark <NA> um... weasel noise? <NA> nay <NA> chirp e moo dtype = 'string[pyarrow]' @pytest.mark.parametrize("dtype", ["object", "string[pyarrow]"]) def test_join_on_single_col_dup_on_right(left_no_dup, right_w_dups, dtype): # GH 46622 # Dups on right allowed by one_to_many constraint if dtype == "string[pyarrow]": pytest.importorskip("pyarrow") left_no_dup = left_no_dup.astype(dtype) right_w_dups.index = right_w_dups.index.astype(dtype) > left_no_dup.join( right_w_dups, on="a", validate="one_to_many", ) dtype = 'string[pyarrow]' left_no_dup = a b 0 a cat 1 b dog 2 c weasel 3 d horse right_w_dups = c a <NA> meow <NA> bark <NA> um... weasel noise? <NA> nay <NA> chirp e moo pandas/tests/frame/methods/test_join.py:169: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ pandas/core/frame.py:10730: in join return merge( concat = <function concat at 0xec6cdc58> how = 'left' lsuffix = '' merge = <function merge at 0xec226e88> on = 'a' other = c a <NA> meow <NA> bark <NA> um... weasel noise? <NA> nay <NA> chirp e moo rsuffix = '' self = a b 0 a cat 1 b dog 2 c weasel 3 d horse sort = False validate = 'one_to_many' pandas/core/reshape/merge.py:184: in merge return op.get_result(copy=copy) copy = None how = 'left' indicator = False left = a b 0 a cat 1 b dog 2 c weasel 3 d horse left_df = a b 0 a cat 1 b dog 2 c weasel 3 d horse left_index = False left_on = 'a' on = None op = <pandas.core.reshape.merge._MergeOperation object at 0xcbf60b30> right = c a <NA> meow <NA> bark <NA> um... weasel noise? <NA> nay <NA> chirp e moo right_df = c a <NA> meow <NA> bark <NA> um... weasel noise? <NA> nay <NA> chirp e moo right_index = True right_on = None sort = False suffixes = ('', '') validate = 'one_to_many' pandas/core/reshape/merge.py:886: in get_result join_index, left_indexer, right_indexer = self._get_join_info() copy = None self = <pandas.core.reshape.merge._MergeOperation object at 0xcbf60b30> pandas/core/reshape/merge.py:1142: in _get_join_info join_index, left_indexer, right_indexer = _left_join_on_index( left_ax = RangeIndex(start=0, stop=4, step=1) right_ax = Index([<NA>, <NA>, <NA>, <NA>, <NA>, 'e'], dtype='string', name='a') self = <pandas.core.reshape.merge._MergeOperation object at 0xcbf60b30> pandas/core/reshape/merge.py:2385: in _left_join_on_index left_key, right_key, count = _factorize_keys(lkey, rkey, sort=sort) join_keys = [<ArrowStringArray> ['a', 'b', 'c', 'd'] Length: 4, dtype: string] left_ax = RangeIndex(start=0, stop=4, step=1) lkey = <ArrowStringArray> ['a', 'b', 'c', 'd'] Length: 4, dtype: string right_ax = Index([<NA>, <NA>, <NA>, <NA>, <NA>, 'e'], dtype='string', name='a') rkey = <ArrowStringArray> [<NA>, <NA>, <NA>, <NA>, <NA>, 'e'] Length: 6, dtype: string sort = False _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ lk = <pyarrow.lib.ChunkedArray object at 0xcba48fa0> [ [ "a", "b", "c", "d" ] ] rk = <pyarrow.lib.ChunkedArray object at 0xcbf280f0> [ [ null, null, null, null, null, "e" ] ] sort = False def _factorize_keys( lk: ArrayLike, rk: ArrayLike, sort: bool = True ) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp], int]: """ Encode left and right keys as enumerated types. This is used to get the join indexers to be used when merging DataFrames. Parameters ---------- lk : ndarray, ExtensionArray Left key. rk : ndarray, ExtensionArray Right key. sort : bool, defaults to True If True, the encoding is done such that the unique elements in the keys are sorted. Returns ------- np.ndarray[np.intp] Left (resp. right if called with `key='right'`) labels, as enumerated type. np.ndarray[np.intp] Right (resp. left if called with `key='right'`) labels, as enumerated type. int Number of unique elements in union of left and right labels. See Also -------- merge : Merge DataFrame or named Series objects with a database-style join. algorithms.factorize : Encode the object as an enumerated type or categorical variable. Examples -------- >>> lk = np.array(["a", "c", "b"]) >>> rk = np.array(["a", "c"]) Here, the unique values are `'a', 'b', 'c'`. With the default `sort=True`, the encoding will be `{0: 'a', 1: 'b', 2: 'c'}`: >>> pd.core.reshape.merge._factorize_keys(lk, rk) (array([0, 2, 1]), array([0, 2]), 3) With the `sort=False`, the encoding will correspond to the order in which the unique elements first appear: `{0: 'a', 1: 'c', 2: 'b'}`: >>> pd.core.reshape.merge._factorize_keys(lk, rk, sort=False) (array([0, 1, 2]), array([0, 1]), 3) """ # TODO: if either is a RangeIndex, we can likely factorize more efficiently? if ( isinstance(lk.dtype, DatetimeTZDtype) and isinstance(rk.dtype, DatetimeTZDtype) ) or (lib.is_np_dtype(lk.dtype, "M") and lib.is_np_dtype(rk.dtype, "M")): # Extract the ndarray (UTC-localized) values # Note: we dont need the dtypes to match, as these can still be compared lk, rk = cast("DatetimeArray", lk)._ensure_matching_resos(rk) lk = cast("DatetimeArray", lk)._ndarray rk = cast("DatetimeArray", rk)._ndarray elif ( isinstance(lk.dtype, CategoricalDtype) and isinstance(rk.dtype, CategoricalDtype) and lk.dtype == rk.dtype ): assert isinstance(lk, Categorical) assert isinstance(rk, Categorical) # Cast rk to encoding so we can compare codes with lk rk = lk._encode_with_my_categories(rk) lk = ensure_int64(lk.codes) rk = ensure_int64(rk.codes) elif isinstance(lk, ExtensionArray) and lk.dtype == rk.dtype: if (isinstance(lk.dtype, ArrowDtype) and is_string_dtype(lk.dtype)) or ( isinstance(lk.dtype, StringDtype) and lk.dtype.storage in ["pyarrow", "pyarrow_numpy"] ): import pyarrow as pa import pyarrow.compute as pc len_lk = len(lk) lk = lk._pa_array # type: ignore[attr-defined] rk = rk._pa_array # type: ignore[union-attr] dc = ( pa.chunked_array(lk.chunks + rk.chunks) # type: ignore[union-attr] .combine_chunks() .dictionary_encode() ) llab, rlab, count = ( pc.fill_null(dc.indices[slice(len_lk)], -1) .to_numpy() .astype(np.intp, copy=False), pc.fill_null(dc.indices[slice(len_lk, None)], -1) .to_numpy() .astype(np.intp, copy=False), len(dc.dictionary), ) if sort: uniques = dc.dictionary.to_numpy(zero_copy_only=False) llab, rlab = _sort_labels(uniques, llab, rlab) if dc.null_count > 0: lmask = llab == -1 lany = lmask.any() rmask = rlab == -1 rany = rmask.any() if lany: np.putmask(llab, lmask, count) if rany: > np.putmask(rlab, rmask, count) E ValueError: putmask: output array is read-only count = 5 dc = <pyarrow.lib.DictionaryArray object at 0xcb83ffb0> -- dictionary: [ "a", "b", "c", "d", "e" ] -- indices: [ 0, 1, 2, 3, null, null, null, null, null, 4 ] lany = False len_lk = 4 lk = <pyarrow.lib.ChunkedArray object at 0xcba48fa0> [ [ "a", "b", "c", "d" ] ] llab = array([0, 1, 2, 3]) lmask = array([False, False, False, False]) pa = <module 'pyarrow' from '/usr/lib/python3.11/site-packages/pyarrow/__init__.py'> pc = <module 'pyarrow.compute' from '/usr/lib/python3.11/site-packages/pyarrow/compute.py'> rany = True rk = <pyarrow.lib.ChunkedArray object at 0xcbf280f0> [ [ null, null, null, null, null, "e" ] ] rlab = array([-1, -1, -1, -1, -1, 4]) rmask = array([ True, True, True, True, True, False]) sort = False pandas/core/reshape/merge.py:2514: ValueError ________________________________________ TestMergeMulti.test_left_join_multi_index[False-True] ________________________________________ [gw3] linux -- Python 3.11.7 /var/tmp/portage/dev-python/pandas-2.2.0-r1/work/pandas-2.2.0-python3_11/install/usr/bin/python3.11 self = <pandas.tests.reshape.merge.test_multi.TestMergeMulti object at 0xd20d8ff0>, sort = False, infer_string = True @pytest.mark.parametrize( "infer_string", [False, pytest.param(True, marks=td.skip_if_no("pyarrow"))] ) @pytest.mark.parametrize("sort", [True, False]) def test_left_join_multi_index(self, sort, infer_string): with option_context("future.infer_string", infer_string): icols = ["1st", "2nd", "3rd"] def bind_cols(df): iord = lambda a: 0 if a != a else ord(a) f = lambda ts: ts.map(iord) - ord("a") return f(df["1st"]) + f(df["3rd"]) * 1e2 + df["2nd"].fillna(0) * 10 def run_asserts(left, right, sort): res = left.join(right, on=icols, how="left", sort=sort) assert len(left) < len(res) + 1 assert not res["4th"].isna().any() assert not res["5th"].isna().any() tm.assert_series_equal(res["4th"], -res["5th"], check_names=False) result = bind_cols(res.iloc[:, :-2]) tm.assert_series_equal(res["4th"], result, check_names=False) assert result.name is None if sort: tm.assert_frame_equal(res, res.sort_values(icols, kind="mergesort")) out = merge(left, right.reset_index(), on=icols, sort=sort, how="left") res.index = RangeIndex(len(res)) tm.assert_frame_equal(out, res) lc = list(map(chr, np.arange(ord("a"), ord("z") + 1))) left = DataFrame( np.random.default_rng(2).choice(lc, (50, 2)), columns=["1st", "3rd"] ) # Explicit cast to float to avoid implicit cast when setting nan left.insert( 1, "2nd", np.random.default_rng(2).integers(0, 10, len(left)).astype("float"), ) i = np.random.default_rng(2).permutation(len(left)) right = left.iloc[i].copy() left["4th"] = bind_cols(left) right["5th"] = -bind_cols(right) right.set_index(icols, inplace=True) run_asserts(left, right, sort) # inject some nulls left.loc[1::4, "1st"] = np.nan left.loc[2::5, "2nd"] = np.nan left.loc[3::6, "3rd"] = np.nan left["4th"] = bind_cols(left) i = np.random.default_rng(2).permutation(len(left)) right = left.iloc[i, :-1] right["5th"] = -bind_cols(right) right.set_index(icols, inplace=True) > run_asserts(left, right, sort) bind_cols = <function TestMergeMulti.test_left_join_multi_index.<locals>.bind_cols at 0xc9928b18> i = array([ 6, 40, 33, 38, 7, 46, 28, 45, 5, 34, 12, 18, 27, 3, 9, 39, 42, 23, 0, 26, 4, 10, 14, 41, 16, 43, 15, 48, 13, 24, 20, 25, 22, 49, 2, 11, 32, 44, 47, 17, 19, 37, 21, 29, 31, 30, 35, 36, 8, 1]) icols = ['1st', '2nd', '3rd'] infer_string = True lc = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] left = 1st 2nd 3rd 4th 0 v 8.0 g 701.0 1 NaN 2.0 h 623.0 2 k NaN v 2110.0 3 l 2.0 NaN -9669.0 4 i 4.0 p 1548.0 5 NaN 8.0 s 1783.0 6 z 4.0 e 465.0 7 w NaN b 122.0 8 o 3.0 h 744.0 9 NaN 6.0 NaN -9737.0 10 h 8.0 o 1487.0 11 g 7.0 d 376.0 12 t NaN l 1119.0 13 NaN 1.0 r 1613.0 14 y 8.0 k 1104.0 15 f 0.0 NaN -9695.0 16 y 5.0 z 2574.0 17 NaN NaN r 1603.0 18 j 2.0 k 1029.0 19 b 6.0 e 461.0 20 i 3.0 i 838.0 21 NaN 5.0 NaN -9747.0 22 s NaN x 2318.0 23 w 1.0 u 2032.0 24 z 7.0 i 895.0 25 NaN 4.0 y 2343.0 26 f 6.0 m 1265.0 27 o NaN NaN -9686.0 28 s 9.0 c 308.0 29 NaN 4.0 c 143.0 30 y 2.0 f 544.0 31 l 6.0 w 2271.0 32 n NaN r 1713.0 33 NaN 9.0 NaN -9707.0 34 p 8.0 q 1695.0 35 l 6.0 k 1071.0 36 p 3.0 n 1345.0 37 NaN NaN p 1403.0 38 m 0.0 w 2212.0 39 f 1.0 NaN -9685.0 40 m 3.0 x 2342.0 41 NaN 3.0 p 1433.0 42 b NaN v 2101.0 43 l 5.0 m 1261.0 44 c 6.0 s 1862.0 45 NaN 8.0 NaN -9717.0 46 t 8.0 n 1399.0 47 b NaN f 501.0 48 g 9.0 c 296.0 49 NaN 3.0 b 33.0 right = 5th 1st 2nd 3rd z 4.0 e -465.0 m 3.0 x -2342.0 nan 9.0 nan 9707.0 m 0.0 w -2212.0 w NaN b -122.0 t 8.0 n -1399.0 s 9.0 c -308.0 nan 8.0 nan 9717.0 s -1783.0 p 8.0 q -1695.0 t NaN l -1119.0 j 2.0 k -1029.0 o NaN nan 9686.0 l 2.0 nan 9669.0 nan 6.0 nan 9737.0 f 1.0 nan 9685.0 b NaN v -2101.0 w 1.0 u -2032.0 v 8.0 g -701.0 f 6.0 m -1265.0 i 4.0 p -1548.0 h 8.0 o -1487.0 y 8.0 k -1104.0 nan 3.0 p -1433.0 y 5.0 z -2574.0 l 5.0 m -1261.0 f 0.0 nan 9695.0 g 9.0 c -296.0 nan 1.0 r -1613.0 z 7.0 i -895.0 i 3.0 i -838.0 nan 4.0 y -2343.0 s NaN x -2318.0 nan 3.0 b -33.0 k NaN v -2110.0 g 7.0 d -376.0 n NaN r -1713.0 c 6.0 s -1862.0 b NaN f -501.0 nan NaN r -1603.0 b 6.0 e -461.0 nan NaN p -1403.0 5.0 nan 9747.0 4.0 c -143.0 l 6.0 w -2271.0 y 2.0 f -544.0 l 6.0 k -1071.0 p 3.0 n -1345.0 o 3.0 h -744.0 nan 2.0 h -623.0 run_asserts = <function TestMergeMulti.test_left_join_multi_index.<locals>.run_asserts at 0xc9928bb8> self = <pandas.tests.reshape.merge.test_multi.TestMergeMulti object at 0xd20d8ff0> sort = False pandas/tests/reshape/merge/test_multi.py:158: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ pandas/tests/reshape/merge/test_multi.py:108: in run_asserts res = left.join(right, on=icols, how="left", sort=sort) bind_cols = <function TestMergeMulti.test_left_join_multi_index.<locals>.bind_cols at 0xc9928b18> icols = ['1st', '2nd', '3rd'] left = 1st 2nd 3rd 4th 0 v 8.0 g 701.0 1 NaN 2.0 h 623.0 2 k NaN v 2110.0 3 l 2.0 NaN -9669.0 4 i 4.0 p 1548.0 5 NaN 8.0 s 1783.0 6 z 4.0 e 465.0 7 w NaN b 122.0 8 o 3.0 h 744.0 9 NaN 6.0 NaN -9737.0 10 h 8.0 o 1487.0 11 g 7.0 d 376.0 12 t NaN l 1119.0 13 NaN 1.0 r 1613.0 14 y 8.0 k 1104.0 15 f 0.0 NaN -9695.0 16 y 5.0 z 2574.0 17 NaN NaN r 1603.0 18 j 2.0 k 1029.0 19 b 6.0 e 461.0 20 i 3.0 i 838.0 21 NaN 5.0 NaN -9747.0 22 s NaN x 2318.0 23 w 1.0 u 2032.0 24 z 7.0 i 895.0 25 NaN 4.0 y 2343.0 26 f 6.0 m 1265.0 27 o NaN NaN -9686.0 28 s 9.0 c 308.0 29 NaN 4.0 c 143.0 30 y 2.0 f 544.0 31 l 6.0 w 2271.0 32 n NaN r 1713.0 33 NaN 9.0 NaN -9707.0 34 p 8.0 q 1695.0 35 l 6.0 k 1071.0 36 p 3.0 n 1345.0 37 NaN NaN p 1403.0 38 m 0.0 w 2212.0 39 f 1.0 NaN -9685.0 40 m 3.0 x 2342.0 41 NaN 3.0 p 1433.0 42 b NaN v 2101.0 43 l 5.0 m 1261.0 44 c 6.0 s 1862.0 45 NaN 8.0 NaN -9717.0 46 t 8.0 n 1399.0 47 b NaN f 501.0 48 g 9.0 c 296.0 49 NaN 3.0 b 33.0 right = 5th 1st 2nd 3rd z 4.0 e -465.0 m 3.0 x -2342.0 nan 9.0 nan 9707.0 m 0.0 w -2212.0 w NaN b -122.0 t 8.0 n -1399.0 s 9.0 c -308.0 nan 8.0 nan 9717.0 s -1783.0 p 8.0 q -1695.0 t NaN l -1119.0 j 2.0 k -1029.0 o NaN nan 9686.0 l 2.0 nan 9669.0 nan 6.0 nan 9737.0 f 1.0 nan 9685.0 b NaN v -2101.0 w 1.0 u -2032.0 v 8.0 g -701.0 f 6.0 m -1265.0 i 4.0 p -1548.0 h 8.0 o -1487.0 y 8.0 k -1104.0 nan 3.0 p -1433.0 y 5.0 z -2574.0 l 5.0 m -1261.0 f 0.0 nan 9695.0 g 9.0 c -296.0 nan 1.0 r -1613.0 z 7.0 i -895.0 i 3.0 i -838.0 nan 4.0 y -2343.0 s NaN x -2318.0 nan 3.0 b -33.0 k NaN v -2110.0 g 7.0 d -376.0 n NaN r -1713.0 c 6.0 s -1862.0 b NaN f -501.0 nan NaN r -1603.0 b 6.0 e -461.0 nan NaN p -1403.0 5.0 nan 9747.0 4.0 c -143.0 l 6.0 w -2271.0 y 2.0 f -544.0 l 6.0 k -1071.0 p 3.0 n -1345.0 o 3.0 h -744.0 nan 2.0 h -623.0 sort = False pandas/core/frame.py:10730: in join return merge( concat = <function concat at 0xec6bec58> how = 'left' lsuffix = '' merge = <function merge at 0xec217e88> on = ['1st', '2nd', '3rd'] other = 5th 1st 2nd 3rd z 4.0 e -465.0 m 3.0 x -2342.0 nan 9.0 nan 9707.0 m 0.0 w -2212.0 w NaN b -122.0 t 8.0 n -1399.0 s 9.0 c -308.0 nan 8.0 nan 9717.0 s -1783.0 p 8.0 q -1695.0 t NaN l -1119.0 j 2.0 k -1029.0 o NaN nan 9686.0 l 2.0 nan 9669.0 nan 6.0 nan 9737.0 f 1.0 nan 9685.0 b NaN v -2101.0 w 1.0 u -2032.0 v 8.0 g -701.0 f 6.0 m -1265.0 i 4.0 p -1548.0 h 8.0 o -1487.0 y 8.0 k -1104.0 nan 3.0 p -1433.0 y 5.0 z -2574.0 l 5.0 m -1261.0 f 0.0 nan 9695.0 g 9.0 c -296.0 nan 1.0 r -1613.0 z 7.0 i -895.0 i 3.0 i -838.0 nan 4.0 y -2343.0 s NaN x -2318.0 nan 3.0 b -33.0 k NaN v -2110.0 g 7.0 d -376.0 n NaN r -1713.0 c 6.0 s -1862.0 b NaN f -501.0 nan NaN r -1603.0 b 6.0 e -461.0 nan NaN p -1403.0 5.0 nan 9747.0 4.0 c -143.0 l 6.0 w -2271.0 y 2.0 f -544.0 l 6.0 k -1071.0 p 3.0 n -1345.0 o 3.0 h -744.0 nan 2.0 h -623.0 rsuffix = '' self = 1st 2nd 3rd 4th 0 v 8.0 g 701.0 1 NaN 2.0 h 623.0 2 k NaN v 2110.0 3 l 2.0 NaN -9669.0 4 i 4.0 p 1548.0 5 NaN 8.0 s 1783.0 6 z 4.0 e 465.0 7 w NaN b 122.0 8 o 3.0 h 744.0 9 NaN 6.0 NaN -9737.0 10 h 8.0 o 1487.0 11 g 7.0 d 376.0 12 t NaN l 1119.0 13 NaN 1.0 r 1613.0 14 y 8.0 k 1104.0 15 f 0.0 NaN -9695.0 16 y 5.0 z 2574.0 17 NaN NaN r 1603.0 18 j 2.0 k 1029.0 19 b 6.0 e 461.0 20 i 3.0 i 838.0 21 NaN 5.0 NaN -9747.0 22 s NaN x 2318.0 23 w 1.0 u 2032.0 24 z 7.0 i 895.0 25 NaN 4.0 y 2343.0 26 f 6.0 m 1265.0 27 o NaN NaN -9686.0 28 s 9.0 c 308.0 29 NaN 4.0 c 143.0 30 y 2.0 f 544.0 31 l 6.0 w 2271.0 32 n NaN r 1713.0 33 NaN 9.0 NaN -9707.0 34 p 8.0 q 1695.0 35 l 6.0 k 1071.0 36 p 3.0 n 1345.0 37 NaN NaN p 1403.0 38 m 0.0 w 2212.0 39 f 1.0 NaN -9685.0 40 m 3.0 x 2342.0 41 NaN 3.0 p 1433.0 42 b NaN v 2101.0 43 l 5.0 m 1261.0 44 c 6.0 s 1862.0 45 NaN 8.0 NaN -9717.0 46 t 8.0 n 1399.0 47 b NaN f 501.0 48 g 9.0 c 296.0 49 NaN 3.0 b 33.0 sort = False validate = None pandas/core/reshape/merge.py:184: in merge return op.get_result(copy=copy) copy = None how = 'left' indicator = False left = 1st 2nd 3rd 4th 0 v 8.0 g 701.0 1 NaN 2.0 h 623.0 2 k NaN v 2110.0 3 l 2.0 NaN -9669.0 4 i 4.0 p 1548.0 5 NaN 8.0 s 1783.0 6 z 4.0 e 465.0 7 w NaN b 122.0 8 o 3.0 h 744.0 9 NaN 6.0 NaN -9737.0 10 h 8.0 o 1487.0 11 g 7.0 d 376.0 12 t NaN l 1119.0 13 NaN 1.0 r 1613.0 14 y 8.0 k 1104.0 15 f 0.0 NaN -9695.0 16 y 5.0 z 2574.0 17 NaN NaN r 1603.0 18 j 2.0 k 1029.0 19 b 6.0 e 461.0 20 i 3.0 i 838.0 21 NaN 5.0 NaN -9747.0 22 s NaN x 2318.0 23 w 1.0 u 2032.0 24 z 7.0 i 895.0 25 NaN 4.0 y 2343.0 26 f 6.0 m 1265.0 27 o NaN NaN -9686.0 28 s 9.0 c 308.0 29 NaN 4.0 c 143.0 30 y 2.0 f 544.0 31 l 6.0 w 2271.0 32 n NaN r 1713.0 33 NaN 9.0 NaN -9707.0 34 p 8.0 q 1695.0 35 l 6.0 k 1071.0 36 p 3.0 n 1345.0 37 NaN NaN p 1403.0 38 m 0.0 w 2212.0 39 f 1.0 NaN -9685.0 40 m 3.0 x 2342.0 41 NaN 3.0 p 1433.0 42 b NaN v 2101.0 43 l 5.0 m 1261.0 44 c 6.0 s 1862.0 45 NaN 8.0 NaN -9717.0 46 t 8.0 n 1399.0 47 b NaN f 501.0 48 g 9.0 c 296.0 49 NaN 3.0 b 33.0 left_df = 1st 2nd 3rd 4th 0 v 8.0 g 701.0 1 NaN 2.0 h 623.0 2 k NaN v 2110.0 3 l 2.0 NaN -9669.0 4 i 4.0 p 1548.0 5 NaN 8.0 s 1783.0 6 z 4.0 e 465.0 7 w NaN b 122.0 8 o 3.0 h 744.0 9 NaN 6.0 NaN -9737.0 10 h 8.0 o 1487.0 11 g 7.0 d 376.0 12 t NaN l 1119.0 13 NaN 1.0 r 1613.0 14 y 8.0 k 1104.0 15 f 0.0 NaN -9695.0 16 y 5.0 z 2574.0 17 NaN NaN r 1603.0 18 j 2.0 k 1029.0 19 b 6.0 e 461.0 20 i 3.0 i 838.0 21 NaN 5.0 NaN -9747.0 22 s NaN x 2318.0 23 w 1.0 u 2032.0 24 z 7.0 i 895.0 25 NaN 4.0 y 2343.0 26 f 6.0 m 1265.0 27 o NaN NaN -9686.0 28 s 9.0 c 308.0 29 NaN 4.0 c 143.0 30 y 2.0 f 544.0 31 l 6.0 w 2271.0 32 n NaN r 1713.0 33 NaN 9.0 NaN -9707.0 34 p 8.0 q 1695.0 35 l 6.0 k 1071.0 36 p 3.0 n 1345.0 37 NaN NaN p 1403.0 38 m 0.0 w 2212.0 39 f 1.0 NaN -9685.0 40 m 3.0 x 2342.0 41 NaN 3.0 p 1433.0 42 b NaN v 2101.0 43 l 5.0 m 1261.0 44 c 6.0 s 1862.0 45 NaN 8.0 NaN -9717.0 46 t 8.0 n 1399.0 47 b NaN f 501.0 48 g 9.0 c 296.0 49 NaN 3.0 b 33.0 left_index = False left_on = ['1st', '2nd', '3rd'] on = None op = <pandas.core.reshape.merge._MergeOperation object at 0xc9857b30> right = 5th 1st 2nd 3rd z 4.0 e -465.0 m 3.0 x -2342.0 nan 9.0 nan 9707.0 m 0.0 w -2212.0 w NaN b -122.0 t 8.0 n -1399.0 s 9.0 c -308.0 nan 8.0 nan 9717.0 s -1783.0 p 8.0 q -1695.0 t NaN l -1119.0 j 2.0 k -1029.0 o NaN nan 9686.0 l 2.0 nan 9669.0 nan 6.0 nan 9737.0 f 1.0 nan 9685.0 b NaN v -2101.0 w 1.0 u -2032.0 v 8.0 g -701.0 f 6.0 m -1265.0 i 4.0 p -1548.0 h 8.0 o -1487.0 y 8.0 k -1104.0 nan 3.0 p -1433.0 y 5.0 z -2574.0 l 5.0 m -1261.0 f 0.0 nan 9695.0 g 9.0 c -296.0 nan 1.0 r -1613.0 z 7.0 i -895.0 i 3.0 i -838.0 nan 4.0 y -2343.0 s NaN x -2318.0 nan 3.0 b -33.0 k NaN v -2110.0 g 7.0 d -376.0 n NaN r -1713.0 c 6.0 s -1862.0 b NaN f -501.0 nan NaN r -1603.0 b 6.0 e -461.0 nan NaN p -1403.0 5.0 nan 9747.0 4.0 c -143.0 l 6.0 w -2271.0 y 2.0 f -544.0 l 6.0 k -1071.0 p 3.0 n -1345.0 o 3.0 h -744.0 nan 2.0 h -623.0 right_df = 5th 1st 2nd 3rd z 4.0 e -465.0 m 3.0 x -2342.0 nan 9.0 nan 9707.0 m 0.0 w -2212.0 w NaN b -122.0 t 8.0 n -1399.0 s 9.0 c -308.0 nan 8.0 nan 9717.0 s -1783.0 p 8.0 q -1695.0 t NaN l -1119.0 j 2.0 k -1029.0 o NaN nan 9686.0 l 2.0 nan 9669.0 nan 6.0 nan 9737.0 f 1.0 nan 9685.0 b NaN v -2101.0 w 1.0 u -2032.0 v 8.0 g -701.0 f 6.0 m -1265.0 i 4.0 p -1548.0 h 8.0 o -1487.0 y 8.0 k -1104.0 nan 3.0 p -1433.0 y 5.0 z -2574.0 l 5.0 m -1261.0 f 0.0 nan 9695.0 g 9.0 c -296.0 nan 1.0 r -1613.0 z 7.0 i -895.0 i 3.0 i -838.0 nan 4.0 y -2343.0 s NaN x -2318.0 nan 3.0 b -33.0 k NaN v -2110.0 g 7.0 d -376.0 n NaN r -1713.0 c 6.0 s -1862.0 b NaN f -501.0 nan NaN r -1603.0 b 6.0 e -461.0 nan NaN p -1403.0 5.0 nan 9747.0 4.0 c -143.0 l 6.0 w -2271.0 y 2.0 f -544.0 l 6.0 k -1071.0 p 3.0 n -1345.0 o 3.0 h -744.0 nan 2.0 h -623.0 right_index = True right_on = None sort = False suffixes = ('', '') validate = None pandas/core/reshape/merge.py:886: in get_result join_index, left_indexer, right_indexer = self._get_join_info() copy = None self = <pandas.core.reshape.merge._MergeOperation object at 0xc9857b30> pandas/core/reshape/merge.py:1142: in _get_join_info join_index, left_indexer, right_indexer = _left_join_on_index( left_ax = RangeIndex(start=0, stop=50, step=1) right_ax = MultiIndex([('z', 4.0, 'e'), ('m', 3.0, 'x'), (nan, 9.0, nan), ('m', 0.0, 'w'), ('w', nan, 'b'), ('t', 8.0, 'n'), ('s', 9.0, 'c'), (nan, 8.0, nan), (nan, 8.0, 's'), ('p', 8.0, 'q'), ('t', nan, 'l'), ('j', 2.0, 'k'), ('o', nan, nan), ('l', 2.0, nan), (nan, 6.0, nan), ('f', 1.0, nan), ('b', nan, 'v'), ('w', 1.0, 'u'), ('v', 8.0, 'g'), ('f', 6.0, 'm'), ('i', 4.0, 'p'), ('h', 8.0, 'o'), ('y', 8.0, 'k'), (nan, 3.0, 'p'), ('y', 5.0, 'z'), ('l', 5.0, 'm'), ('f', 0.0, nan), ('g', 9.0, 'c'), (nan, 1.0, 'r'), ('z', 7.0, 'i'), ('i', 3.0, 'i'), (nan, 4.0, 'y'), ('s', nan, 'x'), (nan, 3.0, 'b'), ('k', nan, 'v'), ('g', 7.0, 'd'), ('n', nan, 'r'), ('c', 6.0, 's'), ('b', nan, 'f'), (nan, nan, 'r'), ('b', 6.0, 'e'), (nan, nan, 'p'), (nan, 5.0, nan), (nan, 4.0, 'c'), ('l', 6.0, 'w'), ('y', 2.0, 'f'), ('l', 6.0, 'k'), ('p', 3.0, 'n'), ('o', 3.0, 'h'), (nan, 2.0, 'h')], names=['1st', '2nd', '3rd']) self = <pandas.core.reshape.merge._MergeOperation object at 0xc9857b30> pandas/core/reshape/merge.py:2375: in _left_join_on_index lkey, rkey = _get_multiindex_indexer(join_keys, right_ax, sort=sort) join_keys = [<ArrowStringArrayNumpySemantics> ['v', nan, 'k', 'l', 'i', nan, 'z', 'w', 'o', nan, 'h', 'g', 't', nan, 'y', 'f', 'y', nan, 'j', 'b', 'i', nan, 's', 'w', 'z', nan, 'f', 'o', 's', nan, 'y', 'l', 'n', nan, 'p', 'l', 'p', nan, 'm', 'f', 'm', nan, 'b', 'l', 'c', nan, 't', 'b', 'g', nan] Length: 50, dtype: string, array([ 8., 2., nan, 2., 4., 8., 4., nan, 3., 6., 8., 7., nan, 1., 8., 0., 5., nan, 2., 6., 3., 5., nan, 1., 7., 4., 6., nan, 9., 4., 2., 6., nan, 9., 8., 6., 3., nan, 0., 1., 3., 3., nan, 5., 6., 8., 8., nan, 9., 3.]), <ArrowStringArrayNumpySemantics> ['g', 'h', 'v', nan, 'p', 's', 'e', 'b', 'h', nan, 'o', 'd', 'l', 'r', 'k', nan, 'z', 'r', 'k', 'e', 'i', nan, 'x', 'u', 'i', 'y', 'm', nan, 'c', 'c', 'f', 'w', 'r', nan, 'q', 'k', 'n', 'p', 'w', nan, 'x', 'p', 'v', 'm', 's', nan, 'n', 'f', 'c', 'b'] Length: 50, dtype: string] left_ax = RangeIndex(start=0, stop=50, step=1) right_ax = MultiIndex([('z', 4.0, 'e'), ('m', 3.0, 'x'), (nan, 9.0, nan), ('m', 0.0, 'w'), ('w', nan, 'b'), ('t', 8.0, 'n'), ('s', 9.0, 'c'), (nan, 8.0, nan), (nan, 8.0, 's'), ('p', 8.0, 'q'), ('t', nan, 'l'), ('j', 2.0, 'k'), ('o', nan, nan), ('l', 2.0, nan), (nan, 6.0, nan), ('f', 1.0, nan), ('b', nan, 'v'), ('w', 1.0, 'u'), ('v', 8.0, 'g'), ('f', 6.0, 'm'), ('i', 4.0, 'p'), ('h', 8.0, 'o'), ('y', 8.0, 'k'), (nan, 3.0, 'p'), ('y', 5.0, 'z'), ('l', 5.0, 'm'), ('f', 0.0, nan), ('g', 9.0, 'c'), (nan, 1.0, 'r'), ('z', 7.0, 'i'), ('i', 3.0, 'i'), (nan, 4.0, 'y'), ('s', nan, 'x'), (nan, 3.0, 'b'), ('k', nan, 'v'), ('g', 7.0, 'd'), ('n', nan, 'r'), ('c', 6.0, 's'), ('b', nan, 'f'), (nan, nan, 'r'), ('b', 6.0, 'e'), (nan, nan, 'p'), (nan, 5.0, nan), (nan, 4.0, 'c'), ('l', 6.0, 'w'), ('y', 2.0, 'f'), ('l', 6.0, 'k'), ('p', 3.0, 'n'), ('o', 3.0, 'h'), (nan, 2.0, 'h')], names=['1st', '2nd', '3rd']) sort = False pandas/core/reshape/merge.py:2309: in _get_multiindex_indexer zipped = zip(*mapped) index = MultiIndex([('z', 4.0, 'e'), ('m', 3.0, 'x'), (nan, 9.0, nan), ('m', 0.0, 'w'), ('w', nan, 'b'), ('t', 8.0, 'n'), ('s', 9.0, 'c'), (nan, 8.0, nan), (nan, 8.0, 's'), ('p', 8.0, 'q'), ('t', nan, 'l'), ('j', 2.0, 'k'), ('o', nan, nan), ('l', 2.0, nan), (nan, 6.0, nan), ('f', 1.0, nan), ('b', nan, 'v'), ('w', 1.0, 'u'), ('v', 8.0, 'g'), ('f', 6.0, 'm'), ('i', 4.0, 'p'), ('h', 8.0, 'o'), ('y', 8.0, 'k'), (nan, 3.0, 'p'), ('y', 5.0, 'z'), ('l', 5.0, 'm'), ('f', 0.0, nan), ('g', 9.0, 'c'), (nan, 1.0, 'r'), ('z', 7.0, 'i'), ('i', 3.0, 'i'), (nan, 4.0, 'y'), ('s', nan, 'x'), (nan, 3.0, 'b'), ('k', nan, 'v'), ('g', 7.0, 'd'), ('n', nan, 'r'), ('c', 6.0, 's'), ('b', nan, 'f'), (nan, nan, 'r'), ('b', 6.0, 'e'), (nan, nan, 'p'), (nan, 5.0, nan), (nan, 4.0, 'c'), ('l', 6.0, 'w'), ('y', 2.0, 'f'), ('l', 6.0, 'k'), ('p', 3.0, 'n'), ('o', 3.0, 'h'), (nan, 2.0, 'h')], names=['1st', '2nd', '3rd']) join_keys = [<ArrowStringArrayNumpySemantics> ['v', nan, 'k', 'l', 'i', nan, 'z', 'w', 'o', nan, 'h', 'g', 't', nan, 'y', 'f', 'y', nan, 'j', 'b', 'i', nan, 's', 'w', 'z', nan, 'f', 'o', 's', nan, 'y', 'l', 'n', nan, 'p', 'l', 'p', nan, 'm', 'f', 'm', nan, 'b', 'l', 'c', nan, 't', 'b', 'g', nan] Length: 50, dtype: string, array([ 8., 2., nan, 2., 4., 8., 4., nan, 3., 6., 8., 7., nan, 1., 8., 0., 5., nan, 2., 6., 3., 5., nan, 1., 7., 4., 6., nan, 9., 4., 2., 6., nan, 9., 8., 6., 3., nan, 0., 1., 3., 3., nan, 5., 6., 8., 8., nan, 9., 3.]), <ArrowStringArrayNumpySemantics> ['g', 'h', 'v', nan, 'p', 's', 'e', 'b', 'h', nan, 'o', 'd', 'l', 'r', 'k', nan, 'z', 'r', 'k', 'e', 'i', nan, 'x', 'u', 'i', 'y', 'm', nan, 'c', 'c', 'f', 'w', 'r', nan, 'q', 'k', 'n', 'p', 'w', nan, 'x', 'p', 'v', 'm', 's', nan, 'n', 'f', 'c', 'b'] Length: 50, dtype: string] mapped = <generator object _get_multiindex_indexer.<locals>.<genexpr> at 0xc9b7a710> sort = False pandas/core/reshape/merge.py:2306: in <genexpr> _factorize_keys(index.levels[n]._values, join_keys[n], sort=sort) .0 = <range_iterator object at 0xc9856710> index = MultiIndex([('z', 4.0, 'e'), ('m', 3.0, 'x'), (nan, 9.0, nan), ('m', 0.0, 'w'), ('w', nan, 'b'), ('t', 8.0, 'n'), ('s', 9.0, 'c'), (nan, 8.0, nan), (nan, 8.0, 's'), ('p', 8.0, 'q'), ('t', nan, 'l'), ('j', 2.0, 'k'), ('o', nan, nan), ('l', 2.0, nan), (nan, 6.0, nan), ('f', 1.0, nan), ('b', nan, 'v'), ('w', 1.0, 'u'), ('v', 8.0, 'g'), ('f', 6.0, 'm'), ('i', 4.0, 'p'), ('h', 8.0, 'o'), ('y', 8.0, 'k'), (nan, 3.0, 'p'), ('y', 5.0, 'z'), ('l', 5.0, 'm'), ('f', 0.0, nan), ('g', 9.0, 'c'), (nan, 1.0, 'r'), ('z', 7.0, 'i'), ('i', 3.0, 'i'), (nan, 4.0, 'y'), ('s', nan, 'x'), (nan, 3.0, 'b'), ('k', nan, 'v'), ('g', 7.0, 'd'), ('n', nan, 'r'), ('c', 6.0, 's'), ('b', nan, 'f'), (nan, nan, 'r'), ('b', 6.0, 'e'), (nan, nan, 'p'), (nan, 5.0, nan), (nan, 4.0, 'c'), ('l', 6.0, 'w'), ('y', 2.0, 'f'), ('l', 6.0, 'k'), ('p', 3.0, 'n'), ('o', 3.0, 'h'), (nan, 2.0, 'h')], names=['1st', '2nd', '3rd']) join_keys = [<ArrowStringArrayNumpySemantics> ['v', nan, 'k', 'l', 'i', nan, 'z', 'w', 'o', nan, 'h', 'g', 't', nan, 'y', 'f', 'y', nan, 'j', 'b', 'i', nan, 's', 'w', 'z', nan, 'f', 'o', 's', nan, 'y', 'l', 'n', nan, 'p', 'l', 'p', nan, 'm', 'f', 'm', nan, 'b', 'l', 'c', nan, 't', 'b', 'g', nan] Length: 50, dtype: string, array([ 8., 2., nan, 2., 4., 8., 4., nan, 3., 6., 8., 7., nan, 1., 8., 0., 5., nan, 2., 6., 3., 5., nan, 1., 7., 4., 6., nan, 9., 4., 2., 6., nan, 9., 8., 6., 3., nan, 0., 1., 3., 3., nan, 5., 6., 8., 8., nan, 9., 3.]), <ArrowStringArrayNumpySemantics> ['g', 'h', 'v', nan, 'p', 's', 'e', 'b', 'h', nan, 'o', 'd', 'l', 'r', 'k', nan, 'z', 'r', 'k', 'e', 'i', nan, 'x', 'u', 'i', 'y', 'm', nan, 'c', 'c', 'f', 'w', 'r', nan, 'q', 'k', 'n', 'p', 'w', nan, 'x', 'p', 'v', 'm', 's', nan, 'n', 'f', 'c', 'b'] Length: 50, dtype: string] n = 0 sort = False _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ lk = <pyarrow.lib.ChunkedArray object at 0xc983bb18> [ [ "b", "c", "f", "g", "h", ... "t", "v", "w", "y", "z" ] ] rk = <pyarrow.lib.ChunkedArray object at 0xc984c7f8> [ [ "v", null, "k", "l", "i", ... null, "t", "b", "g", null ] ] sort = False def _factorize_keys( lk: ArrayLike, rk: ArrayLike, sort: bool = True ) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp], int]: """ Encode left and right keys as enumerated types. This is used to get the join indexers to be used when merging DataFrames. Parameters ---------- lk : ndarray, ExtensionArray Left key. rk : ndarray, ExtensionArray Right key. sort : bool, defaults to True If True, the encoding is done such that the unique elements in the keys are sorted. Returns ------- np.ndarray[np.intp] Left (resp. right if called with `key='right'`) labels, as enumerated type. np.ndarray[np.intp] Right (resp. left if called with `key='right'`) labels, as enumerated type. int Number of unique elements in union of left and right labels. See Also -------- merge : Merge DataFrame or named Series objects with a database-style join. algorithms.factorize : Encode the object as an enumerated type or categorical variable. Examples -------- >>> lk = np.array(["a", "c", "b"]) >>> rk = np.array(["a", "c"]) Here, the unique values are `'a', 'b', 'c'`. With the default `sort=True`, the encoding will be `{0: 'a', 1: 'b', 2: 'c'}`: >>> pd.core.reshape.merge._factorize_keys(lk, rk) (array([0, 2, 1]), array([0, 2]), 3) With the `sort=False`, the encoding will correspond to the order in which the unique elements first appear: `{0: 'a', 1: 'c', 2: 'b'}`: >>> pd.core.reshape.merge._factorize_keys(lk, rk, sort=False) (array([0, 1, 2]), array([0, 1]), 3) """ # TODO: if either is a RangeIndex, we can likely factorize more efficiently? if ( isinstance(lk.dtype, DatetimeTZDtype) and isinstance(rk.dtype, DatetimeTZDtype) ) or (lib.is_np_dtype(lk.dtype, "M") and lib.is_np_dtype(rk.dtype, "M")): # Extract the ndarray (UTC-localized) values # Note: we dont need the dtypes to match, as these can still be compared lk, rk = cast("DatetimeArray", lk)._ensure_matching_resos(rk) lk = cast("DatetimeArray", lk)._ndarray rk = cast("DatetimeArray", rk)._ndarray elif ( isinstance(lk.dtype, CategoricalDtype) and isinstance(rk.dtype, CategoricalDtype) and lk.dtype == rk.dtype ): assert isinstance(lk, Categorical) assert isinstance(rk, Categorical) # Cast rk to encoding so we can compare codes with lk rk = lk._encode_with_my_categories(rk) lk = ensure_int64(lk.codes) rk = ensure_int64(rk.codes) elif isinstance(lk, ExtensionArray) and lk.dtype == rk.dtype: if (isinstance(lk.dtype, ArrowDtype) and is_string_dtype(lk.dtype)) or ( isinstance(lk.dtype, StringDtype) and lk.dtype.storage in ["pyarrow", "pyarrow_numpy"] ): import pyarrow as pa import pyarrow.compute as pc len_lk = len(lk) lk = lk._pa_array # type: ignore[attr-defined] rk = rk._pa_array # type: ignore[union-attr] dc = ( pa.chunked_array(lk.chunks + rk.chunks) # type: ignore[union-attr] .combine_chunks() .dictionary_encode() ) llab, rlab, count = ( pc.fill_null(dc.indices[slice(len_lk)], -1) .to_numpy() .astype(np.intp, copy=False), pc.fill_null(dc.indices[slice(len_lk, None)], -1) .to_numpy() .astype(np.intp, copy=False), len(dc.dictionary), ) if sort: uniques = dc.dictionary.to_numpy(zero_copy_only=False) llab, rlab = _sort_labels(uniques, llab, rlab) if dc.null_count > 0: lmask = llab == -1 lany = lmask.any() rmask = rlab == -1 rany = rmask.any() if lany: np.putmask(llab, lmask, count) if rany: > np.putmask(rlab, rmask, count) E ValueError: putmask: output array is read-only count = 19 dc = <pyarrow.lib.DictionaryArray object at 0xc9083ed0> -- dictionary: [ "b", "c", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "s", "t", "v", "w", "y", "z" ] -- indices: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ... 9, null, 0, 8, 1, null, 14, 0, 3, null ] lany = False len_lk = 19 lk = <pyarrow.lib.ChunkedArray object at 0xc983bb18> [ [ "b", "c", "f", "g", "h", ... "t", "v", "w", "y", "z" ] ] llab = array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]) lmask = array([False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False]) pa = <module 'pyarrow' from '/usr/lib/python3.11/site-packages/pyarrow/__init__.py'> pc = <module 'pyarrow.compute' from '/usr/lib/python3.11/site-packages/pyarrow/compute.py'> rany = True rk = <pyarrow.lib.ChunkedArray object at 0xc984c7f8> [ [ "v", null, "k", "l", "i", ... null, "t", "b", "g", null ] ] rlab = array([15, -1, 7, 8, 5, -1, 18, 16, 11, -1, 4, 3, 14, -1, 17, 2, 17, -1, 6, 0, 5, -1, 13, 16, 18, -1, 2, 11, 13, -1, 17, 8, 10, -1, 12, 8, 12, -1, 9, 2, 9, -1, 0, 8, 1, -1, 14, 0, 3, -1]) rmask = array([False, True, False, False, False, True, False, False, False, True, False, False, False, True, False, False, False, True, False, False, False, True, False, False, False, True, False, False, False, True, False, False, False, True, False, False, False, True, False, False, False, True, False, False, False, True, False, False, False, True]) sort = False pandas/core/reshape/merge.py:2514: ValueError ``` </details> Full build & test log (2.5M .gz, 52M uncompressed): [pandas.txt.gz](https://github.com/pandas-dev/pandas/files/14343832/pandas.txt.gz) This is on Gentoo/x86 systemd-nspawn container. I'm using `-O2 -march=pentium-m -mfpmath=sse -pipe` flags to rule out i387-specific precision issues. I've also filed https://github.com/apache/arrow/issues/40153 for test failures in pyarrow itself. Some of them could be possibly be bugs in pandas instead. ### Expected Behavior Tests passing ;-). ### Installed Versions <details> INSTALLED VERSIONS ------------------ commit : fd3f57170aa1af588ba877e8e28c158a20a4886d python : 3.11.7.final.0 python-bits : 32 OS : Linux OS-release : 6.7.5-gentoo-dist Version : #1 SMP PREEMPT_DYNAMIC Sat Feb 17 07:30:27 -00 2024 machine : x86_64 processor : AMD Ryzen 5 3600 6-Core Processor byteorder : little LC_ALL : None LANG : C.UTF8 LOCALE : en_US.UTF-8 pandas : 2.2.0 numpy : 1.26.4 pytz : 2024.1 dateutil : 2.8.2 setuptools : 69.0.3 pip : None Cython : 3.0.5 pytest : 7.4.4 hypothesis : 6.98.3 sphinx : None blosc : None feather : None xlsxwriter : 3.2.0 lxml.etree : 4.9.4 html5lib : 1.1 pymysql : 1.4.6 psycopg2 : None jinja2 : 3.1.3 IPython : None pandas_datareader : None adbc-driver-postgresql: None adbc-driver-sqlite : None bs4 : 4.12.3 bottleneck : 1.3.7 dataframe-api-compat : None fastparquet : None fsspec : None gcsfs : None matplotlib : 3.8.3 numba : None numexpr : 2.9.0 odfpy : None openpyxl : 3.1.2 pandas_gbq : None pyarrow : 15.0.0 pyreadstat : None python-calamine : None pyxlsb : None s3fs : None scipy : None sqlalchemy : 2.0.27 tables : 3.9.2 tabulate : 0.9.0 xarray : 2024.2.0 xlrd : 2.0.1 zstandard : None tzdata : None qtpy : None pyqt5 : None </details>
[ "Bug", "32bit", "Arrow" ]
0
0
0
0
0
0
0
0
[ "The first error looks like we need to use the platform specific int type instead of int64 (haven't looked too closely, though).\r\n\r\nThe rest seem like they could potentially be related to bugs in Arrow.", "I already have a fix for one bug in Arrow, so I'm going to retry with it applied, later today.", "Yeah, my patch fixed `pandas/tests/interchange/test_impl.py::test_large_string_pyarrow`. I'll check if I can figure out a fix for the other three when I find some time." ]
2,144,190,572
57,522
TYP: fix mypy failures on main in pandas/core/generic.py
closed
2024-02-20T11:45:33
2024-02-20T17:08:05
2024-02-20T17:07:46
https://github.com/pandas-dev/pandas/pull/57522
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57522
https://github.com/pandas-dev/pandas/pull/57522
natmokval
2
fixed `mypy` failure on main in `pandas/core/generic.py`: ``` pandas/core/generic.py:6463: error: Argument "deep" to "copy" of "BaseBlockManager" has incompatible type "bool | None"; expected "bool | Literal['all']" [arg-type] ```
[ "Typing" ]
0
0
0
0
0
0
0
0
[ "Thanks @natmokval ", "cc @phofl for the copy typing issue" ]
2,144,084,011
57,521
BUG: pandas >= 2.0 parses 'May' in ambiguous way.
closed
2024-02-20T10:46:57
2024-02-25T15:57:03
2024-02-25T15:57:03
https://github.com/pandas-dev/pandas/issues/57521
true
null
null
ffyring
8
### Pandas version checks - [X] I have checked that this issue has not already been reported. - [X] I have confirmed this bug exists on the [latest version](https://pandas.pydata.org/docs/whatsnew/index.html) of pandas. - [X] I have confirmed this bug exists on the [main branch](https://pandas.pydata.org/docs/dev/getting_started/install.html#installing-the-development-version-of-pandas) of pandas. ### Reproducible Example ```python import pandas as pd from io import StringIO csv_ok = """ REF_DATE, VAL 20-Apr-2024, 120 20-May-2024, 100 """ csv_error = """ REF_DATE, VAL 20-May-2024, 120 20-Apr-2024, 100 """ # This works fine df_ok = pd.read_csv(StringIO(csv_ok)) df_ok['REF_DATE'] = pd.to_datetime(df_ok['REF_DATE']) df_ok['NEXT_DATE'] = df_ok['REF_DATE'] + pd.Timedelta(days=1) # This gives an error df_error = pd.read_csv(StringIO(csv_error)) df_error['REF_DATE'] = pd.to_datetime(df_error['REF_DATE']) df_error['NEXT_DATE'] = df_error['REF_DATE'] + pd.Timedelta(days=1) ``` ### Issue Description Code above works with pandas<2.0 and fails with pandas>=2.0 Failure occurs because pandas >= 2.0 parses the date format in second example as "%d-%B-%Y" (long datename) instead if "%d-%b-%Y" (3-letter dastename) since "May" is both the full month name and three-letter-abbreviation of the 5th month of the year. The cause is the removal of the default argument ```infer_datetime_format=False``` in ```core.tools.datetimes._convert_listlike_datetimes``` Pandas>=2.0 then uses ``` def _guess_datetime_format_for_array(arr, dayfirst: bool | None = False) -> str | None: # Try to guess the format based on the first non-NaN element, return None if can't if (first_non_null := tslib.first_non_null(arr)) != -1: if type(first_non_nan_element := arr[first_non_null]) is str: # noqa: E721 # GH#32264 np.str_ object guessed_format = guess_datetime_format( first_non_nan_element, dayfirst=dayfirst ) if guessed_format is not None: return guessed_format # If there are multiple non-null elements, warn about # how parsing might not be consistent if tslib.first_non_null(arr[first_non_null + 1 :]) != -1: warnings.warn( "Could not infer format, so each element will be parsed " "individually, falling back to `dateutil`. To ensure parsing is " "consistent and as-expected, please specify a format.", UserWarning, stacklevel=find_stack_level(), ) return None ``` using the ambiguous first element. ### Expected Behavior pandas should infer the datetime format correctly, using several entries when the format is ambiguous. ### Installed Versions <details> INSTALLED VERSIONS ------------------ commit : f538741432edf55c6b9fb5d0d496d2dd1d7c2457 python : 3.11.7.final.0 python-bits : 64 OS : Windows OS-release : 10 Version : 10.0.19044 machine : AMD64 processor : Intel64 Family 6 Model 165 Stepping 5, GenuineIntel byteorder : little LC_ALL : None LANG : None LOCALE : Swedish_Sweden.1252 pandas : 2.2.0 numpy : 1.26.4 pytz : 2024.1 dateutil : 2.8.2 setuptools : 69.1.0 pip : 24.0 Cython : None pytest : 8.0.0 hypothesis : None sphinx : 7.2.6 blosc : None feather : None xlsxwriter : None lxml.etree : 5.1.0 html5lib : 1.1 pymysql : None psycopg2 : None jinja2 : 3.1.3 IPython : 8.21.0 pandas_datareader : None adbc-driver-postgresql: None adbc-driver-sqlite : None bs4 : 4.12.3 bottleneck : 1.3.7 dataframe-api-compat : None fastparquet : None fsspec : 2024.2.0 gcsfs : None matplotlib : 3.8.3 numba : 0.59.0 numexpr : None odfpy : None openpyxl : 3.1.2 pandas_gbq : None pyarrow : 11.0.0 pyreadstat : None python-calamine : None pyxlsb : None s3fs : None scipy : 1.12.0 sqlalchemy : 2.0.27 tables : None tabulate : 0.9.0 xarray : 2024.1.1 </details>
[ "Bug", "Needs Discussion", "datetime.date" ]
0
0
0
0
0
0
0
0
[ "<img width=\"950\" alt=\"Pandas_parse\" src=\"https://github.com/pandas-dev/pandas/assets/45058712/30eebec4-91dd-4f3f-8912-4abf5791c022\">\r\nIt is working fine for me. I am using the installed versions. ", "\n> It is working fine for me. I am using the installed versions. \n\nAnd the installed version is above 2.0?\n\n", "~~Yes~~\r\n\r\nMy bad. I can reproduce the error. I am using pandas 2.2.0 Now. ", "I did some debugging. The below format is also failing and working fine in pandas < 2.0 versions. \r\n\r\ncsv_error = \"\"\"\r\nREF_DATE, VAL\r\n20-05-2024, 120\r\n20-May-2024, 100\r\n\"\"\"\r\n\r\nWhen we pass `format='mixed'` it works as expected. I guess this would be the solution. \r\n\r\n`df_error = pd.read_csv(StringIO(csv_error))\r\ndf_error['REF_DATE'] = pd.to_datetime(df_error['REF_DATE'],format='mixed')\r\ndf_error['NEXT_DATE'] = df_error['REF_DATE'] + pd.Timedelta(days=1)`\r\n", "> I did some debugging. The below format is also failing and working fine in pandas < 2.0 versions.\r\n> \r\n> csv_error = \"\"\" REF_DATE, VAL 20-05-2024, 120 20-May-2024, 100 \"\"\"\r\n> \r\n> When we pass `format='mixed'` it works as expected. I guess this would be the solution.\r\n> \r\n> `df_error = pd.read_csv(StringIO(csv_error)) df_error['REF_DATE'] = pd.to_datetime(df_error['REF_DATE'],format='mixed') df_error['NEXT_DATE'] = df_error['REF_DATE'] + pd.Timedelta(days=1)`\r\n\r\nThanks, passing format='mixed' works fine.\r\n\r\nI still think it is a bug or a regression though, possibly breaking old code bases, since the format really isn't mixed in this case.", "Thanks for the report!\r\n\r\n> pandas should infer the datetime format correctly, using several entries when the format is ambiguous.\r\n\r\nHow many? And if they are all \"May\"?\r\n\r\n> I still think it is a bug or a regression though, possibly breaking old code bases, since the format really isn't mixed in this case.\r\n\r\nThe breaking change was announced here: https://pandas.pydata.org/docs/dev/whatsnew/v2.0.0.html#datetimes-are-now-parsed-with-a-consistent-format\r\n\r\n> Thanks, passing format='mixed' works fine.\r\n\r\nI'd recommend `format=\"%d-%b-%Y\"` instead, if the format is indeed not mixed.\r\n\r\nIt seems to me that inference is a guess, and sometimes guesses can be wrong. I'd recommend not relying on inference when possible.\r\n\r\ncc @MarcoGorelli ", "> Thanks for the report!\r\n> \r\n> > pandas should infer the datetime format correctly, using several entries when the format is ambiguous.\r\n> \r\n> How many? And if they are all \"May\"?\r\n> \r\n> > I still think it is a bug or a regression though, possibly breaking old code bases, since the format really isn't mixed in this case.\r\n> \r\n> The breaking change was announced here: \r\n> I'd recommend `format=\"%d-%b-%Y\"` instead, if the format is indeed not mixed.\r\n>\r\n> It seems to me that inference is a guess, and sometimes guesses can be wrong. I'd recommend not relying on inference when possible.\r\n> \r\n> cc @MarcoGorelli\r\n\r\nThanks, definitely not a bug then. I think your viewpoint as reasonable and this can be closed.\r\n", "Not a bug." ]
2,144,040,421
57,520
Potential performance regression by commit 1e9cccc: PERF Allow RangeIndex.take to return a RangeIndex when possible
closed
2024-02-20T10:24:25
2024-02-21T01:39:26
2024-02-21T01:39:26
https://github.com/pandas-dev/pandas/issues/57520
true
null
null
DeaMariaLeon
1
PR #57445 Benchmarks: - [ ] `groupby.GroupByMethods.time_dtype_as_field` (Python) with application='direct', dtype='uint', method='quantile', ncols=1, param5='cython' - [ ] `frame_methods.SortValues.time_frame_sort_values` (Python) with ascending=False - [ ] `frame_methods.SortValues.time_frame_sort_values` (Python) with ascending=True - [ ] `groupby.Groups.time_series_groups` (Python) with key='object_large' - [ ] `gil.ParallelGroups.time_get_groups` (Python) with threads=2 - [ ] `gil.ParallelGroups.time_get_groups` (Python) with threads=8 - [ ] `groupby.Groups.time_series_groups` (Python) with key='object_small' - [ ] `groupby.GroupByMethods.time_dtype_as_field` (Python) with application='direct', dtype='int16', method='quantile', ncols=1, param5='cython' - [ ] `join_merge.JoinIndex.time_left_outer_join_index` (Python) - [ ] `groupby.Apply.time_scalar_function_single_col` (Python) with factor=5 - [ ] `groupby.Groups.time_series_groups` (Python) with key='int64_small' - [ ] `groupby.GroupByMethods.time_dtype_as_group` (Python) with application='direct', dtype='uint', method='quantile', ncols=1, param5='cython' - [ ] `groupby.Groups.time_series_groups` (Python) with key='int64_large' - [ ] `gil.ParallelGroups.time_get_groups` (Python) with threads=4 ![image](https://github.com/pandas-dev/pandas/assets/11835246/2da40dd0-77f6-46db-ae6e-29cab19e6c92) ![image](https://github.com/pandas-dev/pandas/assets/11835246/dc734b08-87fb-4e50-b176-5e9bd251e420)
[]
0
0
0
0
0
0
0
0
[ "Addressed in https://github.com/pandas-dev/pandas/pull/57534" ]
2,144,037,974
57,519
TST: add a test for selecting columns in DataFrame with `big-endian` dtype
closed
2024-02-20T10:23:12
2024-02-20T17:11:09
2024-02-20T17:11:01
https://github.com/pandas-dev/pandas/pull/57519
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57519
https://github.com/pandas-dev/pandas/pull/57519
natmokval
1
- [x] closes #57457 added a test in to check that selecting columns in DataFrame with `big-endian` dtype is supported
[ "Testing" ]
0
0
0
0
0
0
0
0
[ "Thanks @natmokval " ]
2,143,649,322
57,518
Improving function definition
closed
2024-02-20T06:42:16
2024-02-20T21:39:56
2024-02-20T21:33:09
https://github.com/pandas-dev/pandas/pull/57518
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57518
https://github.com/pandas-dev/pandas/pull/57518
jmarintur
2
- [x] closes #57305 - [x] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit).
[ "Docs" ]
0
0
0
0
0
0
0
0
[ "Thanks @jmarintur ", "Glad to help @mroeschke. Thank you for your suggestions. " ]
2,143,376,452
57,517
BUG: MultiIndex.factorize fails if index is 0-length
open
2024-02-20T01:42:00
2025-08-17T02:22:38
null
https://github.com/pandas-dev/pandas/issues/57517
true
null
null
batterseapower
3
### Pandas version checks - [X] I have checked that this issue has not already been reported. - [X] I have confirmed this bug exists on the [latest version](https://pandas.pydata.org/docs/whatsnew/index.html) of pandas. - [ ] I have confirmed this bug exists on the [main branch](https://pandas.pydata.org/docs/dev/getting_started/install.html#installing-the-development-version-of-pandas) of pandas. ### Reproducible Example ```python empty_ix = pd.MultiIndex.from_product([ pd.Index([], name='a', dtype=object), pd.Index([], name='i', dtype='f4') ]) empty_ix.factorize() # Fails # Names are lost pd.MultiIndex.from_product([ pd.Index(['a', 'b'], name='a'), pd.Index([0, 1, 0], name='i', dtype='f4') ]).factorize()[1].names ``` ### Issue Description The first example should succeed, but actually it fails: ``` File ~/opt/conda/envs/mamba/envs/py3_2/lib/python3.11/site-packages/pandas/core/base.py:1203, in IndexOpsMixin.factorize(self, sort, use_na_sentinel) 1199 uniques = uniques.astype(np.float32) 1201 if isinstance(self, ABCIndex): 1202 # preserve e.g. MultiIndex -> 1203 uniques = self._constructor(uniques) 1204 else: 1205 from pandas import Index File ~/opt/conda/envs/mamba/envs/py3_2/lib/python3.11/site-packages/pandas/core/indexes/multi.py:222, in names_compat.<locals>.new_meth(self_or_cls, *args, **kwargs) 219 if "name" in kwargs: 220 kwargs["names"] = kwargs.pop("name") --> 222 return meth(self_or_cls, *args, **kwargs) File ~/opt/conda/envs/mamba/envs/py3_2/lib/python3.11/site-packages/pandas/core/indexes/multi.py:609, in MultiIndex.from_tuples(cls, tuples, sortorder, names) 607 if len(tuples) == 0: 608 if names is None: --> 609 raise TypeError("Cannot infer number of levels from empty list") 610 # error: Argument 1 to "len" has incompatible type "Hashable"; 611 # expected "Sized" 612 arrays = [[]] * len(names) # type: ignore[arg-type] TypeError: Cannot infer number of levels from empty list ``` Probably because of the same underlying issue, `MultiIndex.factorize` always loses the `names` of the original index. It should preserve the original names instead. ### Expected Behavior First `factorize()` should return `(np.array([], dtype=np.intp), empty_ix)` Second example should return `['a', 'i']` instead of `[None, None]` ### Installed Versions <details> INSTALLED VERSIONS ------------------ commit : fd3f57170aa1af588ba877e8e28c158a20a4886d python : 3.11.6.final.0 python-bits : 64 OS : Linux OS-release : 4.18.0-348.20.1.el8_5.x86_64 Version : #1 SMP Thu Mar 10 20:59:28 UTC 2022 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_GB.UTF-8 LOCALE : en_GB.UTF-8 pandas : 2.2.0 numpy : 1.26.3 pytz : 2023.3.post1 dateutil : 2.8.2 setuptools : 69.0.3 pip : 23.3.2 Cython : None pytest : 7.4.4 hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : 3.1.9 lxml.etree : 5.1.0 html5lib : 1.1 pymysql : None psycopg2 : None jinja2 : 3.1.3 IPython : 8.20.0 pandas_datareader : None adbc-driver-postgresql: None adbc-driver-sqlite : None bs4 : 4.12.3 bottleneck : 1.3.7 dataframe-api-compat : None fastparquet : None fsspec : 2023.12.2 gcsfs : None matplotlib : 3.8.2 numba : 0.58.1 numexpr : None odfpy : None openpyxl : 3.1.2 pandas_gbq : None pyarrow : 14.0.2 pyreadstat : None python-calamine : None pyxlsb : None s3fs : None scipy : 1.12.0 sqlalchemy : None tables : None tabulate : None xarray : 2024.1.0 xlrd : 2.0.1 zstandard : None tzdata : 2023.4 qtpy : 2.4.1 pyqt5 : None </details>
[ "Bug", "Algos", "MultiIndex", "Index" ]
0
0
0
0
0
0
0
0
[ "Thanks for the report. Agreed this shouldn't raise, but I'm not certain about preserving names. `pd.Index([2, 4, 3], name=\"a\").factorize()` also does not preserve the name, and doing so might have some wide ranging complications (haven't checked). Further investigations welcome - in particular, if we do preserve names, what is the impact on the test suite?", "I also think names should be preserved in the regular Index case. It does break backwards compatibility to do this because existing code may be relying on them not being preserved, but leaving this aside it does seem very clear to me that dropping the names is surprising behaviour.", "> but leaving this aside it does seem very clear to me that dropping the names is surprising behaviour.\r\n\r\nNo disagreement here offhand, but this could have wide ranging implications and the impact needs to be investigated. " ]
2,143,360,560
57,516
CI/TST: Use tmp_path for excel test
closed
2024-02-20T01:19:25
2024-02-20T23:32:53
2024-02-20T23:32:50
https://github.com/pandas-dev/pandas/pull/57516
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57516
https://github.com/pandas-dev/pandas/pull/57516
mroeschke
0
- [ ] closes #57511 (Replace xxxx with the GitHub issue number) `tm.ensure_clean` doesn't ensure files are unique if the same name is passed, but `tmp_path` ensures a test gets a unique temp path.
[ "CI", "IO Excel" ]
0
0
0
0
0
0
0
0
[]
2,143,288,302
57,515
Backport PR #57488 on branch 2.2.x (REGR: query raising for all NaT in object column)
closed
2024-02-19T23:36:40
2024-02-20T01:20:21
2024-02-20T01:20:20
https://github.com/pandas-dev/pandas/pull/57515
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57515
https://github.com/pandas-dev/pandas/pull/57515
meeseeksmachine
0
Backport PR #57488: REGR: query raising for all NaT in object column
[ "expressions" ]
0
0
0
0
0
0
0
0
[]
2,143,266,356
57,514
.
closed
2024-02-19T23:06:34
2024-12-20T02:16:43
2024-02-19T23:22:01
https://github.com/pandas-dev/pandas/pull/57514
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57514
https://github.com/pandas-dev/pandas/pull/57514
GrzegorzSzczepanek
0
null
[]
0
0
0
0
0
0
0
0
[]
2,143,264,016
57,513
CoW: Clean up some copy usage
closed
2024-02-19T23:03:27
2024-02-20T00:05:58
2024-02-19T23:56:31
https://github.com/pandas-dev/pandas/pull/57513
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57513
https://github.com/pandas-dev/pandas/pull/57513
phofl
1
- [ ] closes #xxxx (Replace xxxx with the GitHub issue number) - [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.
[ "Copy / view semantics" ]
0
0
0
0
0
0
0
0
[ "Thanks @phofl " ]
2,143,259,336
57,512
BUG: Unexpected read_csv parse_dates behavior
open
2024-02-19T22:57:34
2025-07-15T20:44:59
null
https://github.com/pandas-dev/pandas/issues/57512
true
null
null
kounoupis
6
### Pandas version checks - [X] I have checked that this issue has not already been reported. - [X] I have confirmed this bug exists on the [latest version](https://pandas.pydata.org/docs/whatsnew/index.html) of pandas. - [ ] I have confirmed this bug exists on the [main branch](https://pandas.pydata.org/docs/dev/getting_started/install.html#installing-the-development-version-of-pandas) of pandas. ### Reproducible Example ```python #!/opt/apps/anaconda3/bin/python import pandas from io import StringIO if __name__ == "__main__": csv = StringIO(''' Ticker,Last Update Timestamp AAA,01/29/2024 17:04:19 AAA,01/30/2024 04:19:57 ABEQ,02/08/2024 14:33:51 ABEQ,02/06/2024 15:04:57 ABEQ,02/13/2024 07:53:11 ''') columns={'Ticker': str, 'Last Update Timestamp': str} df = pandas.read_csv(csv, usecols=columns.keys(), dtype=columns, parse_dates=['Last Update Timestamp']) print(pandas.__version__) print(df) ``` ### Issue Description parse_dates in combination with dtype does not correctly identify date column as a DateTime object and, in addition, converts the column into int64 (that are not even valid epochs). This used to work correctly with pandas 1.4.0 The output of the above example is: ``` 2.2.0 Ticker Last Update Timestamp 0 AAA 1706547859000000000 1 AAA 1706588397000000000 2 ABEQ 1707402831000000000 3 ABEQ 1707231897000000000 4 ABEQ 1707810791000000000 ``` ### Expected Behavior ``` #!/opt/apps/anaconda3/bin/python import pandas from io import StringIO if __name__ == "__main__": csv = StringIO(''' Ticker,Last Update Timestamp AAA,01/29/2024 17:04:19 AAA,01/30/2024 04:19:57 ABEQ,02/08/2024 14:33:51 ABEQ,02/06/2024 15:04:57 ABEQ,02/13/2024 07:53:11 ''') columns={'Ticker': str, 'Last Update Timestamp': str} df = pandas.read_csv(csv, parse_dates=['Last Update Timestamp']) print(pandas.__version__) print(df) ``` Output: ``` > ./date.py 2.2.0 Ticker Last Update Timestamp 0 AAA 2024-01-29 17:04:19 1 AAA 2024-01-30 04:19:57 2 ABEQ 2024-02-08 14:33:51 3 ABEQ 2024-02-06 15:04:57 4 ABEQ 2024-02-13 07:53:11 ``` ### Installed Versions <details> /opt/apps/anaconda3/lib/python3.11/site-packages/_distutils_hack/__init__.py:33: UserWarning: Setuptools is replacing distutils. warnings.warn("Setuptools is replacing distutils.") INSTALLED VERSIONS ------------------ commit : f538741432edf55c6b9fb5d0d496d2dd1d7c2457 python : 3.11.6.final.0 python-bits : 64 OS : Linux OS-release : 5.10.0-9-amd64 Version : #1 SMP Debian 5.10.70-1 (2021-09-30) machine : x86_64 processor : byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8 pandas : 2.2.0 numpy : 1.26.4 pytz : 2024.1 dateutil : 2.8.2 setuptools : 69.0.3 pip : 24.0 Cython : None pytest : 8.0.0 hypothesis : None sphinx : 7.2.6 blosc : None feather : None xlsxwriter : 3.1.9 lxml.etree : 4.9.3 html5lib : None pymysql : None psycopg2 : None jinja2 : 3.1.3 IPython : 8.21.0 pandas_datareader : None adbc-driver-postgresql: None adbc-driver-sqlite : None bs4 : 4.12.3 bottleneck : None dataframe-api-compat : None fastparquet : None fsspec : 2023.10.0 gcsfs : None matplotlib : 3.8.0 numba : 0.59.0 numexpr : 2.9.0 odfpy : None openpyxl : 3.1.2 pandas_gbq : None pyarrow : 12.0.1 pyreadstat : None python-calamine : None pyxlsb : None s3fs : None scipy : 1.12.0 sqlalchemy : 2.0.24 tables : 3.9.2 tabulate : 0.9.0 xarray : 2024.1.1 xlrd : None zstandard : 0.22.0 tzdata : 2023.4 qtpy : 2.4.1 pyqt5 : None None </details>
[ "Bug", "Datetime", "Dtype Conversions", "IO CSV" ]
2
0
0
0
0
0
0
0
[ "Same problem here. Though I don't think manual using of `dtype` and `parse_dates` together can be considered as something that has \"expected behaviour\".\r\n\r\nBtw, if you use \r\n```python\r\ncolumns = {\"Ticker\": str, \"Last Update Timestamp\": pandas.StringDtype()}\r\n```\r\n\r\nThere is no problem at all.\r\n\r\nAnd one more thing: try to specify incorrect date_format like that:\r\n```python\r\ndf = pandas.read_csv(\r\n csv,\r\n usecols=list(columns.keys()),\r\n dtype=columns,\r\n parse_dates=[\"Last Update Timestamp\"],\r\n date_format=\"%Y/%m/%d %H:%M:%S\",\r\n )\r\n```\r\nKind of magic xD. Definitely a bug. Seems like date format inferring or something like that... because if you set\r\n```python\r\ndf = pandas.read_csv(\r\n csv,\r\n usecols=list(columns.keys()),\r\n dtype=columns,\r\n parse_dates=[\"Last Update Timestamp\"],\r\n #date_format=\"%Y/%m/%d %H:%M:%S\",\r\n infer_datetime_format=True,\r\n )\r\n```\r\nStill has a bug.\r\n\r\n<details>\r\n<summary>INSTALLED VERSIONS</summary>\r\nINSTALLED VERSIONS\r\n------------------\r\ncommit : f538741432edf55c6b9fb5d0d496d2dd1d7c2457\r\npython : 3.11.4.final.0\r\npython-bits : 64\r\nOS : Windows\r\nOS-release : 10\r\nVersion : 10.0.19045\r\nmachine : AMD64\r\nprocessor : AMD64 Family 23 Model 113 Stepping 0, AuthenticAMD\r\nbyteorder : little\r\nLC_ALL : None\r\nLANG : en_US.UTF-8\r\nLOCALE : Russian_Ukraine.1251\r\n\r\npandas : 2.2.0\r\nnumpy : 1.26.4\r\npytz : 2024.1\r\ndateutil : 2.8.2\r\nsetuptools : 65.5.0\r\npip : 24.0\r\nCython : None\r\npytest : 8.0.1\r\nhypothesis : None\r\nsphinx : None\r\nblosc : None\r\nfeather : None\r\nxlsxwriter : None\r\nlxml.etree : None\r\nhtml5lib : None\r\npymysql : None\r\npsycopg2 : None\r\njinja2 : None\r\nIPython : None\r\npandas_datareader : None\r\nadbc-driver-postgresql: None\r\nadbc-driver-sqlite : None\r\nbs4 : None\r\nbottleneck : None\r\ndataframe-api-compat : None\r\nfastparquet : None\r\nfsspec : None\r\ngcsfs : None\r\nmatplotlib : 3.8.3\r\nnumba : None\r\nnumexpr : None\r\nodfpy : None\r\nopenpyxl : None\r\npandas_gbq : None\r\npyarrow : 15.0.0\r\npyreadstat : None\r\npython-calamine : None\r\npyxlsb : None\r\ns3fs : None\r\nscipy : None\r\nsqlalchemy : None\r\ntables : None\r\ntabulate : None\r\nxarray : None\r\nxlrd : None\r\nzstandard : None\r\ntzdata : 2024.1\r\nqtpy : None\r\npyqt5 : None\r\n</details>", "Thanks for the report and investigation, confirmed on main. Further investigations and PRs to fix are welcome!\r\n\r\nAlso, while they appear as integers, I'm seeing that the output in the OP are in fact strings.", "take", "Is anyone working on this issue? I would like to help with it.", "> Is anyone working on this issue? I would like to help with it.\r\n\r\nI'm working on it. Should have a PR ready very soon. Apologies for the delay.", "Okay. No problem.Thank you for the update." ]
2,143,220,186
57,511
CI: excel tests started failing on windows
closed
2024-02-19T22:13:26
2024-02-20T23:32:51
2024-02-20T23:32:51
https://github.com/pandas-dev/pandas/issues/57511
true
null
null
phofl
0
some issues with concurrent access to the same file not possible on windows PR that circumvented this is here: https://github.com/pandas-dev/pandas/pull/57486
[ "CI" ]
0
0
0
0
0
0
0
0
[]
2,143,218,042
57,510
DOC: Fix xarray example
closed
2024-02-19T22:11:36
2024-02-20T20:48:10
2024-02-20T18:51:06
https://github.com/pandas-dev/pandas/pull/57510
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57510
https://github.com/pandas-dev/pandas/pull/57510
phofl
2
- [ ] closes #xxxx (Replace xxxx with the GitHub issue number) - [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.
[ "Docs" ]
0
0
0
0
0
0
0
0
[ "Thanks @phofl ", "Owee, I'm MrMeeseeks, Look at me.\n\nThere seem to be a conflict, please backport manually. Here are approximate instructions:\n\n1. Checkout backport branch and update it.\n\n```\ngit checkout 2.2.x\ngit pull\n```\n\n2. Cherry pick the first parent branch of the this PR on top of the older branch:\n```\ngit cherry-pick -x -m1 33a1cd7163ce712e5a38fdb5d2e04de203b3ddf9\n```\n\n3. You will likely have some merge/cherry-pick conflict here, fix them and commit:\n\n```\ngit commit -am 'Backport PR #57510: DOC: Fix xarray example'\n```\n\n4. Push to a named branch:\n\n```\ngit push YOURFORK 2.2.x:auto-backport-of-pr-57510-on-2.2.x\n```\n\n5. Create a PR against branch 2.2.x, I would have named this PR:\n\n> \"Backport PR #57510 on branch 2.2.x (DOC: Fix xarray example)\"\n\nAnd apply the correct labels and milestones.\n\nCongratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!\n\nRemember to remove the `Still Needs Manual Backport` label once the PR gets merged.\n\nIf these instructions are inaccurate, feel free to [suggest an improvement](https://github.com/MeeseeksBox/MeeseeksDev).\n " ]
2,143,084,184
57,509
Backport PR #57490 on branch 2.2.x (DOC: Add a few deprecation notes)
closed
2024-02-19T20:15:32
2024-02-19T22:12:25
2024-02-19T22:12:25
https://github.com/pandas-dev/pandas/pull/57509
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57509
https://github.com/pandas-dev/pandas/pull/57509
meeseeksmachine
0
Backport PR #57490: DOC: Add a few deprecation notes
[ "Docs" ]
0
0
0
0
0
0
0
0
[]
2,142,894,312
57,508
BUG: Tick division is incorrect
closed
2024-02-19T17:49:37
2024-04-23T18:54:50
2024-04-23T18:54:50
https://github.com/pandas-dev/pandas/pull/57508
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57508
https://github.com/pandas-dev/pandas/pull/57508
lithomas1
3
- [ ] closes #57264 (Replace xxxx with the GitHub issue number) - [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.
[ "Frequency", "Stale" ]
0
0
0
0
0
0
0
0
[ "did you look at Tick._next_higher_resolution? it is what we use in `Tick.__mul__` when multiplying by a float, and i suspect that logic can be adapted pretty cleanly", "This pull request is stale because it has been open for thirty days with no activity. Please [update](https://pandas.pydata.org/pandas-docs/stable/development/contributing.html#updating-your-pull-request) and respond to this comment if you're still interested in working on this.", "Looks like this PR has gone stale and needs a rebase. Closing to clear the queue but feel free to reopen when you have time to circle back" ]
2,142,871,822
57,507
Backport PR #57486 on branch 2.2.x (CI: Run excel tests on single cpu for windows)
closed
2024-02-19T17:34:17
2024-02-19T20:15:56
2024-02-19T20:15:56
https://github.com/pandas-dev/pandas/pull/57507
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57507
https://github.com/pandas-dev/pandas/pull/57507
meeseeksmachine
0
Backport PR #57486: CI: Run excel tests on single cpu for windows
[ "CI" ]
0
0
0
0
0
0
0
0
[]
2,142,850,552
57,506
Pyarrow will become a required dependency of pandas in the next major release of pandas (pandas 3.0), (to allow more performant data types, such as the Arrow string type, and better interoperability with other libraries) but was not found to be installed on your system. If this would cause problems for you,BUILD:
closed
2024-02-19T17:20:35
2024-02-19T18:49:30
2024-02-19T18:49:29
https://github.com/pandas-dev/pandas/issues/57506
true
null
null
Athiyasyed
2
### Installation check - [X] I have read the [installation guide](https://pandas.pydata.org/pandas-docs/stable/getting_started/install.html#installing-pandas). ### Platform Pyarrow will become a required dependency of pandas in the next major release of pandas (pandas 3.0), (to allow more performant data types, such as the Arrow string type, and better interoperability with other libraries) but was not found to be installed on your system. If this would cause problems for you, ### Installation Method pip install ### pandas Version 2.2.0 ### Python Version 3.12.2 ### Installation Logs <details> Replace this line with the installation logs. </details> !pip install pandas
[ "Build", "Needs Triage" ]
0
0
0
0
0
0
0
0
[ "The warning is purely informational and tells you all you need to know: ignore or install pyarrow.\r\nIf your issue goes beyond just wanting the warning to disappear; see https://github.com/pandas-dev/pandas/issues/54466 \r\n\r\nAlso technically duplicate? #57501", "Please review https://github.com/pandas-dev/pandas/issues/54466" ]
2,142,533,685
57,505
BUG: `std` using `numpy.float32` dtype gives incorrect result on contant array.
closed
2024-02-19T14:44:41
2024-02-25T14:29:28
2024-02-25T14:27:58
https://github.com/pandas-dev/pandas/issues/57505
true
null
null
jamespreed
16
### Pandas version checks - [X] I have checked that this issue has not already been reported. - [X] I have confirmed this bug exists on the [latest version](https://pandas.pydata.org/docs/whatsnew/index.html) of pandas. - [X] I have confirmed this bug exists on the [main branch](https://pandas.pydata.org/docs/dev/getting_started/install.html#installing-the-development-version-of-pandas) of pandas. ### Reproducible Example ```python import pandas as pd import numpy as np # this should be 0 or very close to 0 print(pd.Series([271.46] * 150000, dtype='float32').std()) # returns: 0.229433074593544 # same result using numpy dtype directly (as you would expect) print(pd.Series([271.46] * 150000, dtype=np.float32).std()) # returns: 0.229433074593544 # the pandas float32 dtype does not have this issue. print(pd.Series([271.46] * 150000, dtype=pd.Float32Dtype()).std()) # returns: 0.0 # neither does using the numpy standard deviation function on the numpy values print(np.std(pd.Series([271.46] * 150000, dtype=np.float32).values)) # returns: 0.0 ``` ### Issue Description When using the numpy float32 dtype by passing either the string `'float32'` or the numpy dtype `np.float32`, the value of the standard deviation is incorrect for a constant array (array of identical values). It should return zero, but instead returns a value. Switching to using the Pandas float32 dtype alleviates the error, as does using `np.std` on the numpy values of the series. ### Expected Behavior The expected behavior is the following evaluating to `True` ```python pd.Series([271.46] * 150000, dtype='float32').std() == 0.0 ``` ### Installed Versions <details> ``` INSTALLED VERSIONS ------------------ commit : f538741432edf55c6b9fb5d0d496d2dd1d7c2457 python : 3.11.7.final.0 python-bits : 64 OS : Windows OS-release : 10 Version : 10.0.22621 machine : AMD64 processor : Intel64 Family 6 Model 151 Stepping 5, GenuineIntel byteorder : little LC_ALL : None LANG : None LOCALE : English_United States.1252 pandas : 2.2.0 numpy : 1.26.3 pytz : 2023.3.post1 dateutil : 2.8.2 setuptools : 68.2.2 pip : 23.3.1 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : 4.9.3 html5lib : None pymysql : None psycopg2 : None jinja2 : None IPython : 8.15.0 pandas_datareader : None adbc-driver-postgresql: None adbc-driver-sqlite : None bs4 : None bottleneck : 1.3.7 dataframe-api-compat : None fastparquet : None fsspec : None gcsfs : None matplotlib : 3.8.0 numba : None numexpr : 2.8.7 odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pyreadstat : None python-calamine : None pyxlsb : None s3fs : None scipy : 1.11.4 sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None zstandard : None tzdata : 2023.3 qtpy : None pyqt5 : None ``` </details>
[ "Bug", "Reduction Operations", "Upstream issue" ]
0
0
0
0
0
0
0
0
[ "Have no problems:\r\n![image](https://github.com/pandas-dev/pandas/assets/72792408/897c86d2-a0ef-4933-9ef6-a4dfa777db0c)\r\n\r\n\r\nOS: Windows 10\r\nPython: 3.11.4\r\nWorking in venv with such dependencies:\r\n```\r\ncontourpy==1.2.0\r\ncycler==0.12.1\r\nfonttools==4.49.0\r\nkiwisolver==1.4.5\r\nmatplotlib==3.8.3\r\nnumpy==1.26.4\r\npackaging==23.2\r\npandas==2.2.0\r\npillow==10.2.0\r\npyarrow==15.0.0\r\npyparsing==3.1.1\r\npython-dateutil==2.8.2\r\npytz==2024.1\r\nseaborn==0.13.2\r\nsix==1.16.0\r\ntzdata==2024.1\r\n```\r\n\r\nSorry, don't know how to make such \"Installed Versions\".\r\n\r\nTried the same code with 1.26.3 numpy version, still no problems.", "![image](https://github.com/pandas-dev/pandas/assets/7841701/4d8c9783-c961-42fb-b89c-cd8e840c9123)\r\n\r\nUpdated numpy to 1.26.4 with the same result. Is this a \"just on my machine\" bug?", "> Sorry, don't know how to make such \"Installed Versions\".\r\n\r\nYou can use:\r\n```python\r\npd.show_versions()\r\n```", "@jamespreed Thank you very much! Here is my installed versions:\r\n```\r\nINSTALLED VERSIONS\r\n------------------\r\ncommit : f538741432edf55c6b9fb5d0d496d2dd1d7c2457\r\npython : 3.11.4.final.0\r\npython-bits : 64\r\nOS : Windows\r\nOS-release : 10\r\nVersion : 10.0.19045\r\nmachine : AMD64\r\nprocessor : AMD64 Family 23 Model 113 Stepping 0, AuthenticAMD\r\nbyteorder : little\r\nLC_ALL : None\r\nLANG : en_US.UTF-8\r\nLOCALE : Russian_Ukraine.1251\r\n\r\npandas : 2.2.0\r\nnumpy : 1.26.4\r\npytz : 2024.1\r\ndateutil : 2.8.2\r\nsetuptools : 65.5.0\r\npip : 24.0\r\nCython : None\r\npytest : 8.0.1\r\nhypothesis : None\r\nsphinx : None\r\nblosc : None\r\nfeather : None\r\nxlsxwriter : None\r\nlxml.etree : None\r\nhtml5lib : None\r\npymysql : None\r\npsycopg2 : None\r\njinja2 : None\r\nIPython : None\r\npandas_datareader : None\r\nadbc-driver-postgresql: None\r\nadbc-driver-sqlite : None\r\nbs4 : None\r\nbottleneck : None\r\ndataframe-api-compat : None\r\nfastparquet : None\r\nfsspec : None\r\ngcsfs : None\r\nmatplotlib : 3.8.3\r\nnumba : None\r\nnumexpr : None\r\nodfpy : None\r\nopenpyxl : None\r\npandas_gbq : None\r\npyarrow : 15.0.0\r\npyreadstat : None\r\npython-calamine : None\r\npyxlsb : None\r\ns3fs : None\r\nscipy : None\r\nsqlalchemy : None\r\ntables : None\r\ntabulate : None\r\nxarray : None\r\nxlrd : None\r\nzstandard : None\r\ntzdata : 2024.1\r\nqtpy : None\r\npyqt5 : None\r\n```", "@jamespreed Just out of curious, can you try to create venv and reproduce this bug?\r\nMake sure you are using same python version as described in bug report.\r\n```\r\npython -m venv PROJECT_FOLDER & cd PROJECT_FOLDER & .\\Scripts\\activate & pip install numpy pandas\r\n```\r\nCreate your file and try again.", "Ok, that is interesting. The `pip` installed version gives the same outputs that as you are seeing:\r\n\r\n![image](https://github.com/pandas-dev/pandas/assets/7841701/b2c9e600-7bb5-4426-bb52-948271e70510)\r\n\r\nThe outputs I am originally seeing are from the `conda` version of the packages. ", "Ye, really interesting: package manager affects math results ʘ‿ʘ At least you know how to use `std` with reliable results... ", "Are you able to isolate whether it's the pandas or NumPy package that causes this?", "> The outputs I am originally seeing are from the `conda` version of the packages.\r\n\r\nCan you provide your conda env export file? (or steps to create the env using conda)", "I am extremely confused now. The issue does NOT appear when clean installing via the following methods:\r\n\r\n## venv\r\n```\r\nmkdir test\r\npython -m venv test\r\ncd test\r\n./Scripts/activate\r\npip install pandas\r\n```\r\n\r\n## conda env with numpy, pip install pandas\r\n```\r\nconda create -n test2 python=3.11 numpy\r\nconda activate test2\r\npip install conda-forge::pandas==2.2.0 -y\r\n```\r\n\r\n## clean conda env\r\n```\r\nconda create -n test3 python=3.11 conda-forge::pandas==2.2.0 -y\r\n```", "The issue is `bottleneck`. Whenever I install it into an environment, the `float32` issue appears.\r\n\r\nIn all of the above cases, installing `bottleneck` using either pip or conda exhibits the problem.\r\n\r\n```\r\nconda activate test2\r\npip install bottleneck\r\n# issue appears again.\r\n```\r\n\r\n", "is this only on the new pandas version or does this also happen if you use an older version of pandas?", "It happens on Pandas 1.4.4, 1.5.3, 2.0.0, 2.1.0, 2.1.4, and 2.2.0", "that means that it is most likely a bottleneck issue, could you report there?", "Looking at the linked issue, it appears very likely this is a bottleneck issue. Closing for now.", "Also, note you can disable the use of bottleneck with\r\n\r\n pd.set_option(\"compute.use_bottleneck\", False)\r\n\r\nYou can also temporarily disable it for certain lines:\r\n\r\n```\r\nwith pd.option_context(\"compute.use_bottleneck\", False):\r\n print(pd.Series([271.46] * 150000, dtype='float32').std())\r\n```" ]
2,142,090,284
57,504
DOC: Fix PR01 errors in multiple files (#57438)
closed
2024-02-19T10:55:45
2024-08-31T08:37:19
2024-02-21T01:37:56
https://github.com/pandas-dev/pandas/pull/57504
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57504
https://github.com/pandas-dev/pandas/pull/57504
Deen-dot
1
Fixed PR01 errors (#57438) and added parameter descriptions for: - `pandas.Grouper` - `pandas.core.groupby.DataFrameGroupBy.cummax` - `pandas.core.groupby.DataFrameGroupBy.cummin` - `pandas.core.groupby.DataFrameGroupBy.cumprod` - `pandas.core.groupby.DataFrameGroupBy.cumsum` - `pandas.core.groupby.DataFrameGroupBy.filter` - `pandas.core.groupby.DataFrameGroupBy.pct_change` - `pandas.core.groupby.DataFrameGroupBy.rolling` - `pandas.core.groupby.SeriesGroupBy.nunique` - `pandas.core.groupby.SeriesGroupBy.cummax` - `pandas.core.groupby.SeriesGroupBy.cummin` - `pandas.core.groupby.SeriesGroupBy.cumprod` - `pandas.core.groupby.SeriesGroupBy.cumsum` - `pandas.core.groupby.SeriesGroupBy.cumprod` Fixed functions also removed from code_checks.sh
[ "Docs" ]
0
0
0
1
0
1
0
0
[ "Thanks @Deen-dot " ]
2,141,756,541
57,503
Bump pandas-dev/github-doc-previewer from 0.3.1 to 0.3.2
closed
2024-02-19T08:04:45
2024-02-19T23:41:26
2024-02-19T23:41:24
https://github.com/pandas-dev/pandas/pull/57503
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57503
https://github.com/pandas-dev/pandas/pull/57503
dependabot[bot]
0
Bumps [pandas-dev/github-doc-previewer](https://github.com/pandas-dev/github-doc-previewer) from 0.3.1 to 0.3.2. <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/pandas-dev/github-doc-previewer/releases">pandas-dev/github-doc-previewer's releases</a>.</em></p> <blockquote> <h2>v0.3.2</h2> <p>github-docs-previewer 0.3.2</p> </blockquote> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/pandas-dev/github-doc-previewer/commit/7a1ea7e96d1a24578ec35eedd4256a7d80c3fef8"><code>7a1ea7e</code></a> Increasing the number of CI jobs that are fetched from github (from 30 to 100)</li> <li><a href="https://github.com/pandas-dev/github-doc-previewer/commit/890a0d2e14a3cbeebbfccc3afed35e03bf2a4481"><code>890a0d2</code></a> Fix typo in installation url, and update version for next release</li> <li>See full diff in <a href="https://github.com/pandas-dev/github-doc-previewer/compare/v0.3.1...v0.3.2">compare view</a></li> </ul> </details> <br /> [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=pandas-dev/github-doc-previewer&package-manager=github_actions&previous-version=0.3.1&new-version=0.3.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details>
[ "CI", "Dependencies" ]
0
0
0
0
0
0
0
0
[]
2,141,673,663
57,502
Fix for small typo
closed
2024-02-19T07:13:05
2024-02-19T08:16:16
2024-02-19T07:34:52
https://github.com/pandas-dev/pandas/pull/57502
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57502
https://github.com/pandas-dev/pandas/pull/57502
em1208
0
Just a very small fix for a typo I noticed.
[ "Docs" ]
0
0
0
0
0
0
0
0
[]
2,141,667,255
57,501
Pyarrow will become a required dependency of pandas in the next major release of pandas
closed
2024-02-19T07:08:44
2024-02-19T16:28:39
2024-02-19T16:28:20
https://github.com/pandas-dev/pandas/issues/57501
true
null
null
gbfsdelhi
2
### Pandas version checks - [X] I have checked that this issue has not already been reported. - [X] I have confirmed this issue exists on the [latest version](https://pandas.pydata.org/docs/whatsnew/index.html) of pandas. - [X] I have confirmed this issue exists on the main branch of pandas. ### Reproducible Example I am trying to [index my Website URL](https://www.growbusinessforsure.com/) on Google through Python but getting this warning… Please tell me how I can fix it. ![Capture](https://github.com/pandas-dev/pandas/assets/140062552/bbca08b2-1e26-425c-b81d-8e144360dec9) ### Installed Versions <details> Replace this line with the output of pd.show_versions() </details> ### Prior Performance _No response_
[ "Usage Question" ]
0
0
0
0
0
0
0
0
[ "It's a warning, so there's nothing to \"fix\" really.\r\nBut if you plan on updating to pandas 3.0 you'll need pyarrow", "The warning message also points to https://github.com/pandas-dev/pandas/issues/54466 as a feedback issue. But as @bileamScheuvens mentioned, you can install pyarrow and you won't see the warning message anymore." ]
2,141,564,011
57,500
BUG: Columns resulting from joining multiIndex dataFrame are incorrect in python 3.12.1
closed
2024-02-19T05:52:29
2024-10-04T02:30:33
2024-04-16T17:16:03
https://github.com/pandas-dev/pandas/issues/57500
true
null
null
yuji38kwmt
11
### Pandas version checks - [X] I have checked that this issue has not already been reported. - [X] I have confirmed this bug exists on the [latest version](https://pandas.pydata.org/docs/whatsnew/index.html) of pandas. - [ ] I have confirmed this bug exists on the [main branch](https://pandas.pydata.org/docs/dev/getting_started/install.html#installing-the-development-version-of-pandas) of pandas. ### Reproducible Example ```python import pandas df1=pandas.DataFrame({("A",""):[1,2,3]},index=["x","y","z"]) df2=pandas.DataFrame({("B",""):[11,12,13]},index=["x","y","z"]) df3 = df1.join(df2) print(f"{df3.columns=}") ``` ### Issue Description In Python 3.12.1, the `print(f"{df3=}")` statement output the following string. ``` df3.columns=Index([slice(None, None, None), slice(None, None, None)], dtype='object') ``` And `df3[("A","")]` occurs `KeyError`. But in python 3.11.7, `df3[("A","")]` does not occur `KeyError`. ### Expected Behavior The `print(f"{df3=}")` statement output the following string. ``` df3.columns=MultiIndex([('A', ''),('B', '')]) ``` ### Installed Versions <details> pd.show_versions() INSTALLED VERSIONS ------------------ commit : a671b5a8bf5dd13fb19f0e88edc679bc9e15c673 python : 3.12.1.final.0 python-bits : 64 OS : Linux OS-release : 5.15.133.1-microsoft-standard-WSL2 Version : #1 SMP Thu Oct 5 21:02:42 UTC 2023 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : C.UTF-8 LOCALE : C.UTF-8 pandas : 2.1.4 numpy : 1.26.4 pytz : 2024.1 dateutil : 2.8.2 setuptools : None pip : 24.0 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : 5.1.0 html5lib : None pymysql : None psycopg2 : None jinja2 : 3.1.3 IPython : 8.21.0 pandas_datareader : None bs4 : None bottleneck : None dataframe-api-compat: None fastparquet : None fsspec : None gcsfs : None matplotlib : 3.8.2 numba : None numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pyreadstat : None pyxlsb : None s3fs : None scipy : None sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None zstandard : None tzdata : 2023.4 qtpy : None pyqt5 : None </details>
[ "Bug", "Reshaping" ]
1
0
0
0
0
0
0
0
[ "@yuji38kwmt - can you pls provide folder path for this issue.", "@rajnee28 \r\n\r\n>can you pls provide folder path for this issue.\r\n\r\nThe bug does not depend on folder path.\r\n\r\nFor example, you can reproduce the bug in IPython.\r\n\r\n```\r\nIn [59]: import pandas\r\n ...:\r\n ...: df1=pandas.DataFrame({(\"A\",\"\"):[1,2,3]},index=[\"x\",\"y\",\"z\"])\r\n ...: df2=pandas.DataFrame({(\"B\",\"\"):[11,12,13]},index=[\"x\",\"y\",\"z\"])\r\n ...:\r\n ...: df3 = df1.join(df2)\r\n ...:\r\n ...: print(f\"{df3.columns=}\")\r\ndf3.columns=Index([slice(None, None, None), slice(None, None, None)], dtype='object')\r\n```", "I don't know what causes the problem, but concat is a little workaround:\r\n```python\r\ndf3 = pd.concat([df1, df2], axis=1) #there is join options too\r\n```", "The following code behaved expectedly.\r\n\r\n```\r\nIn [89]: import pandas\r\n ...:\r\n ...: df1=pandas.DataFrame({(\"A\",\"X\"):[1,2,3]},index=[\"x\",\"y\",\"z\"])\r\n ...: df2=pandas.DataFrame({(\"B\",\"Y\"):[11,12,13]},index=[\"x\",\"y\",\"z\"])\r\n ...:\r\n ...: df3 = df1.join(df2)\r\n\r\nIn [90]: print(f\"{df3.columns=}\")\r\ndf3.columns=MultiIndex([('A', 'X'),\r\n ('B', 'Y')],\r\n )\r\n\r\n```\r\n\r\n\r\nApparently the problem occurs when the key with label 1 is an empty string.", "Confirmed that this still exists on 2.2.1, but not yet on main. Further investigations and PRs to fix are welcome!", "I did a litter investigated the bug.\r\n\r\nThe following code creates a `pd.Series` containing index which of name is `slice(None, None, None)`.\r\nhttps://github.com/pandas-dev/pandas/blob/v2.2.1/pandas/core/reshape/merge.py#L837-L838\r\n\r\n# Trial1\r\n\r\n* Python 3.12.1\r\n* pandas 2.2.1\r\n\r\n```\r\nIn [21]: df=pandas.DataFrame({\"A\":[1,2,3]},index=[\"x\",\"y\",\"z\"])\r\n\r\nIn [22]: df[:]\r\nOut[22]:\r\n A\r\nx 1\r\ny 2\r\nz 3\r\n\r\nIn [24]: df[:].columns\r\nOut[24]: Index(['A'], dtype='object')\r\n\r\n\r\n\r\nIn [25]: df11=pandas.DataFrame({(\"A\",\"x\"):[1,2,3]},index=[\"x\",\"y\",\"z\"])\r\n\r\nIn [26]: df11[:]\r\nOut[26]:\r\n x\r\nx 1\r\ny 2\r\nz 3\r\n\r\nIn [27]: df11[:].columns\r\nOut[27]: Index(['x'], dtype='object')\r\n\r\nIn [28]: df12=pandas.DataFrame({(\"A\",\"\"):[1,2,3]},index=[\"x\",\"y\",\"z\"])\r\n\r\n# Look at the code !\r\nIn [29]: df12[:]\r\nOut[29]:\r\nx 1\r\ny 2\r\nz 3\r\nName: slice(None, None, None), dtype: int64\r\n\r\nIn [30]: type(df12[:])\r\nOut[30]: pandas.core.series.Series\r\n```\r\n\r\n\r\n# Trial2\r\n* Python 3.11.7\r\n* pandas 2.2.1\r\n\r\n\r\n```\r\nIn [3]: df11=pandas.DataFrame({(\"A\",\"x\"):[1,2,3]},index=[\"x\",\"y\",\"z\"])\r\n\r\nIn [4]: df11[:]\r\nOut[4]:\r\n A\r\n x\r\nx 1\r\ny 2\r\nz 3\r\n\r\nIn [5]: df11[:].columns\r\nOut[5]:\r\nMultiIndex([('A', 'x')],\r\n )\r\n\r\nIn [6]: df12=pandas.DataFrame({(\"A\",\"\"):[1,2,3]},index=[\"x\",\"y\",\"z\"])\r\n\r\nIn [7]: df12[:]\r\nOut[7]:\r\n A\r\n\r\nx 1\r\ny 2\r\nz 3\r\n\r\nIn [8]: df12[:].columns\r\nOut[8]:\r\nMultiIndex([('A', '')],\r\n )\r\n```\r\n", "Also encountering this issue. I'll see if I can come up with a bug fix.\r\n\r\nIt seems related to Python 3.12 changes, not Pandas changes. I'm failing all of my tests for py3.12 against Pandas 1.5, 2.0, 2.1, and 2.2.", "As @yuji38kwmt noted, the error is due to the way in which Pandas handles the `[:]` indexer in Python 3.12. This comes from a [change](https://github.com/python/cpython/pull/101264) in Python 3.12 which makes slice objects hashable. This is leading to a different control flow in the [`DataFrame.__getitem__()`](https://github.com/pandas-dev/pandas/blob/bdc79c146c2e32f2cab629be240f01658cfb6cc2/pandas/core/frame.py#L4050-L4073).\r\n\r\nAlso note that `slice(None) in df.columns` returns True.\r\n\r\nI'll be submitting a PR. I think it should be as easy as switching the position of the conditions in `__getitem__`, since `slice` and `is_hashable` were mutually exclusive pre-3.12.", "@tehunter \r\nI ran it in the following environment, but the result was the same.\r\nWhat has changed with #58043 ?\r\n\r\n* Python 3.12.4\r\n* pandas 2.2.3\r\n", "> @tehunter \n> I ran it in the following environment, but the result was the same.\n> What has changed with #58043 ?\n> \n> * Python 3.12.4\n> * pandas 2.2.3\n> \n\nIt appears the fix was placed in the planned changes for the pandas 3.0 release. I'm not on the dev team so I don't know when that will be released.", "Thank you! Got it." ]
2,141,462,904
57,499
Just for testing
closed
2024-02-19T04:14:05
2024-02-19T04:18:29
2024-02-19T04:18:29
https://github.com/pandas-dev/pandas/pull/57499
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57499
https://github.com/pandas-dev/pandas/pull/57499
mainak290803
0
Just for testing please consider it!
[]
0
0
0
0
0
0
0
0
[]
2,141,424,912
57,498
QST: How to encrypt pandas.DataFrame data with AES algorithm?
closed
2024-02-19T03:30:59
2024-02-19T18:51:33
2024-02-19T18:51:33
https://github.com/pandas-dev/pandas/issues/57498
true
null
null
snowuyl
2
### Research - [X] I have searched the [[pandas] tag](https://stackoverflow.com/questions/tagged/pandas) on StackOverflow for similar questions. - [X] I have asked my usage related question on [StackOverflow](https://stackoverflow.com). ### Link to question on StackOverflow https://stackoverflow.com/questions/78018229/how-to-encrypt-pandas-dataframe-data-with-aes-algorithm ### Question about pandas I would like to encrypt pandas.DataFrame data with Advanced Encryption Standard (AES). Does Pandas team provide sample code?
[ "Usage Question", "Needs Triage" ]
0
0
0
0
0
0
0
0
[ "This isn't very focused question. What is the purpose of doing such a task?\r\n\r\nA Pandas DataFrame is a Python Object. Is your intent to apply an algorithm to encode every element within the DataFrame and return a DataFrame of encoded elements, which can be decoded at a later stage?\r\n\r\nOr is your intent to compress the DataFrame and its contents to a string, then encode the string which is essentially encoding the entire DataFrame, and then decode and reconstitute the DataFrame later?\r\n\r\nFor what is its worth I have used option 2 previously to save a DataFrame in a database encrypted. You can convert a DataFrame (with custom Type formatters if necessary) to a JSON string. Then encode the JSON string and store. Then retrieve and decode the JSON string and reconstitute the DataFrame in memory.\r\n\r\nLike this:\r\n\r\n```python\r\nimport pandas as pd\r\n\r\ndef encrypt(s): # your own AES encryption on a string\r\n return s[::-1]\r\n\r\ndef decrypt(s):\r\n return s[::-1]\r\n\r\ndf = pd.DataFrame([[1,\"a\",4.0],[2,\"b\",3.0]])\r\ns = df.to_json() # '{\"0\":{\"0\":1,\"1\":2},\"1\":{\"0\":\"a\",\"1\":\"b\"},\"2\":{\"0\":4.0,\"1\":3.0}}'\r\ne = encrypt(s) # '}}0.3:\"1\",0.4:\"0\"{:\"2\",}\"b\":\"1\",\"a\":\"0\"{:\"1\",}2:\"1\",1:\"0\"{:\"0\"{'\r\n# Store e in Database\r\nd = decrypt(e)\r\ndf = pd.read_json(d)\r\n```\r\n", "As already mentioned, this is out of scope for pandas. The best way to probably approach this is write the DataFrame to a file format and encrypt that so closing" ]
2,141,408,555
57,497
DOC: Add whatsnew line for #57485
closed
2024-02-19T03:16:28
2024-02-19T22:18:28
2024-02-19T09:50:19
https://github.com/pandas-dev/pandas/pull/57497
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57497
https://github.com/pandas-dev/pandas/pull/57497
rhshadrach
1
- [ ] closes #xxxx (Replace xxxx with the GitHub issue number) - [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature. Ref: https://github.com/pandas-dev/pandas/pull/57485#issuecomment-1951354802 cc @phofl
[ "Docs" ]
0
0
0
0
0
0
0
0
[ "thx @rhshadrach \r\n\r\nno need to back port in case anyone else reads this, the actual pr was merged directly to 2.2.x" ]
2,141,401,863
57,496
Backport PR #57474 on branch 2.2.x (REGR: DataFrame.transpose resulting in not contiguous data on nullable EAs)
closed
2024-02-19T03:09:19
2024-02-19T22:25:29
2024-02-19T09:51:13
https://github.com/pandas-dev/pandas/pull/57496
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57496
https://github.com/pandas-dev/pandas/pull/57496
rhshadrach
2
…uous data on nullable EAs - [ ] closes #xxxx (Replace xxxx with the GitHub issue number) - [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.
[ "Bug", "Reshaping", "Regression" ]
0
0
0
0
0
0
0
0
[ "resolve conflicts ", "thx @rhshadrach " ]
2,141,284,519
57,495
Deployment pipeline are failing due to permission issue
closed
2024-02-19T00:54:58
2024-02-19T20:49:17
2024-02-19T18:52:32
https://github.com/pandas-dev/pandas/issues/57495
true
null
null
santhoshbethi
2
I am working on https://github.com/pandas-dev/pandas/issues/57419 After adding the example and committing the changes, https://github.com/pandas-dev/pandas/pull/57442 pipeline is failing multiple times at the "Unit Tests / windows-latest actions-312.yaml (pull_request)" . is it related to the changes that I made or a different reason?
[]
0
0
0
0
0
0
0
0
[ "The issue is affecting all PRs currently and not due to your PR specifically it looks like so closing", "Thank you for getting back to me. Can we merge the https://github.com/pandas-dev/pandas/issues/57419 and close it?" ]
2,141,248,587
57,494
BUG: DateTimeIndex.is_year_start unexpected behavior when constructed with freq 'MS' date_range (#57377)
closed
2024-02-19T00:01:38
2024-06-08T14:33:55
2024-06-08T14:33:54
https://github.com/pandas-dev/pandas/pull/57494
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57494
https://github.com/pandas-dev/pandas/pull/57494
mattheeter
7
- [x] closes #49606 - [x] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [x] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [x] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature. - A DateTimeIndex created via date_range with the freq parameter as 'MS' would yield a wrong is_year_start (and later it was discovered is_quarter_start) accessor. In `pandas/_libs/tslibs/fields.pyx`, the way in which the start and end months were set was one way for freq 'MS', 'QS', and 'YS' and another way for other offsets. However, only the latter two had the necessary properties to set start and end this way. As such, removing 'MS' from the list fixed the issue.
[ "Frequency" ]
0
0
0
0
0
0
0
0
[ "This pull request is stale because it has been open for thirty days with no activity. Please [update](https://pandas.pydata.org/pandas-docs/stable/development/contributing.html#updating-your-pull-request) and respond to this comment if you're still interested in working on this.", "Thanks for the pull request, but it appears to have gone stale. If interested in continuing, please merge in the main branch, address any review comments and/or failing tests, and we can reopen.", "wait sorry, I think this is my fault for not having got round to reviewing it\r\n\r\nreopening for now, hoping to get to it at some point before 3.0\r\n\r\n@natmokval fancy taking a look too?", "Thank you for working on this @mattheeter.\r\n\r\nIt looks good to me. I think the suggested changes will fix the bug in `is_year_start` for `MonthBegin`. We will get the correct result for `freq=\"MS\"`:\r\n```\r\ndr = pd.date_range(\"2017-12-01\", periods=2, freq=\"MS\")\r\nprint(dr) # DatetimeIndex(['2017-12-01', '2018-01-01'], dtype='datetime64[ns]', freq='MS')\r\ndr_attr = dr.is_year_start\r\nprint(dr_attr) # [False True]\r\n```\r\n\r\nThese changes won't fix a problem with some other frequencies such as: `freq=\"QS-NOV\"`:\r\n```\r\ndr = pd.date_range(\"2017-07-01\", periods=2, freq=\"QS-NOV\")\r\nprint(dr) # DatetimeIndex(['2017-08-01', '2017-11-01'], dtype='datetime64[ns]', freq='QS-NOV')\r\ndr_comp = [dt.is_year_start for dt in dr]\r\ndr_attr = dr.is_year_start\r\nprint(dr_attr) # [False True]\r\nprint(dr_comp) # [False, False]\r\n```\r\nIt may not be necessary to correct this in the current pull request.", "Of course! @natmokval \r\n\r\nYes, the original issue did not have the QS freq mentioned. I did point it out on the issue, and went ahead with what I thought would fix it there. I think that when I tested with other types of QS (e.g. November) I assumed that these should set the year start attribute to that of the quarter start, making me miss the fact that it was incorrect.\r\n\r\nShould I continue to work on the QS bug, or just remove any changes that attempted to fix that one since the issue didn't reference it? ", "I think it's okay to leave the fix for `\"MS\"` in this PR and open a new PR to work on the problem for frequencies such as `\"QS-NOV\"`.\r\n\r\nThis PR is still `Stale`. It can take a couple of days to change its status to active.\r\n", "Hi @natmokval, I was wondering if you knew anything about the Numpy Dev tests that are failing? I know when I submitted this PR a while ago there were no issues with unit tests, but I just got some time to continue working on this but haven't made any code changes since." ]
2,141,238,126
57,493
BUG: Inconsistent behaviour when checking if scalar for `pd.NA`: `np.isscalar(pd.NA) is False` while `np.isscalar(np.nan) is True`
closed
2024-02-18T23:31:22
2024-02-19T03:47:04
2024-02-19T03:46:48
https://github.com/pandas-dev/pandas/issues/57493
true
null
null
ssche
3
### Pandas version checks - [X] I have checked that this issue has not already been reported. - [X] I have confirmed this bug exists on the [latest version](https://pandas.pydata.org/docs/whatsnew/index.html) of pandas. - [ ] I have confirmed this bug exists on the [main branch](https://pandas.pydata.org/docs/dev/getting_started/install.html#installing-the-development-version-of-pandas) of pandas. ### Reproducible Example ```python >>> np.isscalar(pd.NA) False >>> np.isscalar(np.nan) True ``` ### Issue Description I think `np.isscalar(pd.NA)` should return True, just like `np.isscalar(np.nan)` does. ### Expected Behavior `np.isscalar(pd.NA)` should return True ### Installed Versions <details> ``` INSTALLED VERSIONS ------------------ commit : fd3f57170aa1af588ba877e8e28c158a20a4886d python : 3.11.7.final.0 python-bits : 64 OS : Linux OS-release : 6.7.4-200.fc39.x86_64 Version : #1 SMP PREEMPT_DYNAMIC Mon Feb 5 22:21:14 UTC 2024 machine : x86_64 processor : byteorder : little LC_ALL : None LANG : en_AU.UTF-8 LOCALE : en_AU.UTF-8 pandas : 2.2.0 numpy : 1.26.4 pytz : 2024.1 dateutil : 2.8.2 setuptools : 67.7.2 pip : 23.2.1 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : None IPython : None pandas_datareader : None adbc-driver-postgresql: None adbc-driver-sqlite : None bs4 : None bottleneck : None dataframe-api-compat : None fastparquet : None fsspec : None gcsfs : None matplotlib : None numba : None numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pyreadstat : None python-calamine : None pyxlsb : None s3fs : None scipy : None sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None zstandard : None tzdata : 2024.1 qtpy : None pyqt5 : None ``` </details>
[ "Missing-data", "Usage Question" ]
0
0
0
0
0
0
0
0
[ "Someone correct me if I'm wrong but no where do I know that `pd.NA` is a numpy scalar. \r\n\r\nIn fact I believe `pd.NA` was made specifically for nullable extension arrays, which is actually backed by 2 arrays (one of them being a mask to represent what's missing). `pd.NA` was made to act as a sentinel for missing data, saving `np.nan` to serve NaN's true purpose in ieee754 spec, a failed computation.", "`pd.NA` is a pandas object, not NumPy, I don't think you should expect NumPy functions to properly report it as a scalar. If you'd like to reliably detect both `pd.NA` and `np.nan`, you can use `pandsa.api.types.is_scalar`.", "Fair enough. I guess many things work when using numpy functions on pandas data which made me believe this should also work. I see your point though @rhshadrach. Thanks for pointing me to `pandas.api.types.is_scalar`, I'll use that instead." ]
2,141,207,431
57,492
Remove dtype inference on object dtype indexes for bool
closed
2024-02-18T22:07:49
2025-04-15T16:26:59
2025-04-15T16:26:58
https://github.com/pandas-dev/pandas/pull/57492
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57492
https://github.com/pandas-dev/pandas/pull/57492
phofl
3
- [ ] closes #xxxx (Replace xxxx with the GitHub issue number) - [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature. lets see which tests break, the subset I am normally running is green...
[ "Stale" ]
0
0
0
0
0
0
0
0
[ "Some windows tests", "This pull request is stale because it has been open for thirty days with no activity. Please [update](https://pandas.pydata.org/pandas-docs/stable/development/contributing.html#updating-your-pull-request) and respond to this comment if you're still interested in working on this.", "Looks like the CI isn't running on this PR. I think we would need a new PR here so closing this one" ]
2,141,204,830
57,491
CLN: Remove is_foo_dtype checks
closed
2024-02-18T22:01:11
2024-04-23T18:51:48
2024-04-23T18:51:48
https://github.com/pandas-dev/pandas/pull/57491
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57491
https://github.com/pandas-dev/pandas/pull/57491
phofl
3
- [ ] closes #xxxx (Replace xxxx with the GitHub issue number) - [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.
[ "Clean", "Stale" ]
0
0
0
0
0
0
0
0
[ "This looks like a very nice clean up. I'm missing context, but seems it's just missing fixing the conflict and updating or removing the test were those are still tested, right? Happy to see this finished and merged if that's the case.", "This pull request is stale because it has been open for thirty days with no activity. Please [update](https://pandas.pydata.org/pandas-docs/stable/development/contributing.html#updating-your-pull-request) and respond to this comment if you're still interested in working on this.", "Looks like this PR has gone stale and some tests are still failing here. Closing to clear the queue but feel free to reopen if you have time to circle back" ]
2,141,197,782
57,490
DOC: Add a few deprecation notes
closed
2024-02-18T21:40:39
2024-02-19T20:31:06
2024-02-19T20:15:24
https://github.com/pandas-dev/pandas/pull/57490
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57490
https://github.com/pandas-dev/pandas/pull/57490
phofl
2
- [ ] closes #57382 (Replace xxxx with the GitHub issue number) - [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.
[ "Docs" ]
0
0
0
0
0
0
0
0
[ "pre-commit.ci autofix", "thanks @phofl" ]
2,141,183,560
57,489
REGR: astype introducing decimals when casting from int with na to string
closed
2024-02-18T21:05:47
2024-02-20T17:27:00
2024-02-20T17:26:52
https://github.com/pandas-dev/pandas/pull/57489
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57489
https://github.com/pandas-dev/pandas/pull/57489
phofl
1
… - [ ] closes #57418 (Replace xxxx with the GitHub issue number) - [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.
[ "Dtype Conversions" ]
0
0
0
0
0
0
0
0
[ "Thanks @phofl " ]
2,141,167,659
57,488
REGR: query raising for all NaT in object column
closed
2024-02-18T20:19:14
2024-02-19T23:36:44
2024-02-19T23:36:11
https://github.com/pandas-dev/pandas/pull/57488
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57488
https://github.com/pandas-dev/pandas/pull/57488
phofl
1
- [ ] closes #57068 (Replace xxxx with the GitHub issue number) - [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.
[ "expressions" ]
0
0
0
0
0
0
0
0
[ "Thanks @phofl " ]
2,141,087,697
57,487
CoW: Track references in unstack if there is no copy
closed
2024-02-18T16:59:29
2024-04-02T16:18:07
2024-04-01T18:36:06
https://github.com/pandas-dev/pandas/pull/57487
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57487
https://github.com/pandas-dev/pandas/pull/57487
phofl
3
- [ ] xref #56633 - [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature. cc @jorisvandenbossche @rhshadrach @rhshadrach was correct, we can get there without making a copy. it's a special case, but nevertheless
[ "Reshaping", "Copy / view semantics" ]
0
0
0
0
0
0
0
0
[ "might be worth back porting, but not necessary", "this one should be good to merge", "Thanks @phofl " ]
2,141,037,947
57,486
CI: Run excel tests on single cpu for windows
closed
2024-02-18T15:18:33
2024-02-19T22:13:47
2024-02-19T17:33:47
https://github.com/pandas-dev/pandas/pull/57486
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57486
https://github.com/pandas-dev/pandas/pull/57486
phofl
2
I don't want to debug windows builds but we should get ci green again
[ "CI" ]
0
0
0
0
0
0
0
0
[ "thanks @phofl.\r\n\r\nCan you open up an issue as a followup?", "done, #57511" ]
2,140,983,599
57,485
REGR: DataFrame.update emits spurious warning about downcasting
closed
2024-02-18T13:10:51
2024-02-19T03:16:52
2024-02-18T15:13:56
https://github.com/pandas-dev/pandas/pull/57485
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57485
https://github.com/pandas-dev/pandas/pull/57485
rhshadrach
1
- [x] closes #57124 (Replace xxxx with the GitHub issue number) - [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature. This is meant as a stopgap - I plan to finish up #55634 for 3.0 which will avoid any upcasting/downcasting altogether. However I do no like the idea of that PR being put in a patch version since it is an entirely new approach to `DataFrame.update`. I think this can't go in main because the warning and downcasting behavior has already been removed there.
[ "Bug", "Dtype Conversions", "Regression", "DataFrame", "Warnings", "Conditionals" ]
0
0
0
0
0
0
0
0
[ "thx @rhshadrach \r\n\r\nCan you put up a pr with a whatsnew that adds this to main? Only the whatsnew change" ]
2,140,949,440
57,484
Backport PR #57454 on branch 2.2.x (Release the gil in take for axis=1)
closed
2024-02-18T11:43:48
2024-02-18T12:35:55
2024-02-18T12:35:55
https://github.com/pandas-dev/pandas/pull/57484
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57484
https://github.com/pandas-dev/pandas/pull/57484
meeseeksmachine
0
Backport PR #57454: Release the gil in take for axis=1
[]
0
0
0
0
0
0
0
0
[]
2,140,928,083
57,483
BUG: incompatible dtype when creating new columns with loc
closed
2024-02-18T11:08:11
2024-08-31T10:51:32
2024-02-18T11:54:09
https://github.com/pandas-dev/pandas/issues/57483
true
null
null
zbaibg
7
### Pandas version checks - [X] I have checked that this issue has not already been reported. - [X] I have confirmed this bug exists on the [latest version](https://pandas.pydata.org/docs/whatsnew/index.html) of pandas. - [X] I have confirmed this bug exists on the [main branch](https://pandas.pydata.org/docs/dev/getting_started/install.html#installing-the-development-version-of-pandas) of pandas. ### Reproducible Example ```python Example1: import pandas as pd df = pd.DataFrame({"x": [1]}) df.loc[df["x"] == 1, ["y"]] = "1" Output: <stdin>:1: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value '1' has dtype incompatible with float64, please explicitly cast to a compatible dtype first. Example2 import pandas as pd df = pd.DataFrame() df.loc[0,['x','y']]=[1,'1'] Output: <stdin>:1: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value '1' has dtype incompatible with float64, please explicitly cast to a compatible dtype first. ``` ### Issue Description The example 1 is very similar to the issue at #55025 . I only add a square bracket for the column name "y" in df.loc[] and it gives warning. Example 2 is similar, but deal with multiple columns at once. This is what I need in my code. ### Expected Behavior Run the following codes and it gives no warning: import pandas as pd df = pd.DataFrame() df.loc[0,['x','y']]=[1,'1'] ### Installed Versions <details> /home/bg/soft/miniconda3/lib/python3.11/site-packages/_distutils_hack/__init__.py:33: UserWarning: Setuptools is replacing distutils. warnings.warn("Setuptools is replacing distutils.") INSTALLED VERSIONS ------------------ commit : fd3f57170aa1af588ba877e8e28c158a20a4886d python : 3.11.5.final.0 python-bits : 64 OS : Linux OS-release : 5.15.133.1-microsoft-standard-WSL2 Version : #1 SMP Thu Oct 5 21:02:42 UTC 2023 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : C.UTF-8 LOCALE : en_US.UTF-8 pandas : 2.2.0 numpy : 1.26.4 pytz : 2024.1 dateutil : 2.8.2 setuptools : 68.2.2 pip : 23.3.1 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : None IPython : None pandas_datareader : None adbc-driver-postgresql: None adbc-driver-sqlite : None bs4 : None bottleneck : None dataframe-api-compat : None fastparquet : None fsspec : None gcsfs : None matplotlib : 3.8.2 numba : None numexpr : None odfpy : None openpyxl : 3.1.2 pandas_gbq : None pyarrow : None pyreadstat : None python-calamine : None pyxlsb : None s3fs : None scipy : 1.12.0 sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None zstandard : 0.19.0 tzdata : 2023.4 qtpy : None pyqt5 : None </details>
[ "Bug", "Needs Triage", "PDEP6-related" ]
0
0
0
0
0
0
0
0
[ "cc @MarcoGorelli ", "thanks @zbaibg for the report and @phofl for the ping\r\n\r\nneither of these raise any warning on `main`, so they've been addressed\r\n\r\nclosing then", "Hi, \r\n\r\nI am writing to hear opinions on the best pratice regarding the recent change in silent dtype casting. \r\nMainly, the recommended approach with dtypes when using them for basic numerical operations/transformation (inside pipeline).\r\n\r\nBelow, I've outlined three examples to illustrate the issue:\r\n\r\n(1) OLD CODE (behavior) will cause WARNING\r\n```\r\nD = pd.DataFrame({'C0':['A','B'], 'C1':[10,20]})\r\nD.loc[:,'C1'] = D.loc[:,'C1']/100\r\n```\r\n\r\nFutureWarning: Setting an item of incompatible dtype is deprecated and will raise in a future error of pandas. Value '[0.1 0.2]' has dtype incompatible with int64, please explicitly cast to a compatible dtype first.\r\n\r\n(2) SOLUTION A\r\n```\r\nD = pd.DataFrame({'C0':['A','B'],'C1':[10,20]})\r\nD['C1'] = D['C1']/100\r\n```\r\n\r\n(3) SOLUTION B\r\n```\r\nD = pd.DataFrame({'C0':['A','B'], 'C1':[10,20]})\r\nD = D.astype({'C1':float})\r\nD.loc[:,'C1'] = D.loc[:,'C1']/100\r\n```\r\n\r\nFrom the proper pandas perspective, I believe Solution B (3) is the recommended approach after pandas>=v2.1. \r\n\r\nHowever, when comparing code (1) to Solution (2), where code (1) warns and Solution (2) doesn't, I wonder if Solution (2) is optimal, especially when dealing with hundreds of columns. \r\n\r\nI believe the issue (1) vs. (2) is that pandas has Performance Warning issue as D['C1'] treats transformation of the column C1 in the DataFrame differently (creates a new block at the dataframe backend structure) than D.loc[:,'C1'] (which changes the current block without creating one at the dataframe backend structure).\r\n\r\nObviously, the less extra lines of code, the better - thus I tend to choose (2) instead of (3). Historically (1) is in the code design as it is explicit way to communicate that we intentially transforming the whole column ( D.loc[:,...] ) and want to stay optimal to not create a new structure block at the dataframe backend (i.e. if we used D[...].)\r\n\r\nIs my understanding of the best new pratice correct?", "Hi @MichalRIcar , I’ve also encountered this warning. It seems that this issue: https://github.com/pandas-dev/pandas/issues/57229#issue-2116685958 discussed the same topic. And in this issue, it is recommended to use `df.isetitem` to replace the full column, which is \r\n> In cases where frame.columns is unique, this is equivalent to frame[frame.columns[i]] = value.\r\naccording to https://pandas.pydata.org/pandas-docs/version/2.1/reference/api/pandas.DataFrame.isetitem.html. \r\n\r\nSo maybe your solution A is recommended, ~~even though it's not quite 'pandas-style' to me.~~", "Hello @leakyH, thank you very much for providing the context, that makes life easier! I actually converged to it too as haven't seen any issues with it, happy to hear that there are two of us now.. :-)", "Hi all. Just to chime in because I\"ve run into the same issue (with pandas 2.2.1). The weird thing is that it happens apparently when the data frame has only one value. \r\n```\r\n err_df.loc[:,'ERR_VALUE'] = err_df.loc[:,col]\r\n```\r\n\r\nI was running the code on test data in small chunks and it would randomly appear, so i tried to check the composition of `err_df` and the warning would only appear in such case. If i run the same data in larger test chunks the warning does not appear instead. \r\n\r\n```\r\npython3 ~/Dropbox/Projects/kanta_lab_preprocessing/finngen_qc/main.py --raw-data /mnt/disks/data/kanta/test/tmp.txt --out /mnt/disks/data/kanta/test/ --chunk-size 200\r\n\r\nPercent: [------------------->] 100%\r\n\r\nDone.\r\n\r\n```\r\n\r\nvs\r\n\r\n```\r\npython3 ~/Dropbox/Projects/kanta_lab_preprocessing/finngen_qc/main.py --raw-data /mnt/disks/data/kanta/test/tmp.txt --out /mnt/disks/data/kanta/test/ --chunk-size 100\r\n\r\nPercent: [---------> ] 50%/home/pete/Dropbox/Projects/kanta_lab_preprocessing/finngen_qc/filters/filter_minimal.py:63: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise in a future error of pandas. Value '['K']' has dtype incompatible with string, please explicitly cast to a compatible dtype first.\r\n\r\n err_df.loc[:,'ERR_VALUE'] = err_df.loc[:,col]\r\n\r\nPercent: [------------------->] 100%\r\n\r\nDone.\r\n\r\n```\r\n\r\nAnd this is confirmed because if i add an exception:\r\n```\r\nif len(err_df)>1:\r\n err_df.loc[:,'ERR_VALUE'] = err_df.loc[:,col]\r\n```\r\n\r\nThe same code runs without warning\r\n\r\n", "My panda is v2.2.2 and still the warning comes up. So how to fix it?" ]
2,140,852,860
57,482
CLN remove dataframe api consortium entrypoint
closed
2024-02-18T09:01:11
2024-05-29T13:02:15
2024-02-19T18:27:57
https://github.com/pandas-dev/pandas/pull/57482
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57482
https://github.com/pandas-dev/pandas/pull/57482
MarcoGorelli
3
Discussed privately In short: - I'm no longer involved in the project - nobody in pandas has much interest in leading the effort - pandas devs are already carrying out enough (mostly unpaid) maintenance, let's not add to it The Consortium is more than welcome to work on this, but outside of pandas
[ "Clean" ]
0
0
0
0
0
0
0
0
[ "Just curious why you didn't update the `What's New` section to match the way it was done when adding the entrypoint: https://github.com/pandas-dev/pandas/commit/809f3710807efedc684c8f0ed4adef8d01af3171#diff-cc8593fd6d3036f46dbd73bcd245aef9a5e737cd22ca67e9567e686872bf093e. It took me a while to figure out where it was deleted.\r\n\r\n@rgommers are you aware of this change?", "Hey Anatoly,\r\n\r\nI can't remember exactly, I probably just forgot", "> @rgommers are you aware of this change?\r\n\r\nI don't think I was, thanks for pointing it out. \r\n\r\nThis change was breaking it looks like (or you wouldn't have noticed in Modin I think), and the maintenance burden was minimal (xref gh-54383 comments), so I wouldn't have done it this way. But ultimately decisions like this are up to the maintainers alone, so it is what it is." ]
2,140,717,530
57,481
CI: update pyright
closed
2024-02-18T03:29:59
2024-04-07T10:59:15
2024-02-19T23:31:32
https://github.com/pandas-dev/pandas/pull/57481
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57481
https://github.com/pandas-dev/pandas/pull/57481
twoertwein
1
Pyright 1.1.348 split `reportGeneralTypeIssues` into multiple sub-rules up. Hopefully, this might make it easier to enable some of them more gradually.
[ "Typing" ]
0
0
0
0
0
0
0
0
[ "Thanks @twoertwein " ]
2,140,688,996
57,480
DEPR: read_csv keywords: keep_date_col, delim_whitespace
closed
2024-02-18T01:34:19
2024-02-18T22:16:10
2024-02-18T22:15:49
https://github.com/pandas-dev/pandas/pull/57480
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57480
https://github.com/pandas-dev/pandas/pull/57480
rmhowe425
1
- [X] closes #55569 - [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [X] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.
[]
0
0
0
0
0
0
0
0
[ "@rhshadrach @lithomas1 I was wondering if you would be willing to take a look at the PR and let me know if I'm on the right track?" ]
2,140,668,961
57,479
PERF: Improve performance for fillna with datetime
closed
2024-02-18T00:21:26
2024-02-25T18:15:18
2024-02-20T17:25:20
https://github.com/pandas-dev/pandas/pull/57479
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57479
https://github.com/pandas-dev/pandas/pull/57479
phofl
1
- [ ] closes #xxxx (Replace xxxx with the GitHub issue number) - [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.
[ "Datetime", "Performance" ]
0
0
0
0
0
0
0
0
[ "Thanks @phofl " ]
2,140,653,286
57,478
PERF: Improve performance for astype is view
closed
2024-02-17T23:16:27
2024-03-18T20:56:52
2024-03-18T16:47:46
https://github.com/pandas-dev/pandas/pull/57478
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57478
https://github.com/pandas-dev/pandas/pull/57478
phofl
2
- [ ] closes #xxxx (Replace xxxx with the GitHub issue number) - [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature. This came up in asvs, it wasn't much but we can do better
[ "Performance", "Copy / view semantics" ]
0
0
0
0
0
0
0
0
[ "(there is a mypy error ...)", "Thanks @phofl " ]
2,140,648,682
57,477
CoW: Remove remaining cow occurrences from tests
closed
2024-02-17T22:58:34
2024-02-19T20:30:57
2024-02-19T17:21:50
https://github.com/pandas-dev/pandas/pull/57477
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57477
https://github.com/pandas-dev/pandas/pull/57477
phofl
2
This should be all of them
[ "Copy / view semantics" ]
0
0
0
0
0
0
0
0
[ "For the skipped fastparquet tests, was going to open an issue on their side, but commented on an open one (they already saw the same failures on their CI in the meantime, https://github.com/dask/fastparquet/issues/919)", "Tbh I don’t really care. Not objecting to you investing time, but won’t bother with this\r\n\r\nwe deprecated this in dask/dask already and I would support a similar thing jere " ]
2,140,635,039
57,476
TYP: simplify read_csv/fwf/table overloads
closed
2024-02-17T22:06:03
2024-04-07T10:59:17
2024-02-21T18:05:33
https://github.com/pandas-dev/pandas/pull/57476
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57476
https://github.com/pandas-dev/pandas/pull/57476
twoertwein
1
null
[ "Typing" ]
0
0
0
0
0
0
0
0
[ "Thanks @twoertwein " ]
2,140,629,857
57,475
REGR: Index.map adding back tz to tz-agnostic result
closed
2024-02-17T21:48:03
2024-07-04T12:17:38
2024-07-04T12:17:38
https://github.com/pandas-dev/pandas/pull/57475
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57475
https://github.com/pandas-dev/pandas/pull/57475
rhshadrach
3
- [x] closes #57192 (Replace xxxx with the GitHub issue number) - [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature. It seems to me we should skip casting back to the caller's dtype when the caller dtype is datetime, since these are reliably represented as objects (unlike ints, which loses the size). But datetimes/tzs are definitely not in my wheelhouse. cc @jbrockmendel
[ "Regression", "Apply", "Index" ]
0
0
0
0
0
0
0
0
[ "I'm pretty sure the problem is in DatetimeArray._from_scalars, where we need to check that dont have tzawareness-mismatch. instead of \r\n\r\n```\r\nif lib.infer_dtype(scalars, skipna=True) not in [\"datetime\", \"datetime64\"]:\r\n raise ValueError\r\n```\r\n\r\nsomething like\r\n\r\n```\r\nif isinstance(dtype, DatetimeTZDtype) and not lib.is_datetime_with_singletz_array(scalars);\r\n raise ValueError\r\nelif isinstance(dtype, np.dtype) and not lib.is_naive_datetime_array(scalars):\r\n raise ValueError\r\n```\r\n\r\nis_naive_datetime_array doesn't actually exist but seems like it should.", "Thanks @jbrockmendel - this is much better. One thing I'm running into is that `is_datetime_with_singletz_array` doesn't check if any of the values are actually datetimes (will always return True when there are no datetimes), so I think this still needs to have the line with `lib.infer_dtype(scalars, skipna=True)` or maybe use `lib.is_datetime_or_datetime64_array`? Any recommendations?", "I'm trying to get rid of uses of lib.infer_dtype as it is very rarely the right tool to reach for.\r\n\r\nSeems like `is_datetime_with_singletz_array(values) and not isna(values).all()` is the simplest way to get what you've described. Could try to combine those into a single function i guess but i wouldn't bother at this point." ]
2,140,602,784
57,474
REGR: DataFrame.transpose resulting in not contiguous data on nullable EAs
closed
2024-02-17T20:49:51
2024-02-23T03:35:35
2024-02-18T15:15:09
https://github.com/pandas-dev/pandas/pull/57474
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57474
https://github.com/pandas-dev/pandas/pull/57474
rhshadrach
2
- [x] closes #57315 (Replace xxxx with the GitHub issue number) - [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature - [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit). - [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions. - [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.
[ "Bug", "Reshaping", "Regression" ]
0
0
0
0
0
0
0
0
[ "thx @rhshadrach ", "Owee, I'm MrMeeseeks, Look at me.\n\nThere seem to be a conflict, please backport manually. Here are approximate instructions:\n\n1. Checkout backport branch and update it.\n\n```\ngit checkout 2.2.x\ngit pull\n```\n\n2. Cherry pick the first parent branch of the this PR on top of the older branch:\n```\ngit cherry-pick -x -m1 abc3efb63f02814047a1b291ac2b1ee3cd70252f\n```\n\n3. You will likely have some merge/cherry-pick conflict here, fix them and commit:\n\n```\ngit commit -am 'Backport PR #57474: REGR: DataFrame.transpose resulting in not contiguous data on nullable EAs'\n```\n\n4. Push to a named branch:\n\n```\ngit push YOURFORK 2.2.x:auto-backport-of-pr-57474-on-2.2.x\n```\n\n5. Create a PR against branch 2.2.x, I would have named this PR:\n\n> \"Backport PR #57474 on branch 2.2.x (REGR: DataFrame.transpose resulting in not contiguous data on nullable EAs)\"\n\nAnd apply the correct labels and milestones.\n\nCongratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!\n\nRemember to remove the `Still Needs Manual Backport` label once the PR gets merged.\n\nIf these instructions are inaccurate, feel free to [suggest an improvement](https://github.com/MeeseeksBox/MeeseeksDev).\n " ]
2,140,445,686
57,473
DEPR: remove deprecated method `is_anchored`
closed
2024-02-17T18:46:12
2024-02-19T21:06:02
2024-02-19T20:48:28
https://github.com/pandas-dev/pandas/pull/57473
true
https://api.github.com/repos/pandas-dev/pandas/pulls/57473
https://github.com/pandas-dev/pandas/pull/57473
natmokval
2
xref #56594 removed deprecated methods `DateOffset.is_anchored` and `offsets.Tick.is_anchored`
[ "Deprecate" ]
0
0
0
0
0
0
0
0
[ "I enforced the deprecation of `DateOffset.is_anchored` and `offsets.Tick.is_anchored`. @MarcoGorelli, could you please take a look at this PR? I think, CI failures are not related to my changes.", "Thanks @MarcoGorelli for reviewing this PR. " ]