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 of pandas.

  • [X] I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
ser_1 = pd.Series([1, 2, 3, "b"], dtype="category")
ser_2 = pd.Series([1, 3, 3, "b"], dtype="category")

ser_2 = ser_2.cat.add_categories(2)

print(f"Ser_1 categories: {ser_1.cat.categories}")
print(f"Ser_2 categories: {ser_2.cat.categories}")

ser_1.eq(ser_2)
===============================================
Ser_1 categories: Index([1, 2, 3, 'b'], dtype='object')
Ser_2 categories: Index([1, 3, 'b', 2], dtype='object')
File "/.../site-packages/pandas/core/arrays/categorical.py", line 153, in func
    raise TypeError(msg)
TypeError: Categoricals can only be compared if 'categories' are the same.

Issue Description

I believe this PR may have oversimplified categorical comparisons and prevented unordered categories from being compared.

Expected Behavior

I would expect that comparing two collections of categories would not raise an error if the sets of those two categories are equivalent regardless of the order.

Installed Versions

IINSTALLED VERSIONS ------------------ commit : 2e218d10984e9919f0296931d92ea851c6a6faf5 python : 3.8.16.final.0 python-bits : 64 OS : Darwin OS-release : 21.6.0 Version : Darwin Kernel Version 21.6.0: Mon Aug 22 20:17:10 PDT 2022; root:xnu-8020.140.49~2/RELEASE_X86_64 machine : x86_64 processor : i386 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8 pandas : 1.5.3 numpy : 1.23.5 pytz : 2022.7.1 dateutil : 2.8.2 setuptools : 67.1.0 pip : 23.0 Cython : None pytest : 7.0.1 hypothesis : None sphinx : 5.1.1 blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : 3.1.2 IPython : 8.4.0 pandas_datareader: None bs4 : 4.11.2 bottleneck : None brotli : None fastparquet : None fsspec : 2023.1.0 gcsfs : None matplotlib : None numba : None numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : 11.0.0 pyreadstat : None pyxlsb : None s3fs : None scipy : 1.10.0 snappy : None sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None xlwt : None zstandard : None tzdata : None

Comment From: AlexKirko

Confirmed by reproducing. Since categories are unordered by default, I agree that there shouldn't be an error and we should just get False here.

@ParthivNaresh Would you be willing to take on making a PR to fix this?

Comment From: ParthivNaresh

@AlexKirko For sure I'm on it!

Comment From: ParthivNaresh

take