Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use int32 as default int representation in windows #1179

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions pandera/engines/pandas_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,13 @@ def _register_numpy_numbers(

builtin_type = getattr(builtins, builtin_name, None) # uint doesn't exist

# default to int64 regardless of OS
default_pd_dtype = {
"int": np.dtype("int64"),
"uint": np.dtype("uint64"),
# use OS-specific type for integers. This will be int32 for Windows, int64
# for other systems.
default_int_dtype = {
"int": np.dtype("int32"),
"uint": np.dtype("uint32"),
}.get(builtin_name, pd.Series([1], dtype=builtin_name).dtype)
# default_int_dtype = pd.Series([1], dtype=builtin_name).dtype

for bit_width in sizes:
# e.g.: numpy.int64
Expand All @@ -292,10 +294,10 @@ def _register_numpy_numbers(
)
)

if np_dtype == default_pd_dtype:
if np_dtype == default_int_dtype:
equivalents |= set(
(
default_pd_dtype,
default_int_dtype,
builtin_name,
getattr(dtypes, pandera_name),
getattr(dtypes, pandera_name)(),
Expand Down
6 changes: 4 additions & 2 deletions tests/core/test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ def test_vectorized_checks() -> None:
schema = SeriesSchema(
Int, Check(lambda s: s.value_counts() == 2, element_wise=False)
)
validated_series = schema.validate(pd.Series([1, 1, 2, 2, 3, 3]))
validated_series = schema.validate(
pd.Series([1, 1, 2, 2, 3, 3], dtype=int)
)
assert isinstance(validated_series, pd.Series)

# error case
with pytest.raises(errors.SchemaError):
schema.validate(pd.Series([1, 2, 3]))
schema.validate(pd.Series([1, 2, 3], dtype=int))


def test_check_groupby() -> None:
Expand Down
5 changes: 5 additions & 0 deletions tests/core/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dataclasses
import datetime
import inspect
import platform
import re
import sys
from decimal import Decimal
Expand Down Expand Up @@ -507,6 +508,10 @@ def test_default_numeric_dtypes():
== pandas_engine.Engine.dtype(int)
== pandas_engine.Engine.dtype("int")
)
if platform.system() == "Windows":
assert default_int_dtype == np.dtype("int32")
else:
assert default_int_dtype == np.dtype("int64")
Comment on lines +511 to +514

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Platform check may not reflect architecture

Consider using platform.machine() instead of platform.system() to check for architecture since integer size is typically architecture dependent rather than OS dependent. On 32-bit systems, default int is 32-bit while on 64-bit systems it's 64-bit.

Code suggestion
Check the AI-generated fix before applying
Suggested change
if platform.system() == "Windows":
assert default_int_dtype == np.dtype("int32")
else:
assert default_int_dtype == np.dtype("int64")
if platform.machine() in ["i386", "x86"]:
assert default_int_dtype == np.dtype("int32")
else:
assert default_int_dtype == np.dtype("int64")

Code Review Run #722777


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged


default_float_dtype = pd.Series([1.0]).dtype
assert (
Expand Down