Skip to content

Commit

Permalink
Fix pandas internals changes
Browse files Browse the repository at this point in the history
  • Loading branch information
phofl committed May 6, 2024
1 parent 20e8e70 commit c131955
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- name: Checkout source
Expand Down
39 changes: 18 additions & 21 deletions partd/pandas.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
from functools import partial
import pickle

import numpy as np
import pandas as pd
from pandas.core.internals import create_block_manager_from_blocks, make_block

try:
from pandas.core.internals.managers import create_block_manager_from_blocks
except ImportError:
from pandas.core.internals import create_block_manager_from_blocks

from pandas.core.internals import make_block
from packaging.version import Version

from . import numpy as pnp
from .core import Interface
from .encode import Encode
from .utils import extend, framesplit, frame
from pandas.api.types import is_extension_array_dtype
from pandas.api.extensions import ExtensionArray

try:
# pandas >= 0.24.0
from pandas.api.types import is_extension_array_dtype
except ImportError:
def is_extension_array_dtype(dtype):
return False

try:
# Some `ExtensionArray`s can have a `.dtype` which is not a `ExtensionDtype`
# (e.g. they can be backed by a NumPy dtype). For these cases we check
# whether the instance is a `ExtensionArray`.
# https://github.com/dask/partd/issues/48
from pandas.api.extensions import ExtensionArray
def is_extension_array(x):
return isinstance(x, ExtensionArray)
except ImportError:
def is_extension_array(x):
return False
def is_extension_array(x):
return isinstance(x, ExtensionArray)


dumps = partial(pickle.dumps, protocol=pickle.HIGHEST_PROTOCOL)

PANDAS_GE_210 = Version(pd.__version__).release >= (2, 1, 0)


class PandasColumns(Interface):
def __init__(self, partd=None):
Expand Down Expand Up @@ -195,7 +189,10 @@ def deserialize(bytes):
index_from_header_bytes(headers[1], bytes[1])]
blocks = [block_from_header_bytes(h, b)
for (h, b) in zip(headers[2:], bytes[2:])]
return pd.DataFrame(create_block_manager_from_blocks(blocks, axes))
if PANDAS_GE_210:
return pd.DataFrame._from_mgr(create_block_manager_from_blocks(blocks, axes), axes=axes)
else:
return pd.DataFrame(create_block_manager_from_blocks(blocks, axes))


def join(dfs):
Expand Down
9 changes: 4 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ license = {text = "BSD"}
keywords = []
classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
readme = "README.rst"
urls = {Homepage = "http://github.com/dask/partd/"}
requires-python = ">=3.7"
requires-python = ">=3.9"
dynamic = ["version"]
dependencies = [
"locket",
Expand All @@ -27,8 +26,8 @@ dependencies = [

[project.optional-dependencies]
complete = [
"numpy >= 1.9.0",
"pandas >=0.19.0",
"numpy >= 1.20.0",
"pandas >=1.3",
"pyzmq",
"blosc",
]
Expand Down

0 comments on commit c131955

Please sign in to comment.